Skip to content

Commit 324a7b5

Browse files
thecodefrenck
authored andcommitted
Fix Shelly RPC cover update when the device is not initialized (home-assistant#154159)
1 parent 491ae8f commit 324a7b5

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

homeassistant/components/shelly/cover.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ async def update_position(self) -> None:
226226
def _update_callback(self) -> None:
227227
"""Handle device update. Use a task when opening/closing is in progress."""
228228
super()._update_callback()
229+
if not self.coordinator.device.initialized:
230+
return
229231
if self.is_closing or self.is_opening:
230232
self.launch_update_task()
231233

tests/components/shelly/test_cover.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
CoverState,
2424
)
2525
from homeassistant.components.shelly.const import RPC_COVER_UPDATE_TIME_SEC
26-
from homeassistant.const import ATTR_ENTITY_ID
26+
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE
2727
from homeassistant.core import HomeAssistant
2828
from homeassistant.helpers.entity_registry import EntityRegistry
2929

@@ -417,3 +417,20 @@ async def test_update_position_no_movement(
417417
assert (state := hass.states.get(entity_id))
418418
assert state.state == CoverState.OPEN
419419
assert state.attributes[ATTR_CURRENT_POSITION] == 100
420+
421+
422+
async def test_rpc_not_initialized_update(
423+
hass: HomeAssistant, mock_rpc_device: Mock, monkeypatch: pytest.MonkeyPatch
424+
) -> None:
425+
"""Test update not called when device is not initialized."""
426+
entity_id = "cover.test_name_test_cover_0"
427+
await init_integration(hass, 2)
428+
429+
assert (state := hass.states.get(entity_id))
430+
assert state.state == CoverState.OPEN
431+
432+
monkeypatch.setattr(mock_rpc_device, "initialized", False)
433+
mock_rpc_device.mock_update()
434+
435+
assert (state := hass.states.get(entity_id))
436+
assert state.state == STATE_UNAVAILABLE

0 commit comments

Comments
 (0)