mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Clean up commands generation for rfxtrx (#38236)
This commit is contained in:
parent
c3966a5ef2
commit
c93fc8af4a
@ -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)
|
||||
|
@ -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."""
|
||||
|
@ -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."""
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user