diff --git a/homeassistant/components/hr_energy_qube/sensor.py b/homeassistant/components/hr_energy_qube/sensor.py index b7fb23587652..4ad46f1f8a04 100644 --- a/homeassistant/components/hr_energy_qube/sensor.py +++ b/homeassistant/components/hr_energy_qube/sensor.py @@ -14,9 +14,11 @@ from homeassistant.components.sensor import ( ) from homeassistant.const import ( REVOLUTIONS_PER_MINUTE, + EntityCategory, UnitOfEnergy, UnitOfPower, UnitOfTemperature, + UnitOfTime, UnitOfVolumeFlowRate, ) from homeassistant.helpers.typing import StateType @@ -228,6 +230,51 @@ SENSOR_TYPES: tuple[QubeSensorEntityDescription, ...] = ( suggested_display_precision=1, value_fn=lambda data: data.state.setpoint_room_cool_night, ), + QubeSensorEntityDescription( + key="working_hours_dhw", + translation_key="working_hours_dhw", + device_class=SensorDeviceClass.DURATION, + native_unit_of_measurement=UnitOfTime.HOURS, + state_class=SensorStateClass.TOTAL_INCREASING, + entity_category=EntityCategory.DIAGNOSTIC, + value_fn=lambda data: data.state.workinghours_dhw_hrsret, + ), + QubeSensorEntityDescription( + key="working_hours_heating", + translation_key="working_hours_heating", + device_class=SensorDeviceClass.DURATION, + native_unit_of_measurement=UnitOfTime.HOURS, + state_class=SensorStateClass.TOTAL_INCREASING, + entity_category=EntityCategory.DIAGNOSTIC, + value_fn=lambda data: data.state.workinghours_heat_hrsret, + ), + QubeSensorEntityDescription( + key="working_hours_cooling", + translation_key="working_hours_cooling", + device_class=SensorDeviceClass.DURATION, + native_unit_of_measurement=UnitOfTime.HOURS, + state_class=SensorStateClass.TOTAL_INCREASING, + entity_category=EntityCategory.DIAGNOSTIC, + value_fn=lambda data: data.state.workinghours_cool_hrsret, + ), + *( + QubeSensorEntityDescription( + key=f"working_hours_heater_{number}", + translation_key="working_hours_heater", + translation_placeholders={"number": str(number)}, + device_class=SensorDeviceClass.DURATION, + native_unit_of_measurement=UnitOfTime.HOURS, + state_class=SensorStateClass.TOTAL_INCREASING, + entity_category=EntityCategory.DIAGNOSTIC, + entity_registry_enabled_default=False, + value_fn=value_fn, + ) + for number, value_fn in ( + (1, lambda data: data.state.workinghours_heater1_hrs), + (2, lambda data: data.state.workinghours_heater2_hrs), + (3, lambda data: data.state.workinghours_heater3_hrs), + ) + ), QubeSensorEntityDescription( key="status_heatpump", translation_key="status_heatpump", diff --git a/homeassistant/components/hr_energy_qube/strings.json b/homeassistant/components/hr_energy_qube/strings.json index 3a08f22a4420..b3eadb5e1afc 100644 --- a/homeassistant/components/hr_energy_qube/strings.json +++ b/homeassistant/components/hr_energy_qube/strings.json @@ -225,6 +225,18 @@ }, "temp_supply": { "name": "Supply temperature CH" + }, + "working_hours_cooling": { + "name": "Working hours cooling" + }, + "working_hours_dhw": { + "name": "Working hours DHW" + }, + "working_hours_heater": { + "name": "Working hours heater {number}" + }, + "working_hours_heating": { + "name": "Working hours heating" } }, "switch": { diff --git a/tests/components/hr_energy_qube/conftest.py b/tests/components/hr_energy_qube/conftest.py index 65f56e11a579..ce04b43c33fa 100644 --- a/tests/components/hr_energy_qube/conftest.py +++ b/tests/components/hr_energy_qube/conftest.py @@ -85,6 +85,12 @@ def mock_qube_client(mock_qube_client_cls: MagicMock) -> MagicMock: state.status_code = 1 state.status = StatusCode.STANDBY state.setpoint_dhw = 50.0 + state.workinghours_dhw_hrsret = 1250 + state.workinghours_heat_hrsret = 8400 + state.workinghours_cool_hrsret = 310 + state.workinghours_heater1_hrs = 12 + state.workinghours_heater2_hrs = 0 + state.workinghours_heater3_hrs = 0 # Binary sensors - Outputs state.dout_srcpmp_val = True diff --git a/tests/components/hr_energy_qube/snapshots/test_diagnostics.ambr b/tests/components/hr_energy_qube/snapshots/test_diagnostics.ambr index febb33668c80..5dada4cb22e3 100644 --- a/tests/components/hr_energy_qube/snapshots/test_diagnostics.ambr +++ b/tests/components/hr_energy_qube/snapshots/test_diagnostics.ambr @@ -67,12 +67,12 @@ 'usr_pid_coolsetp': None, 'usr_pid_heatsetp': None, 'usralrms': False, - 'workinghours_cool_hrsret': None, - 'workinghours_dhw_hrsret': None, - 'workinghours_heat_hrsret': None, - 'workinghours_heater1_hrs': None, - 'workinghours_heater2_hrs': None, - 'workinghours_heater3_hrs': None, + 'workinghours_cool_hrsret': 310, + 'workinghours_dhw_hrsret': 1250, + 'workinghours_heat_hrsret': 8400, + 'workinghours_heater1_hrs': 12, + 'workinghours_heater2_hrs': 0, + 'workinghours_heater3_hrs': 0, }), 'switches': dict({ 'antilegionella_frcstart_ant': False, diff --git a/tests/components/hr_energy_qube/snapshots/test_sensor.ambr b/tests/components/hr_energy_qube/snapshots/test_sensor.ambr index 2b6a5efeb20e..4494d0b486d7 100644 --- a/tests/components/hr_energy_qube/snapshots/test_sensor.ambr +++ b/tests/components/hr_energy_qube/snapshots/test_sensor.ambr @@ -1116,3 +1116,351 @@ 'state': '500.0', }) # --- +# name: test_entities[sensor.qube_heat_pump_working_hours_cooling-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': None, + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.qube_heat_pump_working_hours_cooling', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Working hours cooling', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Working hours cooling', + 'platform': 'hr_energy_qube', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'working_hours_cooling', + 'unique_id': '01JQUBEHEATPUMP00000000000-working_hours_cooling', + 'unit_of_measurement': , + }) +# --- +# name: test_entities[sensor.qube_heat_pump_working_hours_cooling-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'duration', + : 'Qube heat pump Working hours cooling', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.qube_heat_pump_working_hours_cooling', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '310', + }) +# --- +# name: test_entities[sensor.qube_heat_pump_working_hours_dhw-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': None, + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.qube_heat_pump_working_hours_dhw', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Working hours DHW', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Working hours DHW', + 'platform': 'hr_energy_qube', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'working_hours_dhw', + 'unique_id': '01JQUBEHEATPUMP00000000000-working_hours_dhw', + 'unit_of_measurement': , + }) +# --- +# name: test_entities[sensor.qube_heat_pump_working_hours_dhw-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'duration', + : 'Qube heat pump Working hours DHW', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.qube_heat_pump_working_hours_dhw', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '1250', + }) +# --- +# name: test_entities[sensor.qube_heat_pump_working_hours_heater_1-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': None, + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.qube_heat_pump_working_hours_heater_1', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Working hours heater 1', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Working hours heater 1', + 'platform': 'hr_energy_qube', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'working_hours_heater', + 'unique_id': '01JQUBEHEATPUMP00000000000-working_hours_heater_1', + 'unit_of_measurement': , + }) +# --- +# name: test_entities[sensor.qube_heat_pump_working_hours_heater_1-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'duration', + : 'Qube heat pump Working hours heater 1', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.qube_heat_pump_working_hours_heater_1', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '12', + }) +# --- +# name: test_entities[sensor.qube_heat_pump_working_hours_heater_2-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': None, + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.qube_heat_pump_working_hours_heater_2', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Working hours heater 2', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Working hours heater 2', + 'platform': 'hr_energy_qube', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'working_hours_heater', + 'unique_id': '01JQUBEHEATPUMP00000000000-working_hours_heater_2', + 'unit_of_measurement': , + }) +# --- +# name: test_entities[sensor.qube_heat_pump_working_hours_heater_2-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'duration', + : 'Qube heat pump Working hours heater 2', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.qube_heat_pump_working_hours_heater_2', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '0', + }) +# --- +# name: test_entities[sensor.qube_heat_pump_working_hours_heater_3-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': None, + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.qube_heat_pump_working_hours_heater_3', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Working hours heater 3', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Working hours heater 3', + 'platform': 'hr_energy_qube', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'working_hours_heater', + 'unique_id': '01JQUBEHEATPUMP00000000000-working_hours_heater_3', + 'unit_of_measurement': , + }) +# --- +# name: test_entities[sensor.qube_heat_pump_working_hours_heater_3-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'duration', + : 'Qube heat pump Working hours heater 3', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.qube_heat_pump_working_hours_heater_3', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '0', + }) +# --- +# name: test_entities[sensor.qube_heat_pump_working_hours_heating-entry] + EntityRegistryEntrySnapshot({ + 'aliases': list([ + None, + ]), + 'area_id': None, + 'capabilities': dict({ + : , + }), + 'config_entry_id': , + 'config_subentry_id': None, + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.qube_heat_pump_working_hours_heating', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'labels': set({ + }), + 'name': None, + 'object_id_base': 'Working hours heating', + 'options': dict({ + 'sensor': dict({ + 'suggested_display_precision': 2, + }), + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Working hours heating', + 'platform': 'hr_energy_qube', + 'previous_unique_id': None, + 'suggested_object_id': None, + 'supported_features': 0, + 'translation_key': 'working_hours_heating', + 'unique_id': '01JQUBEHEATPUMP00000000000-working_hours_heating', + 'unit_of_measurement': , + }) +# --- +# name: test_entities[sensor.qube_heat_pump_working_hours_heating-state] + StateSnapshot({ + 'attributes': ReadOnlyDict({ + : 'duration', + : 'Qube heat pump Working hours heating', + : , + : , + }), + 'context': , + 'entity_id': 'sensor.qube_heat_pump_working_hours_heating', + 'last_changed': , + 'last_reported': , + 'last_updated': , + 'state': '8400', + }) +# --- diff --git a/tests/components/hr_energy_qube/test_sensor.py b/tests/components/hr_energy_qube/test_sensor.py index d8186931ed15..dfa8095ab957 100644 --- a/tests/components/hr_energy_qube/test_sensor.py +++ b/tests/components/hr_energy_qube/test_sensor.py @@ -20,6 +20,7 @@ from homeassistant.helpers import entity_registry as er from . import setup_integration +@pytest.mark.usefixtures("entity_registry_enabled_by_default") async def test_entities( hass: HomeAssistant, snapshot: SnapshotAssertion, @@ -132,3 +133,21 @@ async def test_room_temperature_missing_value( state = hass.states.get("sensor.qube_heat_pump_room_temperature") assert state is not None assert state.state == STATE_UNKNOWN + + +@pytest.mark.parametrize("number", [1, 2, 3]) +async def test_heater_working_hours_disabled_by_default( + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + mock_qube_client: MagicMock, + mock_config_entry: MockConfigEntry, + number: int, +) -> None: + """Test the heater working hours sensors are disabled by default.""" + await setup_integration(hass, mock_config_entry) + + entity_id = f"sensor.qube_heat_pump_working_hours_heater_{number}" + entry = entity_registry.async_get(entity_id) + assert entry is not None + assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION + assert hass.states.get(entity_id) is None