From fd11748a1a6c7535f710b415b527032d5b4e1d57 Mon Sep 17 00:00:00 2001 From: Joakim Plate Date: Sat, 25 Jul 2020 22:56:58 +0200 Subject: [PATCH] Make rfxtrx RfyDevices have sun automation switches (#38210) * RfyDevices have sun automation * We must accept sun automation commands for switch * Add test for Rfy sun automation --- homeassistant/components/rfxtrx/const.py | 2 ++ homeassistant/components/rfxtrx/switch.py | 1 + tests/components/rfxtrx/test_switch.py | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/homeassistant/components/rfxtrx/const.py b/homeassistant/components/rfxtrx/const.py index cd3c4b9a62e..c0436bfcf60 100644 --- a/homeassistant/components/rfxtrx/const.py +++ b/homeassistant/components/rfxtrx/const.py @@ -7,12 +7,14 @@ COMMAND_ON_LIST = [ "Stop", "Open (inline relay)", "Stop (inline relay)", + "Enable sun automation", ] COMMAND_OFF_LIST = [ "Off", "Down", "Close (inline relay)", + "Disable sun automation", ] ATTR_EVENT = "event" diff --git a/homeassistant/components/rfxtrx/switch.py b/homeassistant/components/rfxtrx/switch.py index 5f99c0761f0..6f3cfa5f773 100644 --- a/homeassistant/components/rfxtrx/switch.py +++ b/homeassistant/components/rfxtrx/switch.py @@ -37,6 +37,7 @@ async def async_setup_entry( isinstance(event.device, rfxtrxmod.LightingDevice) and not event.device.known_to_be_dimmable and not event.device.known_to_be_rollershutter + or isinstance(event.device, rfxtrxmod.RfyDevice) ) # Add switch from config file diff --git a/tests/components/rfxtrx/test_switch.py b/tests/components/rfxtrx/test_switch.py index c163401142e..3256f303708 100644 --- a/tests/components/rfxtrx/test_switch.py +++ b/tests/components/rfxtrx/test_switch.py @@ -8,6 +8,9 @@ from homeassistant.setup import async_setup_component from tests.common import mock_restore_cache +EVENT_RFY_ENABLE_SUN_AUTO = "081a00000301010113" +EVENT_RFY_DISABLE_SUN_AUTO = "081a00000301010114" + async def test_one_switch(hass, rfxtrx): """Test with 1 switch.""" @@ -133,3 +136,18 @@ async def test_discover_switch(hass, rfxtrx_automatic): state = hass.states.get("switch.ac_118cdeb_2") assert state assert state.state == "on" + + +async def test_discover_rfy_sun_switch(hass, rfxtrx_automatic): + """Test with discovery of switches.""" + rfxtrx = rfxtrx_automatic + + await rfxtrx.signal(EVENT_RFY_DISABLE_SUN_AUTO) + state = hass.states.get("switch.rfy_030101_1") + assert state + assert state.state == "off" + + await rfxtrx.signal(EVENT_RFY_ENABLE_SUN_AUTO) + state = hass.states.get("switch.rfy_030101_1") + assert state + assert state.state == "on"