Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to native unit of measurement #550

Merged
merged 2 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
68 changes: 34 additions & 34 deletions custom_components/tahoma/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,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 @@ -65,29 +65,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 @@ -120,7 +120,7 @@
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
Expand All @@ -135,97 +135,97 @@
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 @@ -237,37 +237,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 @@ -276,29 +276,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 Expand Up @@ -345,7 +345,7 @@ def state(self):
return None

# Transform the value with a lambda function
if hasattr(self.entity_description, "value"):
return self.entity_description.value(state.value)
if hasattr(self.entity_description, "native_value"):
return self.entity_description.native_value(state.value)

return state.value