From aa8ce07e35beff5ff2fac552d647f5b48160d4ca Mon Sep 17 00:00:00 2001 From: jan iversen Date: Fri, 30 Apr 2021 22:36:55 +0200 Subject: [PATCH] Start Modbus cover timer independent if there is a state to restore (#49919) * Start timer independent if there is a state to restore. * Update test cases, that now start working. --- homeassistant/components/modbus/cover.py | 5 ++--- tests/components/modbus/test_modbus_cover.py | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/modbus/cover.py b/homeassistant/components/modbus/cover.py index dc3da1faa78..a0deba9d732 100644 --- a/homeassistant/components/modbus/cover.py +++ b/homeassistant/components/modbus/cover.py @@ -103,9 +103,8 @@ class ModbusCover(CoverEntity, RestoreEntity): async def async_added_to_hass(self): """Handle entity which will be added.""" state = await self.async_get_last_state() - if not state: - return - self._value = state.state + if state: + self._value = state.state async_track_time_interval( self.hass, lambda arg: self._update(), self._scan_interval diff --git a/tests/components/modbus/test_modbus_cover.py b/tests/components/modbus/test_modbus_cover.py index eddaa6099d7..957f4b28c75 100644 --- a/tests/components/modbus/test_modbus_cover.py +++ b/tests/components/modbus/test_modbus_cover.py @@ -10,8 +10,8 @@ from homeassistant.const import ( CONF_NAME, CONF_SCAN_INTERVAL, CONF_SLAVE, + STATE_CLOSED, STATE_OPEN, - STATE_OPENING, ) from .conftest import base_config_test, base_test @@ -52,23 +52,23 @@ async def test_config_cover(hass, do_options, read_type): [ ( [0x00], - STATE_OPENING, + STATE_CLOSED, ), ( [0x80], - STATE_OPENING, + STATE_CLOSED, ), ( [0xFE], - STATE_OPENING, + STATE_CLOSED, ), ( [0xFF], - STATE_OPENING, + STATE_OPEN, ), ( [0x01], - STATE_OPENING, + STATE_OPEN, ), ], ) @@ -99,7 +99,7 @@ async def test_coil_cover(hass, regs, expected): [ ( [0x00], - STATE_OPEN, + STATE_CLOSED, ), ( [0x80],