Use device classes in volkszaehler (#83823)
parent
9cd159ee01
commit
a30f14a15e
|
@ -10,6 +10,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components.sensor import (
|
||||
PLATFORM_SCHEMA,
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
)
|
||||
|
@ -18,8 +19,8 @@ from homeassistant.const import (
|
|||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_NAME,
|
||||
CONF_PORT,
|
||||
ENERGY_WATT_HOUR,
|
||||
POWER_WATT,
|
||||
UnitOfEnergy,
|
||||
UnitOfPower,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
|
@ -43,25 +44,29 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="average",
|
||||
name="Average",
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
native_unit_of_measurement=UnitOfPower.WATT,
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
icon="mdi:power-off",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="consumption",
|
||||
name="Consumption",
|
||||
native_unit_of_measurement=ENERGY_WATT_HOUR,
|
||||
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
||||
device_class=SensorDeviceClass.ENERGY,
|
||||
icon="mdi:power-plug",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="max",
|
||||
name="Max",
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
native_unit_of_measurement=UnitOfPower.WATT,
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
icon="mdi:arrow-up",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="min",
|
||||
name="Min",
|
||||
native_unit_of_measurement=POWER_WATT,
|
||||
native_unit_of_measurement=UnitOfPower.WATT,
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
icon="mdi:arrow-down",
|
||||
),
|
||||
)
|
||||
|
@ -89,11 +94,11 @@ async def async_setup_platform(
|
|||
) -> None:
|
||||
"""Set up the Volkszaehler sensors."""
|
||||
|
||||
host = config[CONF_HOST]
|
||||
name = config[CONF_NAME]
|
||||
port = config[CONF_PORT]
|
||||
uuid = config[CONF_UUID]
|
||||
conditions = config[CONF_MONITORED_CONDITIONS]
|
||||
host: str = config[CONF_HOST]
|
||||
name: str = config[CONF_NAME]
|
||||
port: int = config[CONF_PORT]
|
||||
uuid: str = config[CONF_UUID]
|
||||
conditions: list[str] = config[CONF_MONITORED_CONDITIONS]
|
||||
|
||||
session = async_get_clientsession(hass)
|
||||
vz_api = VolkszaehlerData(Volkszaehler(session, uuid, host=host, port=port))
|
||||
|
@ -115,7 +120,9 @@ async def async_setup_platform(
|
|||
class VolkszaehlerSensor(SensorEntity):
|
||||
"""Implementation of a Volkszaehler sensor."""
|
||||
|
||||
def __init__(self, vz_api, name, description: SensorEntityDescription):
|
||||
def __init__(
|
||||
self, vz_api: VolkszaehlerData, name: str, description: SensorEntityDescription
|
||||
) -> None:
|
||||
"""Initialize the Volkszaehler sensor."""
|
||||
self.entity_description = description
|
||||
self.vz_api = vz_api
|
||||
|
@ -140,13 +147,13 @@ class VolkszaehlerSensor(SensorEntity):
|
|||
class VolkszaehlerData:
|
||||
"""The class for handling the data retrieval from the Volkszaehler API."""
|
||||
|
||||
def __init__(self, api):
|
||||
def __init__(self, api: Volkszaehler) -> None:
|
||||
"""Initialize the data object."""
|
||||
self.api = api
|
||||
self.available = True
|
||||
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||
async def async_update(self):
|
||||
async def async_update(self) -> None:
|
||||
"""Get the latest data from the Volkszaehler REST API."""
|
||||
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue