Rfxtrx fixup restore (#38039)
This commit is contained in:
1 parent
0b32caa71f
commit
66e490e55f
11 files changed
+204
-186
No files matched your search
@@ -4,9 +4,8 @@ import logging
|
||||
import RFXtrx as rfxtrxmod
|
||||
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.const import CONF_DEVICES
|
||||
from homeassistant.const import CONF_DEVICES, STATE_ON
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
|
||||
from . import (
|
||||
CONF_AUTOMATIC_ADD,
|
||||
@@ -14,7 +13,7 @@ from . import (
|
||||
DEFAULT_SIGNAL_REPETITIONS,
|
||||
DOMAIN,
|
||||
SIGNAL_EVENT,
|
||||
RfxtrxDevice,
|
||||
RfxtrxCommandEntity,
|
||||
get_device_id,
|
||||
get_rfx_object,
|
||||
)
|
||||
@@ -89,18 +88,17 @@ async def async_setup_entry(
|
||||
hass.helpers.dispatcher.async_dispatcher_connect(SIGNAL_EVENT, switch_update)
|
||||
|
||||
|
||||
class RfxtrxSwitch(RfxtrxDevice, SwitchEntity, RestoreEntity):
|
||||
class RfxtrxSwitch(RfxtrxCommandEntity, SwitchEntity):
|
||||
"""Representation of a RFXtrx switch."""
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Restore RFXtrx switch device state (ON/OFF)."""
|
||||
"""Restore device state."""
|
||||
await super().async_added_to_hass()
|
||||
|
||||
self.async_on_remove(
|
||||
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
||||
SIGNAL_EVENT, self._handle_event
|
||||
)
|
||||
)
|
||||
if self._event is None:
|
||||
old_state = await self.async_get_last_state()
|
||||
if old_state is not None:
|
||||
self._state = old_state.state == STATE_ON
|
||||
|
||||
def _apply_event(self, event):
|
||||
"""Apply command from rfxtrx."""
|
||||
@@ -120,6 +118,11 @@ class RfxtrxSwitch(RfxtrxDevice, SwitchEntity, RestoreEntity):
|
||||
|
||||
self.async_write_ha_state()
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if device is on."""
|
||||
return self._state
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn the device on."""
|
||||
self._send_command("turn_on")
|
||||
|
||||
Reference in new issue
Block a user