diff --git a/homeassistant/components/rfxtrx/__init__.py b/homeassistant/components/rfxtrx/__init__.py index 5f350376ec0..04d2078e182 100644 --- a/homeassistant/components/rfxtrx/__init__.py +++ b/homeassistant/components/rfxtrx/__init__.py @@ -487,38 +487,7 @@ class RfxtrxCommandEntity(RfxtrxEntity): self.signal_repetitions = signal_repetitions self._state = None - def _send_command(self, command, brightness=0): + async def _async_send(self, fun, *args): rfx_object = self.hass.data[DOMAIN][DATA_RFXOBJECT] - - if command == "turn_on": - for _ in range(self.signal_repetitions): - self._device.send_on(rfx_object.transport) - self._state = True - - elif command == "dim": - for _ in range(self.signal_repetitions): - self._device.send_dim(rfx_object.transport, brightness) - self._state = True - - elif command == "turn_off": - for _ in range(self.signal_repetitions): - self._device.send_off(rfx_object.transport) - self._state = False - - elif command == "roll_up": - for _ in range(self.signal_repetitions): - self._device.send_open(rfx_object.transport) - self._state = True - - elif command == "roll_down": - for _ in range(self.signal_repetitions): - self._device.send_close(rfx_object.transport) - self._state = False - - elif command == "stop_roll": - for _ in range(self.signal_repetitions): - self._device.send_stop(rfx_object.transport) - self._state = True - - if self.hass: - self.schedule_update_ha_state() + for _ in range(self.signal_repetitions): + await self.hass.async_add_executor_job(fun, rfx_object.transport, *args) diff --git a/homeassistant/components/rfxtrx/cover.py b/homeassistant/components/rfxtrx/cover.py index 58bc27d95bb..8b5886191a5 100644 --- a/homeassistant/components/rfxtrx/cover.py +++ b/homeassistant/components/rfxtrx/cover.py @@ -98,17 +98,23 @@ class RfxtrxCover(RfxtrxCommandEntity, CoverEntity): """Return if the cover is closed.""" return not self._state - def open_cover(self, **kwargs): + async def async_open_cover(self, **kwargs): """Move the cover up.""" - self._send_command("roll_up") + await self._async_send(self._device.send_open) + self._state = True + self.async_write_ha_state() - def close_cover(self, **kwargs): + async def async_close_cover(self, **kwargs): """Move the cover down.""" - self._send_command("roll_down") + await self._async_send(self._device.send_close) + self._state = False + self.async_write_ha_state() - def stop_cover(self, **kwargs): + async def async_stop_cover(self, **kwargs): """Stop the cover.""" - self._send_command("stop_roll") + await self._async_send(self._device.send_stop) + self._state = True + self.async_write_ha_state() def _apply_event(self, event): """Apply command from rfxtrx.""" diff --git a/homeassistant/components/rfxtrx/light.py b/homeassistant/components/rfxtrx/light.py index ab24520e485..44472b6c33c 100644 --- a/homeassistant/components/rfxtrx/light.py +++ b/homeassistant/components/rfxtrx/light.py @@ -125,21 +125,25 @@ class RfxtrxLight(RfxtrxCommandEntity, LightEntity): """Return true if device is on.""" return self._state - def turn_on(self, **kwargs): - """Turn the light on.""" + async def async_turn_on(self, **kwargs): + """Turn the device on.""" brightness = kwargs.get(ATTR_BRIGHTNESS) + self._state = True if brightness is None: + await self._async_send(self._device.send_on) self._brightness = 255 - self._send_command("turn_on") else: + await self._async_send(self._device.send_dim, brightness * 100 // 255) self._brightness = brightness - _brightness = brightness * 100 // 255 - self._send_command("dim", _brightness) - def turn_off(self, **kwargs): + self.async_write_ha_state() + + async def async_turn_off(self, **kwargs): """Turn the device off.""" + await self._async_send(self._device.send_off) + self._state = False self._brightness = 0 - self._send_command("turn_off") + self.async_write_ha_state() def _apply_event(self, event): """Apply command from rfxtrx.""" diff --git a/homeassistant/components/rfxtrx/switch.py b/homeassistant/components/rfxtrx/switch.py index 6f3cfa5f773..9b2c3c60539 100644 --- a/homeassistant/components/rfxtrx/switch.py +++ b/homeassistant/components/rfxtrx/switch.py @@ -127,12 +127,14 @@ class RfxtrxSwitch(RfxtrxCommandEntity, SwitchEntity): """Return true if device is on.""" return self._state - def turn_on(self, **kwargs): + async def async_turn_on(self, **kwargs): """Turn the device on.""" - self._send_command("turn_on") - self.schedule_update_ha_state() + await self._async_send(self._device.send_on) + self._state = True + self.async_write_ha_state() - def turn_off(self, **kwargs): + async def async_turn_off(self, **kwargs): """Turn the device off.""" - self._send_command("turn_off") - self.schedule_update_ha_state() + await self._async_send(self._device.send_off) + self._state = False + self.async_write_ha_state()