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_COMMAND_ON,
|
||||||
CONF_DEVICE_CLASS,
|
CONF_DEVICE_CLASS,
|
||||||
CONF_DEVICES,
|
CONF_DEVICES,
|
||||||
|
STATE_ON,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers import event as evt
|
from homeassistant.helpers import event as evt
|
||||||
|
@ -28,12 +29,7 @@ from . import (
|
||||||
get_pt2262_cmd,
|
get_pt2262_cmd,
|
||||||
get_rfx_object,
|
get_rfx_object,
|
||||||
)
|
)
|
||||||
from .const import (
|
from .const import COMMAND_OFF_LIST, COMMAND_ON_LIST, DEVICE_PACKET_TYPE_LIGHTING4
|
||||||
ATTR_EVENT,
|
|
||||||
COMMAND_OFF_LIST,
|
|
||||||
COMMAND_ON_LIST,
|
|
||||||
DEVICE_PACKET_TYPE_LIGHTING4,
|
|
||||||
)
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -184,9 +180,10 @@ class RfxtrxBinarySensor(RfxtrxEntity, BinarySensorEntity):
|
||||||
if self._event is None:
|
if self._event is None:
|
||||||
old_state = await self.async_get_last_state()
|
old_state = await self.async_get_last_state()
|
||||||
if old_state is not None:
|
if old_state is not None:
|
||||||
event = old_state.attributes.get(ATTR_EVENT)
|
self._state = old_state.state == STATE_ON
|
||||||
if event:
|
|
||||||
self._apply_event(get_rfx_object(event))
|
if self._state and self._off_delay is not None:
|
||||||
|
self._state = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def force_update(self) -> bool:
|
def force_update(self) -> bool:
|
||||||
|
|
|
@ -16,6 +16,8 @@ EVENT_MOTION_DETECTOR_NO_MOTION = "08200100a109000570"
|
||||||
EVENT_LIGHT_DETECTOR_LIGHT = "08200100a109001570"
|
EVENT_LIGHT_DETECTOR_LIGHT = "08200100a109001570"
|
||||||
EVENT_LIGHT_DETECTOR_DARK = "08200100a109001470"
|
EVENT_LIGHT_DETECTOR_DARK = "08200100a109001470"
|
||||||
|
|
||||||
|
EVENT_AC_118CDEA_2_ON = "0b1100100118cdea02010f70"
|
||||||
|
|
||||||
|
|
||||||
async def test_one(hass, rfxtrx):
|
async def test_one(hass, rfxtrx):
|
||||||
"""Test with 1 sensor."""
|
"""Test with 1 sensor."""
|
||||||
|
@ -137,6 +139,37 @@ async def test_discover(hass, rfxtrx_automatic):
|
||||||
assert state.state == "on"
|
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):
|
async def test_off_delay(hass, rfxtrx, timestep):
|
||||||
"""Test with discovery."""
|
"""Test with discovery."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
|
|
Loading…
Reference in New Issue