Correct Modbus platform cover restore state (#50421)
* Correct cover restore state. * Change mock usage. * Add states to convert.
This commit is contained in:
parent
1e11bfae05
commit
224cc779c4
2 changed files with 59 additions and 1 deletions
|
@ -12,6 +12,12 @@ from homeassistant.const import (
|
|||
CONF_NAME,
|
||||
CONF_SCAN_INTERVAL,
|
||||
CONF_SLAVE,
|
||||
STATE_CLOSED,
|
||||
STATE_CLOSING,
|
||||
STATE_OPEN,
|
||||
STATE_OPENING,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.event import async_track_time_interval
|
||||
|
@ -105,7 +111,15 @@ class ModbusCover(CoverEntity, RestoreEntity):
|
|||
"""Handle entity which will be added."""
|
||||
state = await self.async_get_last_state()
|
||||
if state:
|
||||
self._value = state.state
|
||||
convert = {
|
||||
STATE_CLOSED: self._state_closed,
|
||||
STATE_CLOSING: self._state_closing,
|
||||
STATE_OPENING: self._state_opening,
|
||||
STATE_OPEN: self._state_open,
|
||||
STATE_UNAVAILABLE: None,
|
||||
STATE_UNKNOWN: None,
|
||||
}
|
||||
self._value = convert[state.state]
|
||||
|
||||
async_track_time_interval(self.hass, self.async_update, self._scan_interval)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue