Restore rfxtrx state to off when delay off is in effect (#38239)
parent
a1e2bce1b9
commit
0bcee21333
|
@ -13,6 +13,7 @@ from homeassistant.const import (
|
|||
CONF_COMMAND_ON,
|
||||
CONF_DEVICE_CLASS,
|
||||
CONF_DEVICES,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import event as evt
|
||||
|
@ -28,12 +29,7 @@ from . import (
|
|||
get_pt2262_cmd,
|
||||
get_rfx_object,
|
||||
)
|
||||
from .const import (
|
||||
ATTR_EVENT,
|
||||
COMMAND_OFF_LIST,
|
||||
COMMAND_ON_LIST,
|
||||
DEVICE_PACKET_TYPE_LIGHTING4,
|
||||
)
|
||||
from .const import COMMAND_OFF_LIST, COMMAND_ON_LIST, DEVICE_PACKET_TYPE_LIGHTING4
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -184,9 +180,10 @@ class RfxtrxBinarySensor(RfxtrxEntity, BinarySensorEntity):
|
|||
if self._event is None:
|
||||
old_state = await self.async_get_last_state()
|
||||
if old_state is not None:
|
||||
event = old_state.attributes.get(ATTR_EVENT)
|
||||
if event:
|
||||
self._apply_event(get_rfx_object(event))
|
||||
self._state = old_state.state == STATE_ON
|
||||
|
||||
if self._state and self._off_delay is not None:
|
||||
self._state = False
|
||||
|
||||
@property
|
||||
def force_update(self) -> bool:
|
||||
|
|
|
@ -16,6 +16,8 @@ EVENT_MOTION_DETECTOR_NO_MOTION = "08200100a109000570"
|
|||
EVENT_LIGHT_DETECTOR_LIGHT = "08200100a109001570"
|
||||
EVENT_LIGHT_DETECTOR_DARK = "08200100a109001470"
|
||||
|
||||
EVENT_AC_118CDEA_2_ON = "0b1100100118cdea02010f70"
|
||||
|
||||
|
||||
async def test_one(hass, rfxtrx):
|
||||
"""Test with 1 sensor."""
|
||||
|
@ -137,6 +139,37 @@ async def test_discover(hass, rfxtrx_automatic):
|
|||
assert state.state == "on"
|
||||
|
||||
|
||||
async def test_off_delay_restore(hass, rfxtrx):
|
||||
"""Make sure binary sensor restore as off, if off delay is active."""
|
||||
mock_restore_cache(
|
||||
hass,
|
||||
[
|
||||
State(
|
||||
"binary_sensor.ac_118cdea_2",
|
||||
"on",
|
||||
attributes={ATTR_EVENT: EVENT_AC_118CDEA_2_ON},
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"rfxtrx",
|
||||
{
|
||||
"rfxtrx": {
|
||||
"device": "abcd",
|
||||
"devices": {EVENT_AC_118CDEA_2_ON: {"off_delay": 5}},
|
||||
}
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
|
||||
state = hass.states.get("binary_sensor.ac_118cdea_2")
|
||||
assert state
|
||||
assert state.state == "off"
|
||||
|
||||
|
||||
async def test_off_delay(hass, rfxtrx, timestep):
|
||||
"""Test with discovery."""
|
||||
assert await async_setup_component(
|
||||
|
|
Loading…
Reference in New Issue