Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made code compatible with HA 2025.1 #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 16 additions & 26 deletions custom_components/omnik/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,17 @@

from homeassistant.components.sensor import (
PLATFORM_SCHEMA,
SensorEntity,
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
SensorDeviceClass,
SensorEntity,
SensorStateClass,
)
from homeassistant.const import (
EVENT_HOMEASSISTANT_STOP,
CONF_NAME,
from homeassistant.const import (
EVENT_HOMEASSISTANT_STOP,
CONF_NAME,
CONF_SCAN_INTERVAL,
TEMP_CELSIUS,
DEVICE_CLASS_CURRENT,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_POWER,
DEVICE_CLASS_VOLTAGE,
DEVICE_CLASS_TEMPERATURE,
)
import homeassistant.helpers.config_validation as cv
from homeassistant.util import Throttle
#from homeassistant.helpers.entity import Entity
from urllib.request import urlopen
from xml.etree import ElementTree as etree

Expand All @@ -40,9 +33,6 @@
import struct
import sys

# VERSION
VERSION = '0.1.0'

BASE_URL = 'http://{0}:{1}{2}'

_LOGGER = logging.getLogger(__name__)
Expand All @@ -58,18 +48,18 @@
SENSOR_PREFIX = 'Omnik'
SENSOR_TYPES = {
'status': ['Status', None, 'mdi:solar-power', None, None],
'actualpower': ['Actual Power', 'W', 'mdi:weather-sunny',DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT],
'energytoday': ['Energy Today', 'kWh', 'mdi:flash-outline', DEVICE_CLASS_ENERGY, STATE_CLASS_TOTAL_INCREASING],
'energytotal': ['Energy Total', 'kWh', 'mdi:flash-outline', DEVICE_CLASS_ENERGY, STATE_CLASS_TOTAL_INCREASING],
'actualpower': ['Actual Power', 'W', 'mdi:weather-sunny', SensorDeviceClass.POWER, SensorStateClass.MEASUREMENT],
'energytoday': ['Energy Today', 'kWh', 'mdi:flash-outline', SensorDeviceClass.ENERGY, SensorStateClass.TOTAL_INCREASING],
'energytotal': ['Energy Total', 'kWh', 'mdi:flash-outline', SensorDeviceClass.ENERGY, SensorStateClass.TOTAL_INCREASING],
'hourstotal': ['Hours Total', 'Hours', 'mdi:timer', None, None],
'invertersn': ['Inverter Serial Number', None, 'mdi:information-outline', None, None],
'temperature': ['Temperature', '°C', 'mdi:thermometer', DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT],
'dcinputvoltage': ['DC Input Voltage', 'V', 'mdi:flash-outline', DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT],
'dcinputcurrent': ['DC Input Current', 'A', 'mdi:flash-outline', DEVICE_CLASS_CURRENT, STATE_CLASS_MEASUREMENT],
'acoutputvoltage': ['AC Output Voltage', 'V', 'mdi:flash-outline', DEVICE_CLASS_VOLTAGE, STATE_CLASS_MEASUREMENT],
'acoutputcurrent': ['AC Output Current', 'A', 'mdi:flash-outline', DEVICE_CLASS_CURRENT, STATE_CLASS_MEASUREMENT],
'acoutputfrequency': ['AC Output Frequency', 'Hz', 'mdi:flash-outline', None, STATE_CLASS_MEASUREMENT],
'acoutputpower': ['AC Output Power', 'W', 'mdi:flash-outline',DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT],
'temperature': ['Temperature', '°C', 'mdi:thermometer', SensorDeviceClass.TEMPERATURE, SensorStateClass.MEASUREMENT],
'dcinputvoltage': ['DC Input Voltage', 'V', 'mdi:flash-outline', SensorDeviceClass.VOLTAGE, SensorStateClass.MEASUREMENT],
'dcinputcurrent': ['DC Input Current', 'A', 'mdi:flash-outline', SensorDeviceClass.CURRENT, SensorStateClass.MEASUREMENT],
'acoutputvoltage': ['AC Output Voltage', 'V', 'mdi:flash-outline', SensorDeviceClass.VOLTAGE, SensorStateClass.MEASUREMENT],
'acoutputcurrent': ['AC Output Current', 'A', 'mdi:flash-outline', SensorDeviceClass.CURRENT, SensorStateClass.MEASUREMENT],
'acoutputfrequency': ['AC Output Frequency', 'Hz', 'mdi:flash-outline', None, SensorStateClass.MEASUREMENT],
'acoutputpower': ['AC Output Power', 'W', 'mdi:flash-outline', SensorDeviceClass.POWER, SensorStateClass.MEASUREMENT],
}

def _check_config_schema(conf):
Expand Down