Clean up commands generation for rfxtrx (#38236)
This commit is contained in:
parent
c3966a5ef2
commit
c93fc8af4a
4 changed files with 34 additions and 53 deletions
|
@ -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."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue