Skip to content

Commit

Permalink
Migrate to native unit of measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
tetienne committed Sep 4, 2021
1 parent a1629fd commit d46a4af
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
4 changes: 3 additions & 1 deletion custom_components/tahoma/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ def extra_state_attributes(self) -> dict[str, Any]:
class OverkizSensorDescription(SensorEntityDescription):
"""Class to describe an Overkiz sensor."""

value: Callable[[str | int | float], str | int | float] | None = lambda val: val
native_value: Callable[
[str | int | float], str | int | float
] | None = lambda val: val


@dataclass
Expand Down
66 changes: 33 additions & 33 deletions custom_components/tahoma/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@
OverkizSensorDescription(
key="core:BatteryLevelState",
name="Battery Level",
unit_of_measurement=PERCENTAGE,
native_unit_of_measurement=PERCENTAGE,
device_class=sensor.DEVICE_CLASS_BATTERY,
state_class=STATE_CLASS_MEASUREMENT,
),
OverkizSensorDescription(
key="core:BatteryState",
name="Battery",
device_class=sensor.DEVICE_CLASS_BATTERY,
value=lambda value: str(value).capitalize(),
native_value=lambda value: str(value).capitalize(),
),
OverkizSensorDescription(
key="core:RSSILevelState",
name="RSSI Level",
unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
device_class=sensor.DEVICE_CLASS_SIGNAL_STRENGTH,
state_class=STATE_CLASS_MEASUREMENT,
value=lambda value: round(value),
native_value=lambda value: round(value),
),
OverkizSensorDescription(
key="core:ExpectedNumberOfShowerState",
Expand All @@ -62,29 +62,29 @@
key="core:V40WaterVolumeEstimationState",
name="Water Volume Estimation at 40 °C",
icon="mdi:water",
unit_of_measurement=VOLUME_LITERS,
native_unit_of_measurement=VOLUME_LITERS,
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
OverkizSensorDescription(
key="core:WaterConsumptionState",
name="Water Consumption",
icon="mdi:water",
unit_of_measurement=VOLUME_LITERS,
native_unit_of_measurement=VOLUME_LITERS,
state_class=STATE_CLASS_MEASUREMENT,
),
OverkizSensorDescription(
key="io:OutletEngineState",
name="Outlet Engine",
icon="mdi:fan-chevron-down",
unit_of_measurement=VOLUME_LITERS,
native_unit_of_measurement=VOLUME_LITERS,
state_class=STATE_CLASS_MEASUREMENT,
),
OverkizSensorDescription(
key="io:InletEngineState",
name="Inlet Engine",
icon="mdi:fan-chevron-up",
unit_of_measurement=VOLUME_FLOW_RATE_CUBIC_METERS_PER_HOUR,
native_unit_of_measurement=VOLUME_FLOW_RATE_CUBIC_METERS_PER_HOUR,
state_class=STATE_CLASS_MEASUREMENT,
),
OverkizSensorDescription(
Expand Down Expand Up @@ -117,113 +117,113 @@
key="core:LuminanceState",
name="Luminance",
device_class=sensor.DEVICE_CLASS_ILLUMINANCE,
unit_of_measurement=LIGHT_LUX, # core:MeasuredValueType = core:LuminanceInLux
native_unit_of_measurement=LIGHT_LUX, # core:MeasuredValueType = core:LuminanceInLux
state_class=STATE_CLASS_MEASUREMENT,
),
# ElectricitySensor/CumulativeElectricPowerConsumptionSensor
OverkizSensorDescription(
key="core:ElectricEnergyConsumptionState",
name="Electric Energy Consumption",
device_class=sensor.DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh (not for modbus:YutakiV2DHWElectricalEnergyConsumptionComponent)
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh (not for modbus:YutakiV2DHWElectricalEnergyConsumptionComponent)
state_class=STATE_CLASS_MEASUREMENT, # core:MeasurementCategory attribute = electric/overall
last_reset=utc_from_timestamp(0),
),
OverkizSensorDescription(
key="core:ElectricPowerConsumptionState",
name="Electric Power Consumption",
device_class=sensor.DEVICE_CLASS_POWER,
unit_of_measurement=POWER_WATT, # core:MeasuredValueType = core:ElectricalEnergyInWh (not for modbus:YutakiV2DHWElectricalEnergyConsumptionComponent)
native_unit_of_measurement=POWER_WATT, # core:MeasuredValueType = core:ElectricalEnergyInWh (not for modbus:YutakiV2DHWElectricalEnergyConsumptionComponent)
state_class=STATE_CLASS_MEASUREMENT,
),
OverkizSensorDescription(
key="core:ConsumptionTariff1State",
name="Consumption Tariff 1",
device_class=sensor.DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
OverkizSensorDescription(
key="core:ConsumptionTariff2State",
name="Consumption Tariff 2",
device_class=sensor.DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
OverkizSensorDescription(
key="core:ConsumptionTariff3State",
name="Consumption Tariff 3",
device_class=sensor.DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
OverkizSensorDescription(
key="core:ConsumptionTariff4State",
name="Consumption Tariff 4",
device_class=sensor.DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
OverkizSensorDescription(
key="core:ConsumptionTariff5State",
name="Consumption Tariff 5",
device_class=sensor.DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
OverkizSensorDescription(
key="core:ConsumptionTariff6State",
name="Consumption Tariff 6",
device_class=sensor.DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
OverkizSensorDescription(
key="core:ConsumptionTariff7State",
name="Consumption Tariff 7",
device_class=sensor.DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
OverkizSensorDescription(
key="core:ConsumptionTariff8State",
name="Consumption Tariff 8",
device_class=sensor.DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
OverkizSensorDescription(
key="core:ConsumptionTariff9State",
name="Consumption Tariff 9",
device_class=sensor.DEVICE_CLASS_ENERGY,
unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
native_unit_of_measurement=ENERGY_WATT_HOUR, # core:MeasuredValueType = core:ElectricalEnergyInWh
entity_registry_enabled_default=False,
state_class=STATE_CLASS_MEASUREMENT,
),
# HumiditySensor/RelativeHumiditySensor
OverkizSensorDescription(
key="core:RelativeHumidityState",
name="Relative Humidity",
value=lambda value: round(value, 2),
native_value=lambda value: round(value, 2),
device_class=sensor.DEVICE_CLASS_HUMIDITY,
unit_of_measurement=PERCENTAGE, # core:MeasuredValueType = core:RelativeValueInPercentage
native_unit_of_measurement=PERCENTAGE, # core:MeasuredValueType = core:RelativeValueInPercentage
state_class=STATE_CLASS_MEASUREMENT,
),
# TemperatureSensor/TemperatureSensor
OverkizSensorDescription(
key="core:TemperatureState",
name="Temperature",
value=lambda value: round(value, 2),
native_value=lambda value: round(value, 2),
device_class=sensor.DEVICE_CLASS_TEMPERATURE,
unit_of_measurement=TEMP_CELSIUS, # core:MeasuredValueType = core:TemperatureInCelcius
native_unit_of_measurement=TEMP_CELSIUS, # core:MeasuredValueType = core:TemperatureInCelcius
state_class=STATE_CLASS_MEASUREMENT,
),
# WeatherSensor/WeatherForecastSensor
Expand All @@ -235,37 +235,37 @@
key="core:MinimumTemperatureState",
name="Minimum Temperature",
device_class=sensor.DEVICE_CLASS_TEMPERATURE,
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
state_class=STATE_CLASS_MEASUREMENT,
),
OverkizSensorDescription(
key="core:MaximumTemperatureState",
name="Maximum Temperature",
device_class=sensor.DEVICE_CLASS_TEMPERATURE,
unit_of_measurement=TEMP_CELSIUS,
native_unit_of_measurement=TEMP_CELSIUS,
state_class=STATE_CLASS_MEASUREMENT,
),
# AirSensor/COSensor
OverkizSensorDescription(
key="core:COConcentrationState",
name="CO Concentration",
device_class=sensor.DEVICE_CLASS_CO,
unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
state_class=STATE_CLASS_MEASUREMENT,
),
# AirSensor/CO2Sensor
OverkizSensorDescription(
key="core:CO2ConcentrationState",
name="CO2 Concentration",
device_class=sensor.DEVICE_CLASS_CO2,
unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
state_class=STATE_CLASS_MEASUREMENT,
),
# SunSensor/SunEnergySensor
OverkizSensorDescription(
key="core:SunEnergyState",
name="Sun Energy",
value=lambda value: round(value, 2),
native_value=lambda value: round(value, 2),
device_class=sensor.DEVICE_CLASS_ENERGY,
icon="mdi:solar-power",
state_class=STATE_CLASS_MEASUREMENT,
Expand All @@ -274,29 +274,29 @@
OverkizSensorDescription(
key="core:WindSpeedState",
name="Wind Speed",
value=lambda value: round(value, 2),
native_value=lambda value: round(value, 2),
icon="mdi:weather-windy",
state_class=STATE_CLASS_MEASUREMENT,
),
# SmokeSensor/SmokeSensor
OverkizSensorDescription(
key="io:SensorRoomState",
name="Sensor Room",
value=lambda value: str(value).capitalize(),
native_value=lambda value: str(value).capitalize(),
entity_registry_enabled_default=False,
),
OverkizSensorDescription(
key="io:PriorityLockOriginatorState",
name="Priority Lock Originator",
value=lambda value: str(value).capitalize(),
native_value=lambda value: str(value).capitalize(),
icon="mdi:lock",
entity_registry_enabled_default=False,
),
OverkizSensorDescription(
key="core:PriorityLockTimerState",
name="Priority Lock Timer",
icon="mdi:lock-clock",
unit_of_measurement=TIME_SECONDS,
native_unit_of_measurement=TIME_SECONDS,
entity_registry_enabled_default=False,
),
]
Expand Down

0 comments on commit d46a4af

Please sign in to comment.