mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Modbus switch, allow restore "unknown" (#99533)
This commit is contained in:
parent
c938b9e7a3
commit
d19f617c25
@ -21,6 +21,7 @@ from homeassistant.const import (
|
||||
CONF_SLAVE,
|
||||
CONF_STRUCTURE,
|
||||
CONF_UNIQUE_ID,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
)
|
||||
from homeassistant.core import callback
|
||||
@ -309,7 +310,10 @@ class BaseSwitch(BasePlatform, ToggleEntity, RestoreEntity):
|
||||
"""Handle entity which will be added."""
|
||||
await self.async_base_added_to_hass()
|
||||
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:
|
||||
"""Evaluate switch result."""
|
||||
|
@ -250,7 +250,7 @@ async def test_lazy_error_switch(
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mock_test_state",
|
||||
[(State(ENTITY_ID, STATE_ON),)],
|
||||
[(State(ENTITY_ID, STATE_ON),), (State(ENTITY_ID, STATE_OFF),)],
|
||||
indirect=True,
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
|
Loading…
x
Reference in New Issue
Block a user