From d672eed3319a3a2e8073d5bc2702da47f1ee4d15 Mon Sep 17 00:00:00 2001 From: tubalainen Date: Fri, 17 Apr 2020 17:15:04 +0200 Subject: [PATCH] Add rflink binary_sensor allon and alloff commands (#32411) * added "allon" and "alloff" to the binary_sensor Ref to the issue: https://github.com/home-assistant/core/issues/32399 * Cosmetic fix * Fix format * Update test Co-authored-by: Erik Montnemery --- homeassistant/components/rflink/binary_sensor.py | 4 ++-- tests/components/rflink/test_binary_sensor.py | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/rflink/binary_sensor.py b/homeassistant/components/rflink/binary_sensor.py index ab50e6dcc4b..c3600da4051 100644 --- a/homeassistant/components/rflink/binary_sensor.py +++ b/homeassistant/components/rflink/binary_sensor.py @@ -73,9 +73,9 @@ class RflinkBinarySensor(RflinkDevice, BinarySensorDevice): def _handle_event(self, event): """Domain specific event handler.""" command = event["command"] - if command == "on": + if command in ["on", "allon"]: self._state = True - elif command == "off": + elif command in ["off", "alloff"]: self._state = False if self._state and self._off_delay is not None: diff --git a/tests/components/rflink/test_binary_sensor.py b/tests/components/rflink/test_binary_sensor.py index 2a67cf5348d..788e6d4981f 100644 --- a/tests/components/rflink/test_binary_sensor.py +++ b/tests/components/rflink/test_binary_sensor.py @@ -56,18 +56,30 @@ async def test_default_setup(hass, monkeypatch): assert config_sensor.state == STATE_OFF assert config_sensor.attributes["device_class"] == "door" - # test event for config sensor + # test on event for config sensor event_callback({"id": "test", "command": "on"}) await hass.async_block_till_done() assert hass.states.get("binary_sensor.test").state == STATE_ON - # test event for config sensor + # test off event for config sensor event_callback({"id": "test", "command": "off"}) await hass.async_block_till_done() assert hass.states.get("binary_sensor.test").state == STATE_OFF + # test allon event for config sensor + event_callback({"id": "test", "command": "allon"}) + await hass.async_block_till_done() + + assert hass.states.get("binary_sensor.test").state == STATE_ON + + # test alloff event for config sensor + event_callback({"id": "test", "command": "alloff"}) + await hass.async_block_till_done() + + assert hass.states.get("binary_sensor.test").state == STATE_OFF + async def test_entity_availability(hass, monkeypatch): """If Rflink device is disconnected, entities should become unavailable."""