From 11a13aa0b8908ee6421c24a23eacf1635f6ba1b3 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Fri, 11 Feb 2022 13:36:27 +0100 Subject: [PATCH] Add heating and cooling binary sensors to Plugwise (#66317) --- .../components/plugwise/binary_sensor.py | 18 +++++++++++++++++- .../components/plugwise/test_binary_sensor.py | 8 ++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/plugwise/binary_sensor.py b/homeassistant/components/plugwise/binary_sensor.py index ec1f2e5a2b4..129f4faef92 100644 --- a/homeassistant/components/plugwise/binary_sensor.py +++ b/homeassistant/components/plugwise/binary_sensor.py @@ -43,6 +43,20 @@ BINARY_SENSORS: tuple[PlugwiseBinarySensorEntityDescription, ...] = ( icon_off="mdi:fire-off", entity_category=EntityCategory.DIAGNOSTIC, ), + PlugwiseBinarySensorEntityDescription( + key="heating_state", + name="Heating", + icon="mdi:radiator", + icon_off="mdi:radiator-off", + entity_category=EntityCategory.DIAGNOSTIC, + ), + PlugwiseBinarySensorEntityDescription( + key="cooling_state", + name="Cooling", + icon="mdi:snowflake", + icon_off="mdi:snowflake-off", + entity_category=EntityCategory.DIAGNOSTIC, + ), PlugwiseBinarySensorEntityDescription( key="slave_boiler_state", name="Secondary Boiler State", @@ -73,7 +87,7 @@ async def async_setup_entry( entities: list[PlugwiseBinarySensorEntity] = [] for device_id, device in coordinator.data.devices.items(): for description in BINARY_SENSORS: - if ( + if description.key not in device and ( "binary_sensors" not in device or description.key not in device["binary_sensors"] ): @@ -109,6 +123,8 @@ class PlugwiseBinarySensorEntity(PlugwiseEntity, BinarySensorEntity): @property def is_on(self) -> bool | None: """Return true if the binary sensor is on.""" + if self.entity_description.key in self.device: + return self.device[self.entity_description.key] return self.device["binary_sensors"].get(self.entity_description.key) @property diff --git a/tests/components/plugwise/test_binary_sensor.py b/tests/components/plugwise/test_binary_sensor.py index 4bcecf83157..aacb9e469bb 100644 --- a/tests/components/plugwise/test_binary_sensor.py +++ b/tests/components/plugwise/test_binary_sensor.py @@ -21,6 +21,14 @@ async def test_anna_climate_binary_sensor_entities( assert state assert state.state == STATE_OFF + state = hass.states.get("binary_sensor.opentherm_heating") + assert state + assert state.state == STATE_ON + + state = hass.states.get("binary_sensor.opentherm_cooling") + assert state + assert state.state == STATE_OFF + async def test_anna_climate_binary_sensor_change( hass: HomeAssistant, mock_smile_anna: MagicMock, init_integration: MockConfigEntry