mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 06:17:07 +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.signal_repetitions = signal_repetitions
|
||||||
self._state = None
|
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]
|
rfx_object = self.hass.data[DOMAIN][DATA_RFXOBJECT]
|
||||||
|
|
||||||
if command == "turn_on":
|
|
||||||
for _ in range(self.signal_repetitions):
|
for _ in range(self.signal_repetitions):
|
||||||
self._device.send_on(rfx_object.transport)
|
await self.hass.async_add_executor_job(fun, rfx_object.transport, *args)
|
||||||
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()
|
|
||||||
|
@ -98,17 +98,23 @@ class RfxtrxCover(RfxtrxCommandEntity, CoverEntity):
|
|||||||
"""Return if the cover is closed."""
|
"""Return if the cover is closed."""
|
||||||
return not self._state
|
return not self._state
|
||||||
|
|
||||||
def open_cover(self, **kwargs):
|
async def async_open_cover(self, **kwargs):
|
||||||
"""Move the cover up."""
|
"""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."""
|
"""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."""
|
"""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):
|
def _apply_event(self, event):
|
||||||
"""Apply command from rfxtrx."""
|
"""Apply command from rfxtrx."""
|
||||||
|
@ -125,21 +125,25 @@ class RfxtrxLight(RfxtrxCommandEntity, LightEntity):
|
|||||||
"""Return true if device is on."""
|
"""Return true if device is on."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
async def async_turn_on(self, **kwargs):
|
||||||
"""Turn the light on."""
|
"""Turn the device on."""
|
||||||
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
brightness = kwargs.get(ATTR_BRIGHTNESS)
|
||||||
|
self._state = True
|
||||||
if brightness is None:
|
if brightness is None:
|
||||||
|
await self._async_send(self._device.send_on)
|
||||||
self._brightness = 255
|
self._brightness = 255
|
||||||
self._send_command("turn_on")
|
|
||||||
else:
|
else:
|
||||||
|
await self._async_send(self._device.send_dim, brightness * 100 // 255)
|
||||||
self._brightness = brightness
|
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."""
|
"""Turn the device off."""
|
||||||
|
await self._async_send(self._device.send_off)
|
||||||
|
self._state = False
|
||||||
self._brightness = 0
|
self._brightness = 0
|
||||||
self._send_command("turn_off")
|
self.async_write_ha_state()
|
||||||
|
|
||||||
def _apply_event(self, event):
|
def _apply_event(self, event):
|
||||||
"""Apply command from rfxtrx."""
|
"""Apply command from rfxtrx."""
|
||||||
|
@ -127,12 +127,14 @@ class RfxtrxSwitch(RfxtrxCommandEntity, SwitchEntity):
|
|||||||
"""Return true if device is on."""
|
"""Return true if device is on."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
def turn_on(self, **kwargs):
|
async def async_turn_on(self, **kwargs):
|
||||||
"""Turn the device on."""
|
"""Turn the device on."""
|
||||||
self._send_command("turn_on")
|
await self._async_send(self._device.send_on)
|
||||||
self.schedule_update_ha_state()
|
self._state = True
|
||||||
|
self.async_write_ha_state()
|
||||||
|
|
||||||
def turn_off(self, **kwargs):
|
async def async_turn_off(self, **kwargs):
|
||||||
"""Turn the device off."""
|
"""Turn the device off."""
|
||||||
self._send_command("turn_off")
|
await self._async_send(self._device.send_off)
|
||||||
self.schedule_update_ha_state()
|
self._state = False
|
||||||
|
self.async_write_ha_state()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user