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_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."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue