Do not allow zerovalue as total_increasing for homewizard sensors (#90982)

* Do not allow zerovalue  as total_increasing

* Fix for solar exports

* Revert not needed change

* Adjust handling, making tests pass

---------

Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
Jan Bouwhuis 2023-06-28 09:53:33 +02:00 committed by GitHub
parent cfb133d431
commit 265ccae54f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -38,6 +38,7 @@ PARALLEL_UPDATES = 1
class HomeWizardEntityDescriptionMixin: class HomeWizardEntityDescriptionMixin:
"""Mixin values for HomeWizard entities.""" """Mixin values for HomeWizard entities."""
has_fn: Callable[[Data], bool]
value_fn: Callable[[Data], float | int | str | None] value_fn: Callable[[Data], float | int | str | None]
@ -47,6 +48,8 @@ class HomeWizardSensorEntityDescription(
): ):
"""Class describing HomeWizard sensor entities.""" """Class describing HomeWizard sensor entities."""
enabled_fn: Callable[[Data], bool] = lambda data: True
SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = ( SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -54,6 +57,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
name="DSMR version", name="DSMR version",
icon="mdi:counter", icon="mdi:counter",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
has_fn=lambda data: data.smr_version is not None,
value_fn=lambda data: data.smr_version, value_fn=lambda data: data.smr_version,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -61,6 +65,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
name="Smart meter model", name="Smart meter model",
icon="mdi:gauge", icon="mdi:gauge",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
has_fn=lambda data: data.meter_model is not None,
value_fn=lambda data: data.meter_model, value_fn=lambda data: data.meter_model,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -68,6 +73,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
name="Smart meter identifier", name="Smart meter identifier",
icon="mdi:alphabetical-variant", icon="mdi:alphabetical-variant",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
has_fn=lambda data: data.unique_meter_id is not None,
value_fn=lambda data: data.unique_meter_id, value_fn=lambda data: data.unique_meter_id,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -75,12 +81,14 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
name="Wi-Fi SSID", name="Wi-Fi SSID",
icon="mdi:wifi", icon="mdi:wifi",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
has_fn=lambda data: data.wifi_ssid is not None,
value_fn=lambda data: data.wifi_ssid, value_fn=lambda data: data.wifi_ssid,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
key="active_tariff", key="active_tariff",
name="Active tariff", name="Active tariff",
icon="mdi:calendar-clock", icon="mdi:calendar-clock",
has_fn=lambda data: data.active_tariff is not None,
value_fn=lambda data: ( value_fn=lambda data: (
None if data.active_tariff is None else str(data.active_tariff) None if data.active_tariff is None else str(data.active_tariff)
), ),
@ -95,6 +103,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
has_fn=lambda data: data.wifi_strength is not None,
value_fn=lambda data: data.wifi_strength, value_fn=lambda data: data.wifi_strength,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -103,7 +112,8 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
value_fn=lambda data: data.total_power_import_kwh, has_fn=lambda data: data.total_power_import_kwh is not None,
value_fn=lambda data: data.total_power_import_kwh or None,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
key="total_power_import_t1_kwh", key="total_power_import_t1_kwh",
@ -111,7 +121,8 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
value_fn=lambda data: data.total_power_import_t1_kwh, has_fn=lambda data: data.total_power_import_t1_kwh is not None,
value_fn=lambda data: data.total_power_import_t1_kwh or None,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
key="total_power_import_t2_kwh", key="total_power_import_t2_kwh",
@ -119,7 +130,8 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
value_fn=lambda data: data.total_power_import_t2_kwh, has_fn=lambda data: data.total_power_import_t2_kwh is not None,
value_fn=lambda data: data.total_power_import_t2_kwh or None,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
key="total_power_import_t3_kwh", key="total_power_import_t3_kwh",
@ -127,7 +139,8 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
value_fn=lambda data: data.total_power_import_t3_kwh, has_fn=lambda data: data.total_power_import_t3_kwh is not None,
value_fn=lambda data: data.total_power_import_t3_kwh or None,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
key="total_power_import_t4_kwh", key="total_power_import_t4_kwh",
@ -135,7 +148,8 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
value_fn=lambda data: data.total_power_import_t4_kwh, has_fn=lambda data: data.total_power_import_t4_kwh is not None,
value_fn=lambda data: data.total_power_import_t4_kwh or None,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
key="total_power_export_kwh", key="total_power_export_kwh",
@ -143,7 +157,9 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
value_fn=lambda data: data.total_power_export_kwh, has_fn=lambda data: data.total_power_export_kwh is not None,
enabled_fn=lambda data: data.total_power_export_kwh != 0,
value_fn=lambda data: data.total_power_export_kwh or None,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
key="total_power_export_t1_kwh", key="total_power_export_t1_kwh",
@ -151,7 +167,9 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
value_fn=lambda data: data.total_power_export_t1_kwh, has_fn=lambda data: data.total_power_export_t1_kwh is not None,
enabled_fn=lambda data: data.total_power_export_t1_kwh != 0,
value_fn=lambda data: data.total_power_export_t1_kwh or None,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
key="total_power_export_t2_kwh", key="total_power_export_t2_kwh",
@ -159,7 +177,9 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
value_fn=lambda data: data.total_power_export_t2_kwh, has_fn=lambda data: data.total_power_export_t2_kwh is not None,
enabled_fn=lambda data: data.total_power_export_t2_kwh != 0,
value_fn=lambda data: data.total_power_export_t2_kwh or None,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
key="total_power_export_t3_kwh", key="total_power_export_t3_kwh",
@ -167,7 +187,9 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
value_fn=lambda data: data.total_power_export_t3_kwh, has_fn=lambda data: data.total_power_export_t3_kwh is not None,
enabled_fn=lambda data: data.total_power_export_t3_kwh != 0,
value_fn=lambda data: data.total_power_export_t3_kwh or None,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
key="total_power_export_t4_kwh", key="total_power_export_t4_kwh",
@ -175,7 +197,9 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR,
device_class=SensorDeviceClass.ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
value_fn=lambda data: data.total_power_export_t4_kwh, has_fn=lambda data: data.total_power_export_t4_kwh is not None,
enabled_fn=lambda data: data.total_power_export_t4_kwh != 0,
value_fn=lambda data: data.total_power_export_t4_kwh or None,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
key="active_power_w", key="active_power_w",
@ -183,6 +207,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
native_unit_of_measurement=UnitOfPower.WATT, native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
has_fn=lambda data: data.active_power_w is not None,
value_fn=lambda data: data.active_power_w, value_fn=lambda data: data.active_power_w,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -191,6 +216,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
native_unit_of_measurement=UnitOfPower.WATT, native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
has_fn=lambda data: data.active_power_l1_w is not None,
value_fn=lambda data: data.active_power_l1_w, value_fn=lambda data: data.active_power_l1_w,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -199,6 +225,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
native_unit_of_measurement=UnitOfPower.WATT, native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
has_fn=lambda data: data.active_power_l2_w is not None,
value_fn=lambda data: data.active_power_l2_w, value_fn=lambda data: data.active_power_l2_w,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -207,6 +234,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
native_unit_of_measurement=UnitOfPower.WATT, native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
has_fn=lambda data: data.active_power_l3_w is not None,
value_fn=lambda data: data.active_power_l3_w, value_fn=lambda data: data.active_power_l3_w,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -216,6 +244,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
device_class=SensorDeviceClass.VOLTAGE, device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
has_fn=lambda data: data.active_voltage_l1_v is not None,
value_fn=lambda data: data.active_voltage_l1_v, value_fn=lambda data: data.active_voltage_l1_v,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -225,6 +254,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
device_class=SensorDeviceClass.VOLTAGE, device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
has_fn=lambda data: data.active_voltage_l2_v is not None,
value_fn=lambda data: data.active_voltage_l2_v, value_fn=lambda data: data.active_voltage_l2_v,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -234,6 +264,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
device_class=SensorDeviceClass.VOLTAGE, device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
has_fn=lambda data: data.active_voltage_l3_v is not None,
value_fn=lambda data: data.active_voltage_l3_v, value_fn=lambda data: data.active_voltage_l3_v,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -243,6 +274,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
device_class=SensorDeviceClass.CURRENT, device_class=SensorDeviceClass.CURRENT,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
has_fn=lambda data: data.active_current_l1_a is not None,
value_fn=lambda data: data.active_current_l1_a, value_fn=lambda data: data.active_current_l1_a,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -252,6 +284,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
device_class=SensorDeviceClass.CURRENT, device_class=SensorDeviceClass.CURRENT,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
has_fn=lambda data: data.active_current_l2_a is not None,
value_fn=lambda data: data.active_current_l2_a, value_fn=lambda data: data.active_current_l2_a,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -261,6 +294,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
device_class=SensorDeviceClass.CURRENT, device_class=SensorDeviceClass.CURRENT,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
has_fn=lambda data: data.active_current_l3_a is not None,
value_fn=lambda data: data.active_current_l3_a, value_fn=lambda data: data.active_current_l3_a,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -270,6 +304,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
device_class=SensorDeviceClass.FREQUENCY, device_class=SensorDeviceClass.FREQUENCY,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
has_fn=lambda data: data.active_frequency_hz is not None,
value_fn=lambda data: data.active_frequency_hz, value_fn=lambda data: data.active_frequency_hz,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -277,6 +312,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
name="Voltage sags detected L1", name="Voltage sags detected L1",
icon="mdi:alert", icon="mdi:alert",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
has_fn=lambda data: data.voltage_sag_l1_count is not None,
value_fn=lambda data: data.voltage_sag_l1_count, value_fn=lambda data: data.voltage_sag_l1_count,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -284,6 +320,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
name="Voltage sags detected L2", name="Voltage sags detected L2",
icon="mdi:alert", icon="mdi:alert",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
has_fn=lambda data: data.voltage_sag_l2_count is not None,
value_fn=lambda data: data.voltage_sag_l2_count, value_fn=lambda data: data.voltage_sag_l2_count,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -291,6 +328,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
name="Voltage sags detected L3", name="Voltage sags detected L3",
icon="mdi:alert", icon="mdi:alert",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
has_fn=lambda data: data.voltage_sag_l3_count is not None,
value_fn=lambda data: data.voltage_sag_l3_count, value_fn=lambda data: data.voltage_sag_l3_count,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -298,6 +336,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
name="Voltage swells detected L1", name="Voltage swells detected L1",
icon="mdi:alert", icon="mdi:alert",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
has_fn=lambda data: data.voltage_swell_l1_count is not None,
value_fn=lambda data: data.voltage_swell_l1_count, value_fn=lambda data: data.voltage_swell_l1_count,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -305,6 +344,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
name="Voltage swells detected L2", name="Voltage swells detected L2",
icon="mdi:alert", icon="mdi:alert",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
has_fn=lambda data: data.voltage_swell_l2_count is not None,
value_fn=lambda data: data.voltage_swell_l2_count, value_fn=lambda data: data.voltage_swell_l2_count,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -312,6 +352,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
name="Voltage swells detected L3", name="Voltage swells detected L3",
icon="mdi:alert", icon="mdi:alert",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
has_fn=lambda data: data.voltage_swell_l3_count is not None,
value_fn=lambda data: data.voltage_swell_l3_count, value_fn=lambda data: data.voltage_swell_l3_count,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -319,6 +360,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
name="Power failures detected", name="Power failures detected",
icon="mdi:transmission-tower-off", icon="mdi:transmission-tower-off",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
has_fn=lambda data: data.any_power_fail_count is not None,
value_fn=lambda data: data.any_power_fail_count, value_fn=lambda data: data.any_power_fail_count,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -326,6 +368,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
name="Long power failures detected", name="Long power failures detected",
icon="mdi:transmission-tower-off", icon="mdi:transmission-tower-off",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
has_fn=lambda data: data.long_power_fail_count is not None,
value_fn=lambda data: data.long_power_fail_count, value_fn=lambda data: data.long_power_fail_count,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -333,6 +376,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
name="Active average demand", name="Active average demand",
native_unit_of_measurement=UnitOfPower.WATT, native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
has_fn=lambda data: data.active_power_average_w is not None,
value_fn=lambda data: data.active_power_average_w, value_fn=lambda data: data.active_power_average_w,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -340,6 +384,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
name="Peak demand current month", name="Peak demand current month",
native_unit_of_measurement=UnitOfPower.WATT, native_unit_of_measurement=UnitOfPower.WATT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
has_fn=lambda data: data.monthly_power_peak_w is not None,
value_fn=lambda data: data.monthly_power_peak_w, value_fn=lambda data: data.monthly_power_peak_w,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -348,13 +393,15 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
native_unit_of_measurement=UnitOfVolume.CUBIC_METERS, native_unit_of_measurement=UnitOfVolume.CUBIC_METERS,
device_class=SensorDeviceClass.GAS, device_class=SensorDeviceClass.GAS,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
value_fn=lambda data: data.total_gas_m3, has_fn=lambda data: data.total_gas_m3 is not None,
value_fn=lambda data: data.total_gas_m3 or None,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
key="gas_unique_id", key="gas_unique_id",
name="Gas meter identifier", name="Gas meter identifier",
icon="mdi:alphabetical-variant", icon="mdi:alphabetical-variant",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
has_fn=lambda data: data.gas_unique_id is not None,
value_fn=lambda data: data.gas_unique_id, value_fn=lambda data: data.gas_unique_id,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -363,6 +410,7 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
native_unit_of_measurement="l/min", native_unit_of_measurement="l/min",
icon="mdi:water", icon="mdi:water",
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
has_fn=lambda data: data.active_liter_lpm is not None,
value_fn=lambda data: data.active_liter_lpm, value_fn=lambda data: data.active_liter_lpm,
), ),
HomeWizardSensorEntityDescription( HomeWizardSensorEntityDescription(
@ -372,7 +420,8 @@ SENSORS: Final[tuple[HomeWizardSensorEntityDescription, ...]] = (
icon="mdi:gauge", icon="mdi:gauge",
device_class=SensorDeviceClass.WATER, device_class=SensorDeviceClass.WATER,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
value_fn=lambda data: data.total_liter_m3, has_fn=lambda data: data.total_liter_m3 is not None,
value_fn=lambda data: data.total_liter_m3 or None,
), ),
) )
@ -386,7 +435,7 @@ async def async_setup_entry(
async_add_entities( async_add_entities(
HomeWizardSensorEntity(coordinator, entry, description) HomeWizardSensorEntity(coordinator, entry, description)
for description in SENSORS for description in SENSORS
if description.value_fn(coordinator.data.data) is not None if description.has_fn(coordinator.data.data)
) )
@ -405,20 +454,7 @@ class HomeWizardSensorEntity(HomeWizardEntity, SensorEntity):
super().__init__(coordinator) super().__init__(coordinator)
self.entity_description = description self.entity_description = description
self._attr_unique_id = f"{entry.unique_id}_{description.key}" self._attr_unique_id = f"{entry.unique_id}_{description.key}"
if not description.enabled_fn(self.coordinator.data.data):
# Special case for export, not everyone has solar panels
# The chance that 'export' is non-zero when you have solar panels is nil
if (
description.key
in [
"total_power_export_kwh",
"total_power_export_t1_kwh",
"total_power_export_t2_kwh",
"total_power_export_t3_kwh",
"total_power_export_t4_kwh",
]
and self.native_value == 0
):
self._attr_entity_registry_enabled_default = False self._attr_entity_registry_enabled_default = False
@property @property