Use enums in youless (#61977)
This commit is contained in:
parent
1568ee67c2
commit
701699350d
1 changed files with 22 additions and 22 deletions
|
@ -4,17 +4,13 @@ from __future__ import annotations
|
|||
from youless_api.youless_sensor import YoulessSensor
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
STATE_CLASS_TOTAL,
|
||||
STATE_CLASS_TOTAL_INCREASING,
|
||||
SensorDeviceClass,
|
||||
SensorEntity,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_DEVICE,
|
||||
DEVICE_CLASS_ENERGY,
|
||||
DEVICE_CLASS_GAS,
|
||||
DEVICE_CLASS_POWER,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
POWER_WATT,
|
||||
VOLUME_CUBIC_METERS,
|
||||
|
@ -43,9 +39,13 @@ async def async_setup_entry(
|
|||
async_add_entities(
|
||||
[
|
||||
GasSensor(coordinator, device),
|
||||
PowerMeterSensor(coordinator, device, "low", STATE_CLASS_TOTAL_INCREASING),
|
||||
PowerMeterSensor(coordinator, device, "high", STATE_CLASS_TOTAL_INCREASING),
|
||||
PowerMeterSensor(coordinator, device, "total", STATE_CLASS_TOTAL),
|
||||
PowerMeterSensor(
|
||||
coordinator, device, "low", SensorStateClass.TOTAL_INCREASING
|
||||
),
|
||||
PowerMeterSensor(
|
||||
coordinator, device, "high", SensorStateClass.TOTAL_INCREASING
|
||||
),
|
||||
PowerMeterSensor(coordinator, device, "total", SensorStateClass.TOTAL),
|
||||
CurrentPowerSensor(coordinator, device),
|
||||
DeliveryMeterSensor(coordinator, device, "low"),
|
||||
DeliveryMeterSensor(coordinator, device, "high"),
|
||||
|
@ -103,8 +103,8 @@ class GasSensor(YoulessBaseSensor):
|
|||
"""The Youless gas sensor."""
|
||||
|
||||
_attr_native_unit_of_measurement = VOLUME_CUBIC_METERS
|
||||
_attr_device_class = DEVICE_CLASS_GAS
|
||||
_attr_state_class = STATE_CLASS_TOTAL_INCREASING
|
||||
_attr_device_class = SensorDeviceClass.GAS
|
||||
_attr_state_class = SensorStateClass.TOTAL_INCREASING
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, device: str) -> None:
|
||||
"""Instantiate a gas sensor."""
|
||||
|
@ -122,8 +122,8 @@ class CurrentPowerSensor(YoulessBaseSensor):
|
|||
"""The current power usage sensor."""
|
||||
|
||||
_attr_native_unit_of_measurement = POWER_WATT
|
||||
_attr_device_class = DEVICE_CLASS_POWER
|
||||
_attr_state_class = STATE_CLASS_MEASUREMENT
|
||||
_attr_device_class = SensorDeviceClass.POWER
|
||||
_attr_state_class = SensorStateClass.MEASUREMENT
|
||||
|
||||
def __init__(self, coordinator: DataUpdateCoordinator, device: str) -> None:
|
||||
"""Instantiate the usage meter."""
|
||||
|
@ -141,8 +141,8 @@ class DeliveryMeterSensor(YoulessBaseSensor):
|
|||
"""The Youless delivery meter value sensor."""
|
||||
|
||||
_attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR
|
||||
_attr_device_class = DEVICE_CLASS_ENERGY
|
||||
_attr_state_class = STATE_CLASS_TOTAL_INCREASING
|
||||
_attr_device_class = SensorDeviceClass.ENERGY
|
||||
_attr_state_class = SensorStateClass.TOTAL_INCREASING
|
||||
|
||||
def __init__(
|
||||
self, coordinator: DataUpdateCoordinator, device: str, dev_type: str
|
||||
|
@ -167,15 +167,15 @@ class PowerMeterSensor(YoulessBaseSensor):
|
|||
"""The Youless low meter value sensor."""
|
||||
|
||||
_attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR
|
||||
_attr_device_class = DEVICE_CLASS_ENERGY
|
||||
_attr_state_class = STATE_CLASS_TOTAL_INCREASING
|
||||
_attr_device_class = SensorDeviceClass.ENERGY
|
||||
_attr_state_class = SensorStateClass.TOTAL_INCREASING
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: DataUpdateCoordinator,
|
||||
device: str,
|
||||
dev_type: str,
|
||||
state_class: str,
|
||||
state_class: SensorStateClass,
|
||||
) -> None:
|
||||
"""Instantiate a power meter sensor."""
|
||||
super().__init__(
|
||||
|
@ -199,8 +199,8 @@ class ExtraMeterSensor(YoulessBaseSensor):
|
|||
"""The Youless extra meter value sensor (s0)."""
|
||||
|
||||
_attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR
|
||||
_attr_device_class = DEVICE_CLASS_ENERGY
|
||||
_attr_state_class = STATE_CLASS_TOTAL_INCREASING
|
||||
_attr_device_class = SensorDeviceClass.ENERGY
|
||||
_attr_state_class = SensorStateClass.TOTAL_INCREASING
|
||||
|
||||
def __init__(
|
||||
self, coordinator: DataUpdateCoordinator, device: str, dev_type: str
|
||||
|
@ -225,8 +225,8 @@ class ExtraMeterPowerSensor(YoulessBaseSensor):
|
|||
"""The Youless extra meter power value sensor (s0)."""
|
||||
|
||||
_attr_native_unit_of_measurement = POWER_WATT
|
||||
_attr_device_class = DEVICE_CLASS_POWER
|
||||
_attr_state_class = STATE_CLASS_MEASUREMENT
|
||||
_attr_device_class = SensorDeviceClass.POWER
|
||||
_attr_state_class = SensorStateClass.MEASUREMENT
|
||||
|
||||
def __init__(
|
||||
self, coordinator: DataUpdateCoordinator, device: str, dev_type: str
|
||||
|
|
Loading…
Add table
Reference in a new issue