diff --git a/homeassistant/components/homewizard/sensor.py b/homeassistant/components/homewizard/sensor.py index 87235cdb6f23f..78cee9ee6fec9 100644 --- a/homeassistant/components/homewizard/sensor.py +++ b/homeassistant/components/homewizard/sensor.py @@ -114,7 +114,11 @@ class HomeWizardSensorEntityDescription(SensorEntityDescription): native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, - has_fn=lambda data: data.total_energy_import_t1_kwh is not None, + has_fn=lambda data: ( + # SKT/SDM230/630 provides both total and tariff 1: duplicate. + data.total_energy_import_t1_kwh is not None + and data.total_energy_export_t2_kwh is not None + ), value_fn=lambda data: data.total_energy_import_t1_kwh, ), HomeWizardSensorEntityDescription( @@ -160,7 +164,11 @@ class HomeWizardSensorEntityDescription(SensorEntityDescription): native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, device_class=SensorDeviceClass.ENERGY, state_class=SensorStateClass.TOTAL_INCREASING, - has_fn=lambda data: data.total_energy_export_t1_kwh is not None, + has_fn=lambda data: ( + # SKT/SDM230/630 provides both total and tariff 1: duplicate. + data.total_energy_export_t1_kwh is not None + and data.total_energy_export_t2_kwh is not None + ), enabled_fn=lambda data: data.total_energy_export_t1_kwh != 0, value_fn=lambda data: data.total_energy_export_t1_kwh, ), diff --git a/tests/components/homewizard/snapshots/test_sensor.ambr b/tests/components/homewizard/snapshots/test_sensor.ambr index 9e49c42ea98ed..e237edee58eb2 100644 --- a/tests/components/homewizard/snapshots/test_sensor.ambr +++ b/tests/components/homewizard/snapshots/test_sensor.ambr @@ -6185,86 +6185,6 @@ 'state': '0', }) # --- -# name: test_sensors[HWE-SKT-entity_ids2][sensor.device_total_energy_export_tariff_1:device-registry] - DeviceRegistryEntrySnapshot({ - 'area_id': None, - 'config_entries': , - 'configuration_url': None, - 'connections': set({ - tuple( - 'mac', - '3c:39:e7:aa:bb:cc', - ), - }), - 'disabled_by': None, - 'entry_type': None, - 'hw_version': None, - 'id': , - 'identifiers': set({ - tuple( - 'homewizard', - '3c39e7aabbcc', - ), - }), - 'is_new': False, - 'manufacturer': 'HomeWizard', - 'model': 'HWE-SKT', - 'name': 'Device', - 'name_by_user': None, - 'serial_number': None, - 'suggested_area': None, - 'sw_version': '3.03', - 'via_device_id': None, - }) -# --- -# name: test_sensors[HWE-SKT-entity_ids2][sensor.device_total_energy_export_tariff_1:entity-registry] - EntityRegistryEntrySnapshot({ - 'aliases': set({ - }), - 'area_id': None, - 'capabilities': dict({ - 'state_class': , - }), - 'config_entry_id': , - 'device_class': None, - 'device_id': , - 'disabled_by': None, - 'domain': 'sensor', - 'entity_category': None, - 'entity_id': 'sensor.device_total_energy_export_tariff_1', - 'has_entity_name': True, - 'hidden_by': None, - 'icon': None, - 'id': , - 'name': None, - 'options': dict({ - }), - 'original_device_class': , - 'original_icon': None, - 'original_name': 'Total energy export tariff 1', - 'platform': 'homewizard', - 'previous_unique_id': None, - 'supported_features': 0, - 'translation_key': 'total_energy_export_t1_kwh', - 'unique_id': 'aabbccddeeff_total_power_export_t1_kwh', - 'unit_of_measurement': , - }) -# --- -# name: test_sensors[HWE-SKT-entity_ids2][sensor.device_total_energy_export_tariff_1:state] - StateSnapshot({ - 'attributes': ReadOnlyDict({ - 'device_class': 'energy', - 'friendly_name': 'Device Total energy export tariff 1', - 'state_class': , - 'unit_of_measurement': , - }), - 'context': , - 'entity_id': 'sensor.device_total_energy_export_tariff_1', - 'last_changed': , - 'last_updated': , - 'state': '0', - }) -# --- # name: test_sensors[HWE-SKT-entity_ids2][sensor.device_total_energy_import:device-registry] DeviceRegistryEntrySnapshot({ 'area_id': None, @@ -6345,86 +6265,6 @@ 'state': '63.651', }) # --- -# name: test_sensors[HWE-SKT-entity_ids2][sensor.device_total_energy_import_tariff_1:device-registry] - DeviceRegistryEntrySnapshot({ - 'area_id': None, - 'config_entries': , - 'configuration_url': None, - 'connections': set({ - tuple( - 'mac', - '3c:39:e7:aa:bb:cc', - ), - }), - 'disabled_by': None, - 'entry_type': None, - 'hw_version': None, - 'id': , - 'identifiers': set({ - tuple( - 'homewizard', - '3c39e7aabbcc', - ), - }), - 'is_new': False, - 'manufacturer': 'HomeWizard', - 'model': 'HWE-SKT', - 'name': 'Device', - 'name_by_user': None, - 'serial_number': None, - 'suggested_area': None, - 'sw_version': '3.03', - 'via_device_id': None, - }) -# --- -# name: test_sensors[HWE-SKT-entity_ids2][sensor.device_total_energy_import_tariff_1:entity-registry] - EntityRegistryEntrySnapshot({ - 'aliases': set({ - }), - 'area_id': None, - 'capabilities': dict({ - 'state_class': , - }), - 'config_entry_id': , - 'device_class': None, - 'device_id': , - 'disabled_by': None, - 'domain': 'sensor', - 'entity_category': None, - 'entity_id': 'sensor.device_total_energy_import_tariff_1', - 'has_entity_name': True, - 'hidden_by': None, - 'icon': None, - 'id': , - 'name': None, - 'options': dict({ - }), - 'original_device_class': , - 'original_icon': None, - 'original_name': 'Total energy import tariff 1', - 'platform': 'homewizard', - 'previous_unique_id': None, - 'supported_features': 0, - 'translation_key': 'total_energy_import_t1_kwh', - 'unique_id': 'aabbccddeeff_total_power_import_t1_kwh', - 'unit_of_measurement': , - }) -# --- -# name: test_sensors[HWE-SKT-entity_ids2][sensor.device_total_energy_import_tariff_1:state] - StateSnapshot({ - 'attributes': ReadOnlyDict({ - 'device_class': 'energy', - 'friendly_name': 'Device Total energy import tariff 1', - 'state_class': , - 'unit_of_measurement': , - }), - 'context': , - 'entity_id': 'sensor.device_total_energy_import_tariff_1', - 'last_changed': , - 'last_updated': , - 'state': '63.651', - }) -# --- # name: test_sensors[HWE-SKT-entity_ids2][sensor.device_wi_fi_ssid:device-registry] DeviceRegistryEntrySnapshot({ 'area_id': None, @@ -7144,86 +6984,6 @@ 'state': '255.551', }) # --- -# name: test_sensors[SDM230-entity_ids4][sensor.device_total_energy_export_tariff_1:device-registry] - DeviceRegistryEntrySnapshot({ - 'area_id': None, - 'config_entries': , - 'configuration_url': None, - 'connections': set({ - tuple( - 'mac', - '3c:39:e7:aa:bb:cc', - ), - }), - 'disabled_by': None, - 'entry_type': None, - 'hw_version': None, - 'id': , - 'identifiers': set({ - tuple( - 'homewizard', - '3c39e7aabbcc', - ), - }), - 'is_new': False, - 'manufacturer': 'HomeWizard', - 'model': 'SDM230-wifi', - 'name': 'Device', - 'name_by_user': None, - 'serial_number': None, - 'suggested_area': None, - 'sw_version': '3.06', - 'via_device_id': None, - }) -# --- -# name: test_sensors[SDM230-entity_ids4][sensor.device_total_energy_export_tariff_1:entity-registry] - EntityRegistryEntrySnapshot({ - 'aliases': set({ - }), - 'area_id': None, - 'capabilities': dict({ - 'state_class': , - }), - 'config_entry_id': , - 'device_class': None, - 'device_id': , - 'disabled_by': None, - 'domain': 'sensor', - 'entity_category': None, - 'entity_id': 'sensor.device_total_energy_export_tariff_1', - 'has_entity_name': True, - 'hidden_by': None, - 'icon': None, - 'id': , - 'name': None, - 'options': dict({ - }), - 'original_device_class': , - 'original_icon': None, - 'original_name': 'Total energy export tariff 1', - 'platform': 'homewizard', - 'previous_unique_id': None, - 'supported_features': 0, - 'translation_key': 'total_energy_export_t1_kwh', - 'unique_id': 'aabbccddeeff_total_power_export_t1_kwh', - 'unit_of_measurement': , - }) -# --- -# name: test_sensors[SDM230-entity_ids4][sensor.device_total_energy_export_tariff_1:state] - StateSnapshot({ - 'attributes': ReadOnlyDict({ - 'device_class': 'energy', - 'friendly_name': 'Device Total energy export tariff 1', - 'state_class': , - 'unit_of_measurement': , - }), - 'context': , - 'entity_id': 'sensor.device_total_energy_export_tariff_1', - 'last_changed': , - 'last_updated': , - 'state': '255.551', - }) -# --- # name: test_sensors[SDM230-entity_ids4][sensor.device_total_energy_import:device-registry] DeviceRegistryEntrySnapshot({ 'area_id': None, @@ -7304,86 +7064,6 @@ 'state': '2.705', }) # --- -# name: test_sensors[SDM230-entity_ids4][sensor.device_total_energy_import_tariff_1:device-registry] - DeviceRegistryEntrySnapshot({ - 'area_id': None, - 'config_entries': , - 'configuration_url': None, - 'connections': set({ - tuple( - 'mac', - '3c:39:e7:aa:bb:cc', - ), - }), - 'disabled_by': None, - 'entry_type': None, - 'hw_version': None, - 'id': , - 'identifiers': set({ - tuple( - 'homewizard', - '3c39e7aabbcc', - ), - }), - 'is_new': False, - 'manufacturer': 'HomeWizard', - 'model': 'SDM230-wifi', - 'name': 'Device', - 'name_by_user': None, - 'serial_number': None, - 'suggested_area': None, - 'sw_version': '3.06', - 'via_device_id': None, - }) -# --- -# name: test_sensors[SDM230-entity_ids4][sensor.device_total_energy_import_tariff_1:entity-registry] - EntityRegistryEntrySnapshot({ - 'aliases': set({ - }), - 'area_id': None, - 'capabilities': dict({ - 'state_class': , - }), - 'config_entry_id': , - 'device_class': None, - 'device_id': , - 'disabled_by': None, - 'domain': 'sensor', - 'entity_category': None, - 'entity_id': 'sensor.device_total_energy_import_tariff_1', - 'has_entity_name': True, - 'hidden_by': None, - 'icon': None, - 'id': , - 'name': None, - 'options': dict({ - }), - 'original_device_class': , - 'original_icon': None, - 'original_name': 'Total energy import tariff 1', - 'platform': 'homewizard', - 'previous_unique_id': None, - 'supported_features': 0, - 'translation_key': 'total_energy_import_t1_kwh', - 'unique_id': 'aabbccddeeff_total_power_import_t1_kwh', - 'unit_of_measurement': , - }) -# --- -# name: test_sensors[SDM230-entity_ids4][sensor.device_total_energy_import_tariff_1:state] - StateSnapshot({ - 'attributes': ReadOnlyDict({ - 'device_class': 'energy', - 'friendly_name': 'Device Total energy import tariff 1', - 'state_class': , - 'unit_of_measurement': , - }), - 'context': , - 'entity_id': 'sensor.device_total_energy_import_tariff_1', - 'last_changed': , - 'last_updated': , - 'state': '2.705', - }) -# --- # name: test_sensors[SDM230-entity_ids4][sensor.device_wi_fi_ssid:device-registry] DeviceRegistryEntrySnapshot({ 'area_id': None, @@ -7952,86 +7632,6 @@ 'state': '0.523', }) # --- -# name: test_sensors[SDM630-entity_ids5][sensor.device_total_energy_export_tariff_1:device-registry] - DeviceRegistryEntrySnapshot({ - 'area_id': None, - 'config_entries': , - 'configuration_url': None, - 'connections': set({ - tuple( - 'mac', - '3c:39:e7:aa:bb:cc', - ), - }), - 'disabled_by': None, - 'entry_type': None, - 'hw_version': None, - 'id': , - 'identifiers': set({ - tuple( - 'homewizard', - '3c39e7aabbcc', - ), - }), - 'is_new': False, - 'manufacturer': 'HomeWizard', - 'model': 'SDM630-wifi', - 'name': 'Device', - 'name_by_user': None, - 'serial_number': None, - 'suggested_area': None, - 'sw_version': '3.06', - 'via_device_id': None, - }) -# --- -# name: test_sensors[SDM630-entity_ids5][sensor.device_total_energy_export_tariff_1:entity-registry] - EntityRegistryEntrySnapshot({ - 'aliases': set({ - }), - 'area_id': None, - 'capabilities': dict({ - 'state_class': , - }), - 'config_entry_id': , - 'device_class': None, - 'device_id': , - 'disabled_by': None, - 'domain': 'sensor', - 'entity_category': None, - 'entity_id': 'sensor.device_total_energy_export_tariff_1', - 'has_entity_name': True, - 'hidden_by': None, - 'icon': None, - 'id': , - 'name': None, - 'options': dict({ - }), - 'original_device_class': , - 'original_icon': None, - 'original_name': 'Total energy export tariff 1', - 'platform': 'homewizard', - 'previous_unique_id': None, - 'supported_features': 0, - 'translation_key': 'total_energy_export_t1_kwh', - 'unique_id': 'aabbccddeeff_total_power_export_t1_kwh', - 'unit_of_measurement': , - }) -# --- -# name: test_sensors[SDM630-entity_ids5][sensor.device_total_energy_export_tariff_1:state] - StateSnapshot({ - 'attributes': ReadOnlyDict({ - 'device_class': 'energy', - 'friendly_name': 'Device Total energy export tariff 1', - 'state_class': , - 'unit_of_measurement': , - }), - 'context': , - 'entity_id': 'sensor.device_total_energy_export_tariff_1', - 'last_changed': , - 'last_updated': , - 'state': '0.523', - }) -# --- # name: test_sensors[SDM630-entity_ids5][sensor.device_total_energy_import:device-registry] DeviceRegistryEntrySnapshot({ 'area_id': None, @@ -8112,86 +7712,6 @@ 'state': '0.101', }) # --- -# name: test_sensors[SDM630-entity_ids5][sensor.device_total_energy_import_tariff_1:device-registry] - DeviceRegistryEntrySnapshot({ - 'area_id': None, - 'config_entries': , - 'configuration_url': None, - 'connections': set({ - tuple( - 'mac', - '3c:39:e7:aa:bb:cc', - ), - }), - 'disabled_by': None, - 'entry_type': None, - 'hw_version': None, - 'id': , - 'identifiers': set({ - tuple( - 'homewizard', - '3c39e7aabbcc', - ), - }), - 'is_new': False, - 'manufacturer': 'HomeWizard', - 'model': 'SDM630-wifi', - 'name': 'Device', - 'name_by_user': None, - 'serial_number': None, - 'suggested_area': None, - 'sw_version': '3.06', - 'via_device_id': None, - }) -# --- -# name: test_sensors[SDM630-entity_ids5][sensor.device_total_energy_import_tariff_1:entity-registry] - EntityRegistryEntrySnapshot({ - 'aliases': set({ - }), - 'area_id': None, - 'capabilities': dict({ - 'state_class': , - }), - 'config_entry_id': , - 'device_class': None, - 'device_id': , - 'disabled_by': None, - 'domain': 'sensor', - 'entity_category': None, - 'entity_id': 'sensor.device_total_energy_import_tariff_1', - 'has_entity_name': True, - 'hidden_by': None, - 'icon': None, - 'id': , - 'name': None, - 'options': dict({ - }), - 'original_device_class': , - 'original_icon': None, - 'original_name': 'Total energy import tariff 1', - 'platform': 'homewizard', - 'previous_unique_id': None, - 'supported_features': 0, - 'translation_key': 'total_energy_import_t1_kwh', - 'unique_id': 'aabbccddeeff_total_power_import_t1_kwh', - 'unit_of_measurement': , - }) -# --- -# name: test_sensors[SDM630-entity_ids5][sensor.device_total_energy_import_tariff_1:state] - StateSnapshot({ - 'attributes': ReadOnlyDict({ - 'device_class': 'energy', - 'friendly_name': 'Device Total energy import tariff 1', - 'state_class': , - 'unit_of_measurement': , - }), - 'context': , - 'entity_id': 'sensor.device_total_energy_import_tariff_1', - 'last_changed': , - 'last_updated': , - 'state': '0.101', - }) -# --- # name: test_sensors[SDM630-entity_ids5][sensor.device_wi_fi_ssid:device-registry] DeviceRegistryEntrySnapshot({ 'area_id': None, diff --git a/tests/components/homewizard/test_sensor.py b/tests/components/homewizard/test_sensor.py index 006f12089eedc..7e59769a76819 100644 --- a/tests/components/homewizard/test_sensor.py +++ b/tests/components/homewizard/test_sensor.py @@ -114,9 +114,7 @@ "sensor.device_wi_fi_ssid", "sensor.device_wi_fi_strength", "sensor.device_total_energy_import", - "sensor.device_total_energy_import_tariff_1", "sensor.device_total_energy_export", - "sensor.device_total_energy_export_tariff_1", "sensor.device_active_power", "sensor.device_active_power_phase_1", ], @@ -136,9 +134,7 @@ "sensor.device_wi_fi_ssid", "sensor.device_wi_fi_strength", "sensor.device_total_energy_import", - "sensor.device_total_energy_import_tariff_1", "sensor.device_total_energy_export", - "sensor.device_total_energy_export_tariff_1", "sensor.device_active_power", "sensor.device_active_power_phase_1", ], @@ -149,9 +145,7 @@ "sensor.device_wi_fi_ssid", "sensor.device_wi_fi_strength", "sensor.device_total_energy_import", - "sensor.device_total_energy_import_tariff_1", "sensor.device_total_energy_export", - "sensor.device_total_energy_export_tariff_1", "sensor.device_active_power", "sensor.device_active_power_phase_1", "sensor.device_active_power_phase_2", @@ -287,9 +281,11 @@ async def test_sensors_unreachable( "sensor.device_power_failures_detected", "sensor.device_smart_meter_identifier", "sensor.device_smart_meter_model", + "sensor.device_total_energy_export_tariff_1", "sensor.device_total_energy_export_tariff_2", "sensor.device_total_energy_export_tariff_3", "sensor.device_total_energy_export_tariff_4", + "sensor.device_total_energy_import_tariff_1", "sensor.device_total_energy_import_tariff_2", "sensor.device_total_energy_import_tariff_3", "sensor.device_total_energy_import_tariff_4", @@ -367,9 +363,11 @@ async def test_sensors_unreachable( "sensor.device_power_failures_detected", "sensor.device_smart_meter_identifier", "sensor.device_smart_meter_model", + "sensor.device_total_energy_export_tariff_1", "sensor.device_total_energy_export_tariff_2", "sensor.device_total_energy_export_tariff_3", "sensor.device_total_energy_export_tariff_4", + "sensor.device_total_energy_import_tariff_1", "sensor.device_total_energy_import_tariff_2", "sensor.device_total_energy_import_tariff_3", "sensor.device_total_energy_import_tariff_4", @@ -403,9 +401,11 @@ async def test_sensors_unreachable( "sensor.device_power_failures_detected", "sensor.device_smart_meter_identifier", "sensor.device_smart_meter_model", + "sensor.device_total_energy_export_tariff_1", "sensor.device_total_energy_export_tariff_2", "sensor.device_total_energy_export_tariff_3", "sensor.device_total_energy_export_tariff_4", + "sensor.device_total_energy_import_tariff_1", "sensor.device_total_energy_import_tariff_2", "sensor.device_total_energy_import_tariff_3", "sensor.device_total_energy_import_tariff_4",