Skip to content

Commit

Permalink
Merge pull request #133 from binsentsu/feature/deviceClassDeprecated
Browse files Browse the repository at this point in the history
update deprecated const variables to new enum classes
  • Loading branch information
binsentsu authored Jan 4, 2023
2 parents 44a77a2 + 470dc9d commit 9b23a8a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions custom_components/solaredge_modbus/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
)
from datetime import datetime
from homeassistant.helpers.entity import Entity
from homeassistant.const import CONF_NAME, DEVICE_CLASS_ENERGY, ENERGY_KILO_WATT_HOUR
from homeassistant.const import CONF_NAME, UnitOfEnergy
from homeassistant.components.sensor import (
PLATFORM_SCHEMA,
STATE_CLASS_MEASUREMENT,
SensorEntity,
SensorDeviceClass,
)

try: # backward-compatibility to 2021.8
Expand Down Expand Up @@ -139,9 +140,9 @@ def __init__(self, platform_name, hub, device_info, name, key, unit, icon):
self._icon = icon
self._device_info = device_info
self._attr_state_class = STATE_CLASS_MEASUREMENT
if self._unit_of_measurement == ENERGY_KILO_WATT_HOUR:
if self._unit_of_measurement == UnitOfEnergy.KILO_WATT_HOUR :
self._attr_state_class = STATE_CLASS_TOTAL_INCREASING
self._attr_device_class = DEVICE_CLASS_ENERGY
self._attr_device_class = SensorDeviceClass.ENERGY
if STATE_CLASS_TOTAL_INCREASING == STATE_CLASS_MEASUREMENT: # compatibility to 2021.8
self._attr_last_reset = dt_util.utc_from_timestamp(0)

Expand Down

0 comments on commit 9b23a8a

Please sign in to comment.