From 8de6f04829aa2fca5c19e95621e97c635487406e Mon Sep 17 00:00:00 2001 From: RSDynamics <34572043+RSDynamics@users.noreply.github.com> Date: Mon, 15 Dec 2025 17:42:42 +0100 Subject: [PATCH] Change Lektrico lifetime_energy sensor to float (#158880) --- .../components/lektrico/binary_sensor.py | 20 ++++---- homeassistant/components/lektrico/number.py | 4 +- homeassistant/components/lektrico/sensor.py | 46 +++++++++---------- .../lektrico/fixtures/get_info.json | 2 +- .../lektrico/snapshots/test_sensor.ambr | 2 +- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/homeassistant/components/lektrico/binary_sensor.py b/homeassistant/components/lektrico/binary_sensor.py index 37e55ade798..6ada6e8e4ad 100644 --- a/homeassistant/components/lektrico/binary_sensor.py +++ b/homeassistant/components/lektrico/binary_sensor.py @@ -30,70 +30,70 @@ BINARY_SENSORS: tuple[LektricoBinarySensorEntityDescription, ...] = ( translation_key="state_e_activated", entity_category=EntityCategory.DIAGNOSTIC, device_class=BinarySensorDeviceClass.PROBLEM, - value_fn=lambda data: bool(data["state_e_activated"]), + value_fn=lambda data: data["state_e_activated"], ), LektricoBinarySensorEntityDescription( key="overtemp", translation_key="overtemp", entity_category=EntityCategory.DIAGNOSTIC, device_class=BinarySensorDeviceClass.PROBLEM, - value_fn=lambda data: bool(data["overtemp"]), + value_fn=lambda data: data["overtemp"], ), LektricoBinarySensorEntityDescription( key="critical_temp", translation_key="critical_temp", entity_category=EntityCategory.DIAGNOSTIC, device_class=BinarySensorDeviceClass.PROBLEM, - value_fn=lambda data: bool(data["critical_temp"]), + value_fn=lambda data: data["critical_temp"], ), LektricoBinarySensorEntityDescription( key="overcurrent", translation_key="overcurrent", entity_category=EntityCategory.DIAGNOSTIC, device_class=BinarySensorDeviceClass.PROBLEM, - value_fn=lambda data: bool(data["overcurrent"]), + value_fn=lambda data: data["overcurrent"], ), LektricoBinarySensorEntityDescription( key="meter_fault", translation_key="meter_fault", entity_category=EntityCategory.DIAGNOSTIC, device_class=BinarySensorDeviceClass.PROBLEM, - value_fn=lambda data: bool(data["meter_fault"]), + value_fn=lambda data: data["meter_fault"], ), LektricoBinarySensorEntityDescription( key="undervoltage", translation_key="undervoltage", entity_category=EntityCategory.DIAGNOSTIC, device_class=BinarySensorDeviceClass.PROBLEM, - value_fn=lambda data: bool(data["undervoltage_error"]), + value_fn=lambda data: data["undervoltage_error"], ), LektricoBinarySensorEntityDescription( key="overvoltage", translation_key="overvoltage", entity_category=EntityCategory.DIAGNOSTIC, device_class=BinarySensorDeviceClass.PROBLEM, - value_fn=lambda data: bool(data["overvoltage_error"]), + value_fn=lambda data: data["overvoltage_error"], ), LektricoBinarySensorEntityDescription( key="rcd_error", translation_key="rcd_error", entity_category=EntityCategory.DIAGNOSTIC, device_class=BinarySensorDeviceClass.PROBLEM, - value_fn=lambda data: bool(data["rcd_error"]), + value_fn=lambda data: data["rcd_error"], ), LektricoBinarySensorEntityDescription( key="cp_diode_failure", translation_key="cp_diode_failure", entity_category=EntityCategory.DIAGNOSTIC, device_class=BinarySensorDeviceClass.PROBLEM, - value_fn=lambda data: bool(data["cp_diode_failure"]), + value_fn=lambda data: data["cp_diode_failure"], ), LektricoBinarySensorEntityDescription( key="contactor_failure", translation_key="contactor_failure", entity_category=EntityCategory.DIAGNOSTIC, device_class=BinarySensorDeviceClass.PROBLEM, - value_fn=lambda data: bool(data["contactor_failure"]), + value_fn=lambda data: data["contactor_failure"], ), ) diff --git a/homeassistant/components/lektrico/number.py b/homeassistant/components/lektrico/number.py index c54ee938607..0567aa4da84 100644 --- a/homeassistant/components/lektrico/number.py +++ b/homeassistant/components/lektrico/number.py @@ -38,7 +38,7 @@ NUMBERS: tuple[LektricoNumberEntityDescription, ...] = ( native_max_value=100, native_step=5, native_unit_of_measurement=PERCENTAGE, - value_fn=lambda data: int(data["led_max_brightness"]), + value_fn=lambda data: data["led_max_brightness"], set_value_fn=lambda data, value: data.set_led_max_brightness(value), ), LektricoNumberEntityDescription( @@ -49,7 +49,7 @@ NUMBERS: tuple[LektricoNumberEntityDescription, ...] = ( native_max_value=32, native_step=1, native_unit_of_measurement=UnitOfElectricCurrent.AMPERE, - value_fn=lambda data: int(data["dynamic_current"]), + value_fn=lambda data: data["dynamic_current"], set_value_fn=lambda data, value: data.set_dynamic_current(value), ), ) diff --git a/homeassistant/components/lektrico/sensor.py b/homeassistant/components/lektrico/sensor.py index 927011459b0..73e579569ca 100644 --- a/homeassistant/components/lektrico/sensor.py +++ b/homeassistant/components/lektrico/sensor.py @@ -79,7 +79,7 @@ SENSORS_FOR_CHARGERS: tuple[LektricoSensorEntityDescription, ...] = ( translation_key="charging_time", device_class=SensorDeviceClass.DURATION, native_unit_of_measurement=UnitOfTime.SECONDS, - value_fn=lambda data: int(data["charging_time"]), + value_fn=lambda data: data["charging_time"], ), LektricoSensorEntityDescription( key="power", @@ -87,20 +87,20 @@ SENSORS_FOR_CHARGERS: tuple[LektricoSensorEntityDescription, ...] = ( state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=UnitOfPower.WATT, suggested_unit_of_measurement=UnitOfPower.KILO_WATT, - value_fn=lambda data: float(data["instant_power"]), + value_fn=lambda data: data["instant_power"], ), LektricoSensorEntityDescription( key="energy", device_class=SensorDeviceClass.ENERGY, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, - value_fn=lambda data: float(data["session_energy"]) / 1000, + value_fn=lambda data: data["session_energy"] / 1000, ), LektricoSensorEntityDescription( key="temperature", device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=UnitOfTemperature.CELSIUS, - value_fn=lambda data: float(data["temperature"]), + value_fn=lambda data: data["temperature"], ), LektricoSensorEntityDescription( key="lifetime_energy", @@ -108,14 +108,14 @@ SENSORS_FOR_CHARGERS: tuple[LektricoSensorEntityDescription, ...] = ( state_class=SensorStateClass.TOTAL_INCREASING, device_class=SensorDeviceClass.ENERGY, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, - value_fn=lambda data: int(data["total_charged_energy"]), + value_fn=lambda data: data["total_charged_energy"], ), LektricoSensorEntityDescription( key="installation_current", translation_key="installation_current", device_class=SensorDeviceClass.CURRENT, native_unit_of_measurement=UnitOfElectricCurrent.AMPERE, - value_fn=lambda data: int(data["install_current"]), + value_fn=lambda data: data["install_current"], ), LektricoSensorEntityDescription( key="limit_reason", @@ -137,7 +137,7 @@ SENSORS_FOR_LB_DEVICES: tuple[LektricoSensorEntityDescription, ...] = ( device_class=SensorDeviceClass.CURRENT, state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=UnitOfElectricCurrent.AMPERE, - value_fn=lambda data: int(data["breaker_curent"]), + value_fn=lambda data: data["breaker_curent"], ), ) @@ -146,14 +146,14 @@ SENSORS_FOR_1_PHASE: tuple[LektricoSensorEntityDescription, ...] = ( key="voltage", device_class=SensorDeviceClass.VOLTAGE, native_unit_of_measurement=UnitOfElectricPotential.VOLT, - value_fn=lambda data: float(data["voltage_l1"]), + value_fn=lambda data: data["voltage_l1"], ), LektricoSensorEntityDescription( key="current", device_class=SensorDeviceClass.CURRENT, state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=UnitOfElectricCurrent.AMPERE, - value_fn=lambda data: float(data["current_l1"]), + value_fn=lambda data: data["current_l1"], ), ) @@ -163,21 +163,21 @@ SENSORS_FOR_3_PHASE: tuple[LektricoSensorEntityDescription, ...] = ( translation_key="voltage_l1", device_class=SensorDeviceClass.VOLTAGE, native_unit_of_measurement=UnitOfElectricPotential.VOLT, - value_fn=lambda data: float(data["voltage_l1"]), + value_fn=lambda data: data["voltage_l1"], ), LektricoSensorEntityDescription( key="voltage_l2", translation_key="voltage_l2", device_class=SensorDeviceClass.VOLTAGE, native_unit_of_measurement=UnitOfElectricPotential.VOLT, - value_fn=lambda data: float(data["voltage_l2"]), + value_fn=lambda data: data["voltage_l2"], ), LektricoSensorEntityDescription( key="voltage_l3", translation_key="voltage_l3", device_class=SensorDeviceClass.VOLTAGE, native_unit_of_measurement=UnitOfElectricPotential.VOLT, - value_fn=lambda data: float(data["voltage_l3"]), + value_fn=lambda data: data["voltage_l3"], ), LektricoSensorEntityDescription( key="current_l1", @@ -185,7 +185,7 @@ SENSORS_FOR_3_PHASE: tuple[LektricoSensorEntityDescription, ...] = ( device_class=SensorDeviceClass.CURRENT, state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=UnitOfElectricCurrent.AMPERE, - value_fn=lambda data: float(data["current_l1"]), + value_fn=lambda data: data["current_l1"], ), LektricoSensorEntityDescription( key="current_l2", @@ -193,7 +193,7 @@ SENSORS_FOR_3_PHASE: tuple[LektricoSensorEntityDescription, ...] = ( device_class=SensorDeviceClass.CURRENT, state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=UnitOfElectricCurrent.AMPERE, - value_fn=lambda data: float(data["current_l2"]), + value_fn=lambda data: data["current_l2"], ), LektricoSensorEntityDescription( key="current_l3", @@ -201,7 +201,7 @@ SENSORS_FOR_3_PHASE: tuple[LektricoSensorEntityDescription, ...] = ( device_class=SensorDeviceClass.CURRENT, state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=UnitOfElectricCurrent.AMPERE, - value_fn=lambda data: float(data["current_l3"]), + value_fn=lambda data: data["current_l3"], ), ) @@ -213,14 +213,14 @@ SENSORS_FOR_LB_1_PHASE: tuple[LektricoSensorEntityDescription, ...] = ( state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=UnitOfPower.WATT, suggested_unit_of_measurement=UnitOfPower.KILO_WATT, - value_fn=lambda data: float(data["power_l1"]), + value_fn=lambda data: data["power_l1"], ), LektricoSensorEntityDescription( key="pf", device_class=SensorDeviceClass.POWER_FACTOR, state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=PERCENTAGE, - value_fn=lambda data: float(data["power_factor_l1"]) * 100, + value_fn=lambda data: data["power_factor_l1"] * 100, ), ) @@ -233,7 +233,7 @@ SENSORS_FOR_LB_3_PHASE: tuple[LektricoSensorEntityDescription, ...] = ( state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=UnitOfPower.WATT, suggested_unit_of_measurement=UnitOfPower.KILO_WATT, - value_fn=lambda data: float(data["power_l1"]), + value_fn=lambda data: data["power_l1"], ), LektricoSensorEntityDescription( key="power_l2", @@ -242,7 +242,7 @@ SENSORS_FOR_LB_3_PHASE: tuple[LektricoSensorEntityDescription, ...] = ( state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=UnitOfPower.WATT, suggested_unit_of_measurement=UnitOfPower.KILO_WATT, - value_fn=lambda data: float(data["power_l2"]), + value_fn=lambda data: data["power_l2"], ), LektricoSensorEntityDescription( key="power_l3", @@ -251,7 +251,7 @@ SENSORS_FOR_LB_3_PHASE: tuple[LektricoSensorEntityDescription, ...] = ( state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=UnitOfPower.WATT, suggested_unit_of_measurement=UnitOfPower.KILO_WATT, - value_fn=lambda data: float(data["power_l3"]), + value_fn=lambda data: data["power_l3"], ), LektricoSensorEntityDescription( key="pf_l1", @@ -259,7 +259,7 @@ SENSORS_FOR_LB_3_PHASE: tuple[LektricoSensorEntityDescription, ...] = ( device_class=SensorDeviceClass.POWER_FACTOR, state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=PERCENTAGE, - value_fn=lambda data: float(data["power_factor_l1"]) * 100, + value_fn=lambda data: data["power_factor_l1"] * 100, ), LektricoSensorEntityDescription( key="pf_l2", @@ -267,7 +267,7 @@ SENSORS_FOR_LB_3_PHASE: tuple[LektricoSensorEntityDescription, ...] = ( device_class=SensorDeviceClass.POWER_FACTOR, state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=PERCENTAGE, - value_fn=lambda data: float(data["power_factor_l2"]) * 100, + value_fn=lambda data: data["power_factor_l2"] * 100, ), LektricoSensorEntityDescription( key="pf_l3", @@ -275,7 +275,7 @@ SENSORS_FOR_LB_3_PHASE: tuple[LektricoSensorEntityDescription, ...] = ( device_class=SensorDeviceClass.POWER_FACTOR, state_class=SensorStateClass.MEASUREMENT, native_unit_of_measurement=PERCENTAGE, - value_fn=lambda data: float(data["power_factor_l3"]) * 100, + value_fn=lambda data: data["power_factor_l3"] * 100, ), ) diff --git a/tests/components/lektrico/fixtures/get_info.json b/tests/components/lektrico/fixtures/get_info.json index 2b099a666e5..6528ec73d92 100644 --- a/tests/components/lektrico/fixtures/get_info.json +++ b/tests/components/lektrico/fixtures/get_info.json @@ -4,7 +4,7 @@ "instant_power": 0, "session_energy": 0.0, "temperature": 34.5, - "total_charged_energy": 0, + "total_charged_energy": 1.123, "install_current": 6, "current_limit_reason": "installation_current", "voltage_l1": 220.0, diff --git a/tests/components/lektrico/snapshots/test_sensor.ambr b/tests/components/lektrico/snapshots/test_sensor.ambr index 569c6af4c04..1d3796ef437 100644 --- a/tests/components/lektrico/snapshots/test_sensor.ambr +++ b/tests/components/lektrico/snapshots/test_sensor.ambr @@ -267,7 +267,7 @@ 'last_changed': , 'last_reported': , 'last_updated': , - 'state': '0', + 'state': '1.123', }) # --- # name: test_all_entities[sensor.1p7k_500006_limit_reason-entry]