From 5617e6913b4eee185edd5e7ce3108781e91b6ad5 Mon Sep 17 00:00:00 2001 From: Ernst Klamer Date: Thu, 16 Apr 2020 15:07:55 +0200 Subject: [PATCH] Add state to RFXtrx covers (#30935) * Add state to rfxtrx cover * Add state to rfxtrx cover (cover.py) --- homeassistant/components/rfxtrx/__init__.py | 32 +++++++++++++++++---- homeassistant/components/rfxtrx/cover.py | 2 +- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/rfxtrx/__init__.py b/homeassistant/components/rfxtrx/__init__.py index b37ad8c15a8..387c42a35b5 100644 --- a/homeassistant/components/rfxtrx/__init__.py +++ b/homeassistant/components/rfxtrx/__init__.py @@ -131,7 +131,7 @@ def setup(hass, config): if dummy_connection: rfx_object = rfxtrxmod.Connect( - device, None, debug=debug, transport_protocol=rfxtrxmod.DummyTransport2 + device, None, debug=debug, transport_protocol=rfxtrxmod.DummyTransport2, ) elif port is not None: # If port is set then we create a TCP connection @@ -215,7 +215,7 @@ def get_pt2262_device(device_id): and device.masked_id == get_pt2262_deviceid(device_id, device.data_bits) ): _LOGGER.debug( - "rfxtrx: found matching device %s for %s", device_id, device.masked_id + "rfxtrx: found matching device %s for %s", device_id, device.masked_id, ) return device return None @@ -307,13 +307,32 @@ def apply_received_command(event): return _LOGGER.debug( - "Device_id: %s device_update. Command: %s", device_id, event.values["Command"] + "Device_id: %s device_update. Command: %s", device_id, event.values["Command"], ) - if event.values["Command"] == "On" or event.values["Command"] == "Off": + if event.values["Command"] in [ + "On", + "Off", + "Up", + "Down", + "Stop", + "Open (inline relay)", + "Close (inline relay)", + "Stop (inline relay)", + ]: # Update the rfxtrx device state - is_on = event.values["Command"] == "On" + command = event.values["Command"] + if command in [ + "On", + "Up", + "Stop", + "Open (inline relay)", + "Stop (inline relay)", + ]: + is_on = True + elif command in ["Off", "Down", "Close (inline relay)"]: + is_on = False RFX_DEVICES[device_id].update_state(is_on) elif ( @@ -425,14 +444,17 @@ class RfxtrxDevice(Entity): elif command == "roll_up": for _ in range(self.signal_repetitions): self._event.device.send_open(rfx_object.transport) + self._state = True elif command == "roll_down": for _ in range(self.signal_repetitions): self._event.device.send_close(rfx_object.transport) + self._state = False elif command == "stop_roll": for _ in range(self.signal_repetitions): self._event.device.send_stop(rfx_object.transport) + self._state = True if self.added_to_hass: self.schedule_update_ha_state() diff --git a/homeassistant/components/rfxtrx/cover.py b/homeassistant/components/rfxtrx/cover.py index e1eb6ae77f5..da19c42ed69 100644 --- a/homeassistant/components/rfxtrx/cover.py +++ b/homeassistant/components/rfxtrx/cover.py @@ -82,7 +82,7 @@ class RfxtrxCover(RfxtrxDevice, CoverDevice, RestoreEntity): @property def is_closed(self): """Return if the cover is closed.""" - return None + return not self._state def open_cover(self, **kwargs): """Move the cover up."""