Modbus switch, allow restore "unknown" (#99533)
This commit is contained in:
parent
c938b9e7a3
commit
d19f617c25
2 changed files with 6 additions and 2 deletions
|
@ -21,6 +21,7 @@ from homeassistant.const import (
|
||||||
CONF_SLAVE,
|
CONF_SLAVE,
|
||||||
CONF_STRUCTURE,
|
CONF_STRUCTURE,
|
||||||
CONF_UNIQUE_ID,
|
CONF_UNIQUE_ID,
|
||||||
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
@ -309,7 +310,10 @@ class BaseSwitch(BasePlatform, ToggleEntity, RestoreEntity):
|
||||||
"""Handle entity which will be added."""
|
"""Handle entity which will be added."""
|
||||||
await self.async_base_added_to_hass()
|
await self.async_base_added_to_hass()
|
||||||
if state := await self.async_get_last_state():
|
if state := await self.async_get_last_state():
|
||||||
self._attr_is_on = state.state == STATE_ON
|
if state.state == STATE_ON:
|
||||||
|
self._attr_is_on = True
|
||||||
|
elif state.state == STATE_OFF:
|
||||||
|
self._attr_is_on = False
|
||||||
|
|
||||||
async def async_turn(self, command: int) -> None:
|
async def async_turn(self, command: int) -> None:
|
||||||
"""Evaluate switch result."""
|
"""Evaluate switch result."""
|
||||||
|
|
|
@ -250,7 +250,7 @@ async def test_lazy_error_switch(
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"mock_test_state",
|
"mock_test_state",
|
||||||
[(State(ENTITY_ID, STATE_ON),)],
|
[(State(ENTITY_ID, STATE_ON),), (State(ENTITY_ID, STATE_OFF),)],
|
||||||
indirect=True,
|
indirect=True,
|
||||||
)
|
)
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue