Do not reload Shelly TRV entry when not needed (#88037)

* Do not reload the entry when the target temperature changes

* Do not reload the entry when the mode changes

* Increase test coverage

* Increase test coverage
pull/88163/head
Maciej Bieniek 2023-02-15 10:21:53 +01:00 committed by GitHub
parent cd4ce86f07
commit 95bb019f71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -161,6 +161,7 @@ class ShellyBlockCoordinator(ShellyCoordinatorBase[BlockDevice]):
self._last_mode: str | None = None
self._last_effect: int | None = None
self._last_input_events_count: dict = {}
self._last_target_temp: float | None = None
entry.async_on_unload(
self.async_add_listener(self._async_device_updates_handler)
@ -194,6 +195,18 @@ class ShellyBlockCoordinator(ShellyCoordinatorBase[BlockDevice]):
if block.type == "device":
cfg_changed = block.cfgChanged
if self.model == "SHTRV-01":
# Reloading the entry is not needed when the target temperature changes
if "targetTemp" in block.sensor_ids:
if self._last_target_temp != block.targetTemp:
self._last_cfg_changed = None
self._last_target_temp = block.targetTemp
# Reloading the entry is not needed when the mode changes
if "mode" in block.sensor_ids:
if self._last_mode != block.mode:
self._last_cfg_changed = None
self._last_mode = block.mode
# For dual mode bulbs ignore change if it is due to mode/effect change
if self.model in DUAL_MODE_LIGHT_MODELS:
if "mode" in block.sensor_ids:

View File

@ -35,8 +35,13 @@ ENTITY_ID = f"{CLIMATE_DOMAIN}.test_name"
async def test_climate_hvac_mode(hass, mock_block_device, monkeypatch):
"""Test climate hvac mode service."""
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
monkeypatch.setattr(
mock_block_device.blocks[SENSOR_BLOCK_ID],
"sensor_ids",
{"battery": 98, "valvePos": 50, "targetTemp": 21.0},
)
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 0)
await init_integration(hass, 1, sleep_period=1000)
await init_integration(hass, 1, sleep_period=1000, model="SHTRV-01")
# Make device online
mock_block_device.mock_update()
@ -131,7 +136,7 @@ async def test_climate_set_preset_mode(hass, mock_block_device, monkeypatch):
monkeypatch.delattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "targetTemp")
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "valveError", 0)
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "mode", None)
await init_integration(hass, 1, sleep_period=1000)
await init_integration(hass, 1, sleep_period=1000, model="SHTRV-01")
# Make device online
mock_block_device.mock_update()