diff --git a/homeassistant/components/weheat/const.py b/homeassistant/components/weheat/const.py index cd521afd2ea..20df56bafd6 100644 --- a/homeassistant/components/weheat/const.py +++ b/homeassistant/components/weheat/const.py @@ -13,7 +13,7 @@ OAUTH2_AUTHORIZE = ( OAUTH2_TOKEN = ( "https://auth.weheat.nl/auth/realms/Weheat/protocol/openid-connect/token/" ) -API_URL = "https://api.weheat.nl" +API_URL = "https://api.weheat.nl/third_party" OAUTH2_SCOPES = ["openid", "offline_access"] diff --git a/homeassistant/components/weheat/icons.json b/homeassistant/components/weheat/icons.json index e8eb5bb8dd9..9606cbdf6fb 100644 --- a/homeassistant/components/weheat/icons.json +++ b/homeassistant/components/weheat/icons.json @@ -39,6 +39,33 @@ "electricity_used": { "default": "mdi:flash" }, + "electricity_used_cooling": { + "default": "mdi:flash" + }, + "electricity_used_defrost": { + "default": "mdi:flash" + }, + "electricity_used_dhw": { + "default": "mdi:flash" + }, + "electricity_used_heating": { + "default": "mdi:flash" + }, + "energy_output": { + "default": "mdi:flash" + }, + "energy_output_cooling": { + "default": "mdi:snowflake" + }, + "energy_output_defrost": { + "default": "mdi:snowflake" + }, + "energy_output_dhw": { + "default": "mdi:heat-wave" + }, + "energy_output_heating": { + "default": "mdi:heat-wave" + }, "heat_pump_state": { "default": "mdi:state-machine" }, diff --git a/homeassistant/components/weheat/sensor.py b/homeassistant/components/weheat/sensor.py index 0e6170fc33d..960749a1aa1 100644 --- a/homeassistant/components/weheat/sensor.py +++ b/homeassistant/components/weheat/sensor.py @@ -221,6 +221,73 @@ ENERGY_SENSORS = [ state_class=SensorStateClass.TOTAL_INCREASING, value_fn=lambda status: status.energy_output, ), + WeHeatSensorEntityDescription( + translation_key="electricity_used_heating", + key="electricity_used_heating", + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, + device_class=SensorDeviceClass.ENERGY, + state_class=SensorStateClass.TOTAL_INCREASING, + value_fn=lambda status: status.energy_in_heating, + ), + WeHeatSensorEntityDescription( + translation_key="electricity_used_cooling", + key="electricity_used_cooling", + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, + device_class=SensorDeviceClass.ENERGY, + state_class=SensorStateClass.TOTAL_INCREASING, + value_fn=lambda status: status.energy_in_cooling, + ), + WeHeatSensorEntityDescription( + translation_key="electricity_used_defrost", + key="electricity_used_defrost", + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, + device_class=SensorDeviceClass.ENERGY, + state_class=SensorStateClass.TOTAL_INCREASING, + value_fn=lambda status: status.energy_in_defrost, + ), + WeHeatSensorEntityDescription( + translation_key="energy_output_heating", + key="energy_output_heating", + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, + device_class=SensorDeviceClass.ENERGY, + state_class=SensorStateClass.TOTAL_INCREASING, + value_fn=lambda status: status.energy_out_heating, + ), + WeHeatSensorEntityDescription( + translation_key="energy_output_cooling", + key="energy_output_cooling", + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, + device_class=SensorDeviceClass.ENERGY, + state_class=SensorStateClass.TOTAL, + value_fn=lambda status: status.energy_out_cooling, + ), + WeHeatSensorEntityDescription( + translation_key="energy_output_defrost", + key="energy_output_defrost", + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, + device_class=SensorDeviceClass.ENERGY, + state_class=SensorStateClass.TOTAL, + value_fn=lambda status: status.energy_out_defrost, + ), +] + +DHW_ENERGY_SENSORS = [ + WeHeatSensorEntityDescription( + translation_key="electricity_used_dhw", + key="electricity_used_dhw", + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, + device_class=SensorDeviceClass.ENERGY, + state_class=SensorStateClass.TOTAL_INCREASING, + value_fn=lambda status: status.energy_in_dhw, + ), + WeHeatSensorEntityDescription( + translation_key="energy_output_dhw", + key="energy_output_dhw", + native_unit_of_measurement=UnitOfEnergy.KILO_WATT_HOUR, + device_class=SensorDeviceClass.ENERGY, + state_class=SensorStateClass.TOTAL_INCREASING, + value_fn=lambda status: status.energy_out_dhw, + ), ] @@ -253,6 +320,16 @@ async def async_setup_entry( if entity_description.value_fn(weheatdata.data_coordinator.data) is not None ) + entities.extend( + WeheatHeatPumpSensor( + weheatdata.heat_pump_info, + weheatdata.energy_coordinator, + entity_description, + ) + for entity_description in DHW_ENERGY_SENSORS + if entity_description.value_fn(weheatdata.energy_coordinator.data) + is not None + ) entities.extend( WeheatHeatPumpSensor( weheatdata.heat_pump_info, diff --git a/homeassistant/components/weheat/strings.json b/homeassistant/components/weheat/strings.json index eb60bcbc737..f98d1ab086d 100644 --- a/homeassistant/components/weheat/strings.json +++ b/homeassistant/components/weheat/strings.json @@ -84,9 +84,33 @@ "electricity_used": { "name": "Electricity used" }, + "electricity_used_cooling": { + "name": "Electricity used cooling" + }, + "electricity_used_defrost": { + "name": "Electricity used defrost" + }, + "electricity_used_dhw": { + "name": "Electricity used DHW" + }, + "electricity_used_heating": { + "name": "Electricity used heating" + }, "energy_output": { "name": "Total energy output" }, + "energy_output_cooling": { + "name": "Energy output cooling" + }, + "energy_output_defrost": { + "name": "Energy output defrost" + }, + "energy_output_dhw": { + "name": "Energy output DHW" + }, + "energy_output_heating": { + "name": "Energy output heating" + }, "heat_pump_state": { "state": { "cooling": "Cooling", diff --git a/tests/components/weheat/conftest.py b/tests/components/weheat/conftest.py index 8d2f70ea472..6e371f1afe2 100644 --- a/tests/components/weheat/conftest.py +++ b/tests/components/weheat/conftest.py @@ -120,8 +120,16 @@ def mock_weheat_heat_pump_instance() -> MagicMock: mock_heat_pump_instance.thermostat_room_temperature_setpoint = 21 mock_heat_pump_instance.cop = 4.5 mock_heat_pump_instance.heat_pump_state = HeatPump.State.HEATING - mock_heat_pump_instance.energy_total = 12345 - mock_heat_pump_instance.energy_output = 56789 + mock_heat_pump_instance.energy_in_heating = 12345 + mock_heat_pump_instance.energy_in_dhw = 6789 + mock_heat_pump_instance.energy_in_defrost = 555 + mock_heat_pump_instance.energy_in_cooling = 9000 + mock_heat_pump_instance.energy_total = 28689 + mock_heat_pump_instance.energy_out_heating = 10000 + mock_heat_pump_instance.energy_out_dhw = 6677 + mock_heat_pump_instance.energy_out_defrost = -1200 + mock_heat_pump_instance.energy_out_cooling = -876 + mock_heat_pump_instance.energy_output = 14601 mock_heat_pump_instance.compressor_rpm = 4500 mock_heat_pump_instance.compressor_percentage = 100 mock_heat_pump_instance.dhw_flow_volume = 1.12 diff --git a/tests/components/weheat/snapshots/test_sensor.ambr b/tests/components/weheat/snapshots/test_sensor.ambr index d64640a4317..06058390ede 100644 --- a/tests/components/weheat/snapshots/test_sensor.ambr +++ b/tests/components/weheat/snapshots/test_sensor.ambr @@ -631,9 +631,465 @@ 'last_changed': , 'last_reported': , 'last_updated': , + 'state': '28689', + }) +# --- +# name: test_all_entities[sensor.test_model_electricity_used_cooling-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.test_model_electricity_used_cooling', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Electricity used cooling', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Electricity used cooling', + 'platform': 'weheat', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'electricity_used_cooling', + 'unique_id': '0000-1111-2222-3333_electricity_used_cooling', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.test_model_electricity_used_cooling-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'energy', + 'friendly_name': 'Test Model Electricity used cooling', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.test_model_electricity_used_cooling', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '9000', + }) +# --- +# name: test_all_entities[sensor.test_model_electricity_used_defrost-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.test_model_electricity_used_defrost', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Electricity used defrost', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Electricity used defrost', + 'platform': 'weheat', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'electricity_used_defrost', + 'unique_id': '0000-1111-2222-3333_electricity_used_defrost', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.test_model_electricity_used_defrost-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'energy', + 'friendly_name': 'Test Model Electricity used defrost', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.test_model_electricity_used_defrost', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '555', + }) +# --- +# name: test_all_entities[sensor.test_model_electricity_used_dhw-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.test_model_electricity_used_dhw', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Electricity used DHW', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Electricity used DHW', + 'platform': 'weheat', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'electricity_used_dhw', + 'unique_id': '0000-1111-2222-3333_electricity_used_dhw', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.test_model_electricity_used_dhw-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'energy', + 'friendly_name': 'Test Model Electricity used DHW', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.test_model_electricity_used_dhw', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '6789', + }) +# --- +# name: test_all_entities[sensor.test_model_electricity_used_heating-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.test_model_electricity_used_heating', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Electricity used heating', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Electricity used heating', + 'platform': 'weheat', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'electricity_used_heating', + 'unique_id': '0000-1111-2222-3333_electricity_used_heating', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.test_model_electricity_used_heating-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'energy', + 'friendly_name': 'Test Model Electricity used heating', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.test_model_electricity_used_heating', + 'last_changed': , + 'last_reported': , + 'last_updated': , 'state': '12345', }) # --- +# name: test_all_entities[sensor.test_model_energy_output_cooling-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.test_model_energy_output_cooling', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Energy output cooling', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Energy output cooling', + 'platform': 'weheat', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'energy_output_cooling', + 'unique_id': '0000-1111-2222-3333_energy_output_cooling', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.test_model_energy_output_cooling-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'energy', + 'friendly_name': 'Test Model Energy output cooling', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.test_model_energy_output_cooling', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '-876', + }) +# --- +# name: test_all_entities[sensor.test_model_energy_output_defrost-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.test_model_energy_output_defrost', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Energy output defrost', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Energy output defrost', + 'platform': 'weheat', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'energy_output_defrost', + 'unique_id': '0000-1111-2222-3333_energy_output_defrost', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.test_model_energy_output_defrost-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'energy', + 'friendly_name': 'Test Model Energy output defrost', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.test_model_energy_output_defrost', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '-1200', + }) +# --- +# name: test_all_entities[sensor.test_model_energy_output_dhw-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.test_model_energy_output_dhw', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Energy output DHW', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Energy output DHW', + 'platform': 'weheat', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'energy_output_dhw', + 'unique_id': '0000-1111-2222-3333_energy_output_dhw', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.test_model_energy_output_dhw-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'energy', + 'friendly_name': 'Test Model Energy output DHW', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.test_model_energy_output_dhw', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '6677', + }) +# --- +# name: test_all_entities[sensor.test_model_energy_output_heating-entry] + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'config_subentry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.test_model_energy_output_heating', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Energy output heating', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Energy output heating', + 'platform': 'weheat', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'energy_output_heating', + 'unique_id': '0000-1111-2222-3333_energy_output_heating', + 'unit_of_measurement': , + }) +# --- +# name: test_all_entities[sensor.test_model_energy_output_heating-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'energy', + 'friendly_name': 'Test Model Energy output heating', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.test_model_energy_output_heating', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '10000', + }) +# --- # name: test_all_entities[sensor.test_model_input_power-entry] EntityRegistryEntrySnapshot({ 'aliases': set({ @@ -916,7 +1372,7 @@ 'last_changed': , 'last_reported': , 'last_updated': , - 'state': '56789', + 'state': '14601', }) # --- # name: test_all_entities[sensor.test_model_water_inlet_temperature-entry] diff --git a/tests/components/weheat/test_sensor.py b/tests/components/weheat/test_sensor.py index b4d436cdaf1..45499784c48 100644 --- a/tests/components/weheat/test_sensor.py +++ b/tests/components/weheat/test_sensor.py @@ -33,7 +33,7 @@ async def test_all_entities( await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id) -@pytest.mark.parametrize(("has_dhw", "nr_of_entities"), [(False, 16), (True, 19)]) +@pytest.mark.parametrize(("has_dhw", "nr_of_entities"), [(False, 22), (True, 27)]) async def test_create_entities( hass: HomeAssistant, mock_weheat_discover: AsyncMock,