mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
Use new enums in integration (#61803)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
2c26eae9b2
commit
1692fab664
@ -5,11 +5,10 @@ import logging
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
DEVICE_CLASS_ENERGY,
|
|
||||||
DEVICE_CLASS_POWER,
|
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
STATE_CLASS_TOTAL,
|
SensorDeviceClass,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_DEVICE_CLASS,
|
ATTR_DEVICE_CLASS,
|
||||||
@ -119,7 +118,7 @@ class IntegrationSensor(RestoreEntity, SensorEntity):
|
|||||||
self._unit_of_measurement = unit_of_measurement
|
self._unit_of_measurement = unit_of_measurement
|
||||||
self._unit_prefix = UNIT_PREFIXES[unit_prefix]
|
self._unit_prefix = UNIT_PREFIXES[unit_prefix]
|
||||||
self._unit_time = UNIT_TIME[unit_time]
|
self._unit_time = UNIT_TIME[unit_time]
|
||||||
self._attr_state_class = STATE_CLASS_TOTAL
|
self._attr_state_class = SensorStateClass.TOTAL
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""Handle entity which will be added."""
|
"""Handle entity which will be added."""
|
||||||
@ -149,9 +148,10 @@ class IntegrationSensor(RestoreEntity, SensorEntity):
|
|||||||
)
|
)
|
||||||
if (
|
if (
|
||||||
self.device_class is None
|
self.device_class is None
|
||||||
and new_state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_POWER
|
and new_state.attributes.get(ATTR_DEVICE_CLASS)
|
||||||
|
== SensorDeviceClass.POWER
|
||||||
):
|
):
|
||||||
self._attr_device_class = DEVICE_CLASS_ENERGY
|
self._attr_device_class = SensorDeviceClass.ENERGY
|
||||||
|
|
||||||
if (
|
if (
|
||||||
old_state is None
|
old_state is None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user