Skip to content

Commit

Permalink
Replaced deprecated DEVICE_CLASS_* constants. Closes #49
Browse files Browse the repository at this point in the history
  • Loading branch information
erikkastelec committed Jan 3, 2023
1 parent 544176a commit 888371c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion custom_components/wemportal/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"documentation": "https://github.com/erikkastelec/hass-WEM-Portal",
"issue_tracker": "https://github.com/erikkastelec/hass-WEM-Portal/issues",
"dependencies": [],
"version": "1.4.1",
"version": "1.4.2",
"codeowners": [
"@erikkastelec"
],
Expand Down
32 changes: 16 additions & 16 deletions custom_components/wemportal/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
Sensor platform for wemportal component
"""

from homeassistant.components.sensor import (STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
SensorEntity)
from homeassistant.components.sensor import (
SensorEntity,
SensorDeviceClass,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (DEVICE_CLASS_ENERGY, DEVICE_CLASS_POWER,
DEVICE_CLASS_POWER_FACTOR,
DEVICE_CLASS_TEMPERATURE)

from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
Expand All @@ -17,10 +17,10 @@


async def async_setup_platform(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
discovery_info=None,
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
discovery_info=None,
):
"""Setup the Wem Portal sensors."""

Expand Down Expand Up @@ -103,23 +103,23 @@ def unit_of_measurement(self):
def device_class(self):
"""Return the device_class of this entity."""
if self._unit == "°C":
return DEVICE_CLASS_TEMPERATURE
return SensorDeviceClass.TEMPERATURE
elif self._unit in ("kWh", "Wh"):
return DEVICE_CLASS_ENERGY
return SensorDeviceClass.ENERGY
elif self._unit in ("kW", "W"):
return DEVICE_CLASS_POWER
return SensorDeviceClass.POWER
elif self._unit == "%":
return DEVICE_CLASS_POWER_FACTOR
return SensorDeviceClass.POWER_FACTOR
else:
return None

@property
def state_class(self):
"""Return the state class of this entity, if any."""
if self._unit in ("°C", "kW", "W", "%"):
return STATE_CLASS_MEASUREMENT
return SensorStateClass.MEASUREMENT
elif self._unit in ("kWh", "Wh"):
return STATE_CLASS_TOTAL_INCREASING
return SensorStateClass.TOTAL_INCREASING
else:
return None

Expand Down

0 comments on commit 888371c

Please sign in to comment.