Use unit enums in overkiz (#83660)

This commit is contained in:
epenet 2022-12-10 00:08:03 +01:00 committed by GitHub
parent d5c322732f
commit 5c700916d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,15 +17,15 @@ from homeassistant.components.sensor import (
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
CONCENTRATION_PARTS_PER_MILLION, CONCENTRATION_PARTS_PER_MILLION,
ENERGY_WATT_HOUR,
LIGHT_LUX, LIGHT_LUX,
PERCENTAGE, PERCENTAGE,
POWER_WATT,
SIGNAL_STRENGTH_DECIBELS, SIGNAL_STRENGTH_DECIBELS,
TEMP_CELSIUS,
TIME_SECONDS,
VOLUME_FLOW_RATE_CUBIC_METERS_PER_HOUR, VOLUME_FLOW_RATE_CUBIC_METERS_PER_HOUR,
VOLUME_LITERS, UnitOfEnergy,
UnitOfPower,
UnitOfTemperature,
UnitOfTime,
UnitOfVolume,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo, EntityCategory from homeassistant.helpers.entity import DeviceInfo, EntityCategory
@ -91,7 +91,7 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
key=OverkizState.CORE_V40_WATER_VOLUME_ESTIMATION, key=OverkizState.CORE_V40_WATER_VOLUME_ESTIMATION,
name="Water volume estimation at 40 °C", name="Water volume estimation at 40 °C",
icon="mdi:water", icon="mdi:water",
native_unit_of_measurement=VOLUME_LITERS, native_unit_of_measurement=UnitOfVolume.LITERS,
device_class=SensorDeviceClass.VOLUME, device_class=SensorDeviceClass.VOLUME,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
@ -100,7 +100,7 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
key=OverkizState.CORE_WATER_CONSUMPTION, key=OverkizState.CORE_WATER_CONSUMPTION,
name="Water consumption", name="Water consumption",
icon="mdi:water", icon="mdi:water",
native_unit_of_measurement=VOLUME_LITERS, native_unit_of_measurement=UnitOfVolume.LITERS,
device_class=SensorDeviceClass.VOLUME, device_class=SensorDeviceClass.VOLUME,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
@ -108,7 +108,7 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
key=OverkizState.IO_OUTLET_ENGINE, key=OverkizState.IO_OUTLET_ENGINE,
name="Outlet engine", name="Outlet engine",
icon="mdi:fan-chevron-down", icon="mdi:fan-chevron-down",
native_unit_of_measurement=VOLUME_LITERS, native_unit_of_measurement=UnitOfVolume.LITERS,
device_class=SensorDeviceClass.VOLUME, device_class=SensorDeviceClass.VOLUME,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
@ -124,14 +124,14 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
name="Room temperature", name="Room temperature",
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=UnitOfTemperature.CELSIUS,
), ),
OverkizSensorDescription( OverkizSensorDescription(
key=OverkizState.IO_MIDDLE_WATER_TEMPERATURE, key=OverkizState.IO_MIDDLE_WATER_TEMPERATURE,
name="Middle water temperature", name="Middle water temperature",
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=UnitOfTemperature.CELSIUS,
), ),
OverkizSensorDescription( OverkizSensorDescription(
key=OverkizState.CORE_FOSSIL_ENERGY_CONSUMPTION, key=OverkizState.CORE_FOSSIL_ENERGY_CONSUMPTION,
@ -158,21 +158,21 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
key=OverkizState.CORE_ELECTRIC_ENERGY_CONSUMPTION, key=OverkizState.CORE_ELECTRIC_ENERGY_CONSUMPTION,
name="Electric energy consumption", name="Electric energy consumption",
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh (not for modbus:YutakiV2DHWElectricalEnergyConsumptionComponent) native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh (not for modbus:YutakiV2DHWElectricalEnergyConsumptionComponent)
state_class=SensorStateClass.TOTAL_INCREASING, # core:MeasurementCategory attribute = electric/overall state_class=SensorStateClass.TOTAL_INCREASING, # core:MeasurementCategory attribute = electric/overall
), ),
OverkizSensorDescription( OverkizSensorDescription(
key=OverkizState.CORE_ELECTRIC_POWER_CONSUMPTION, key=OverkizState.CORE_ELECTRIC_POWER_CONSUMPTION,
name="Electric power consumption", name="Electric power consumption",
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
native_unit_of_measurement=POWER_WATT, # core:MeasuredValueType = core:ElectricalEnergyInWh (not for modbus:YutakiV2DHWElectricalEnergyConsumptionComponent) native_unit_of_measurement=UnitOfPower.WATT, # core:MeasuredValueType = core:ElectricalEnergyInWh (not for modbus:YutakiV2DHWElectricalEnergyConsumptionComponent)
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
OverkizSensorDescription( OverkizSensorDescription(
key=OverkizState.CORE_CONSUMPTION_TARIFF1, key=OverkizState.CORE_CONSUMPTION_TARIFF1,
name="Consumption tariff 1", name="Consumption tariff 1",
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
@ -180,7 +180,7 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
key=OverkizState.CORE_CONSUMPTION_TARIFF2, key=OverkizState.CORE_CONSUMPTION_TARIFF2,
name="Consumption tariff 2", name="Consumption tariff 2",
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
@ -188,7 +188,7 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
key=OverkizState.CORE_CONSUMPTION_TARIFF3, key=OverkizState.CORE_CONSUMPTION_TARIFF3,
name="Consumption tariff 3", name="Consumption tariff 3",
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
@ -196,7 +196,7 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
key=OverkizState.CORE_CONSUMPTION_TARIFF4, key=OverkizState.CORE_CONSUMPTION_TARIFF4,
name="Consumption tariff 4", name="Consumption tariff 4",
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
@ -204,7 +204,7 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
key=OverkizState.CORE_CONSUMPTION_TARIFF5, key=OverkizState.CORE_CONSUMPTION_TARIFF5,
name="Consumption tariff 5", name="Consumption tariff 5",
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
@ -212,7 +212,7 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
key=OverkizState.CORE_CONSUMPTION_TARIFF6, key=OverkizState.CORE_CONSUMPTION_TARIFF6,
name="Consumption tariff 6", name="Consumption tariff 6",
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
@ -220,7 +220,7 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
key=OverkizState.CORE_CONSUMPTION_TARIFF7, key=OverkizState.CORE_CONSUMPTION_TARIFF7,
name="Consumption tariff 7", name="Consumption tariff 7",
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
@ -228,7 +228,7 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
key=OverkizState.CORE_CONSUMPTION_TARIFF8, key=OverkizState.CORE_CONSUMPTION_TARIFF8,
name="Consumption tariff 8", name="Consumption tariff 8",
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
@ -236,7 +236,7 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
key=OverkizState.CORE_CONSUMPTION_TARIFF9, key=OverkizState.CORE_CONSUMPTION_TARIFF9,
name="Consumption tariff 9", name="Consumption tariff 9",
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh native_unit_of_measurement=UnitOfEnergy.WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
@ -255,7 +255,7 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
name="Temperature", name="Temperature",
native_value=lambda value: round(cast(float, value), 2), native_value=lambda value: round(cast(float, value), 2),
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=TEMP_CELSIUS, # core:MeasuredValueType = core:TemperatureInCelcius native_unit_of_measurement=UnitOfTemperature.CELSIUS, # core:MeasuredValueType = core:TemperatureInCelcius
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
# WeatherSensor/WeatherForecastSensor # WeatherSensor/WeatherForecastSensor
@ -263,21 +263,21 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
key=OverkizState.CORE_WEATHER_STATUS, key=OverkizState.CORE_WEATHER_STATUS,
name="Weather status", name="Weather status",
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=UnitOfTemperature.CELSIUS,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
OverkizSensorDescription( OverkizSensorDescription(
key=OverkizState.CORE_MINIMUM_TEMPERATURE, key=OverkizState.CORE_MINIMUM_TEMPERATURE,
name="Minimum temperature", name="Minimum temperature",
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=UnitOfTemperature.CELSIUS,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
OverkizSensorDescription( OverkizSensorDescription(
key=OverkizState.CORE_MAXIMUM_TEMPERATURE, key=OverkizState.CORE_MAXIMUM_TEMPERATURE,
name="Maximum temperature", name="Maximum temperature",
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=TEMP_CELSIUS, native_unit_of_measurement=UnitOfTemperature.CELSIUS,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
# AirSensor/COSensor # AirSensor/COSensor
@ -336,7 +336,7 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
key=OverkizState.CORE_PRIORITY_LOCK_TIMER, key=OverkizState.CORE_PRIORITY_LOCK_TIMER,
name="Priority lock timer", name="Priority lock timer",
icon="mdi:lock-clock", icon="mdi:lock-clock",
native_unit_of_measurement=TIME_SECONDS, native_unit_of_measurement=UnitOfTime.SECONDS,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
), ),
OverkizSensorDescription( OverkizSensorDescription(
@ -365,13 +365,13 @@ SENSOR_DESCRIPTIONS: list[OverkizSensorDescription] = [
name="Heat pump operating time", name="Heat pump operating time",
device_class=SensorDeviceClass.DURATION, device_class=SensorDeviceClass.DURATION,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=TIME_SECONDS, native_unit_of_measurement=UnitOfTime.SECONDS,
), ),
OverkizSensorDescription( OverkizSensorDescription(
key=OverkizState.IO_ELECTRIC_BOOSTER_OPERATING_TIME, key=OverkizState.IO_ELECTRIC_BOOSTER_OPERATING_TIME,
name="Electric booster operating time", name="Electric booster operating time",
device_class=SensorDeviceClass.DURATION, device_class=SensorDeviceClass.DURATION,
native_unit_of_measurement=TIME_SECONDS, native_unit_of_measurement=UnitOfTime.SECONDS,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
# Cover # Cover