Correct Modbus platform cover restore state (#50421)

* Correct cover restore state.

* Change mock usage.

* Add states to convert.
This commit is contained in:
jan iversen 2021-05-16 08:40:19 +02:00 committed by GitHub
parent 1e11bfae05
commit 224cc779c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 1 deletions

View file

@ -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)