Skip to content

Commit 7e9e199

Browse files
authored
Merge pull request #1328 from JurajNyiri/v7.1.15
Fix #484: Remember presets on failure of retrieval, and force refresh on privacy change
2 parents 5f357ca + b7b5a68 commit 7e9e199

5 files changed

Lines changed: 42 additions & 15 deletions

File tree

custom_components/tapo_control/camera.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@
3838
CONF_CUSTOM_STREAM_6,
3939
CONF_CUSTOM_STREAM_7,
4040
)
41-
from .utils import build_device_info, getStreamSource
41+
from .utils import (
42+
async_force_entry_refresh,
43+
build_device_info,
44+
getStreamSource,
45+
)
4246

4347

4448
async def async_setup_entry(
@@ -390,15 +394,15 @@ async def async_turn_on(self):
390394
self._controller.setPrivacyMode,
391395
False,
392396
)
393-
await self._coordinator.async_request_refresh()
397+
await async_force_entry_refresh(self._hass, self._entry)
394398

395399
async def async_turn_off(self):
396400
LOGGER.debug("async_turn_off - camera")
397401
await self._hass.async_add_executor_job(
398402
self._controller.setPrivacyMode,
399403
True,
400404
)
401-
await self._coordinator.async_request_refresh()
405+
await async_force_entry_refresh(self._hass, self._entry)
402406

403407
async def save_preset(self, name):
404408
LOGGER.debug("save_preset - camera")

custom_components/tapo_control/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"codeowners": [
77
"@JurajNyiri"
88
],
9-
"version": "7.1.14",
9+
"version": "7.1.15",
1010
"requirements": [
1111
"pytapo==3.4.14",
1212
"python-kasa[speedups]==0.10.2"

custom_components/tapo_control/select.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,17 +1611,20 @@ async def async_update(self) -> None:
16111611
await self._coordinator.async_request_refresh()
16121612

16131613
def updateTapo(self, camData):
1614-
if not camData or camData["privacy_mode"] == "on":
1614+
if not camData:
16151615
self._attr_state = STATE_UNAVAILABLE
1616+
return
1617+
1618+
self._presets = camData["presets"]
1619+
self._attr_options = list(camData["presets"].values())
1620+
1621+
if camData["privacy_mode"] == "on":
1622+
self._attr_state = STATE_UNAVAILABLE
1623+
elif self._presets:
1624+
self._attr_current_option = None
1625+
self._attr_state = self._attr_current_option
16161626
else:
1617-
self._presets = camData["presets"]
1618-
presetsConvertedToList = list(camData["presets"].values())
1619-
if presetsConvertedToList:
1620-
self._attr_options = list(camData["presets"].values())
1621-
self._attr_current_option = None
1622-
self._attr_state = self._attr_current_option
1623-
else:
1624-
self._attr_state = STATE_UNAVAILABLE
1627+
self._attr_state = STATE_UNAVAILABLE
16251628

16261629
async def async_select_option(self, option: str) -> None:
16271630
foundKey = False

custom_components/tapo_control/switch.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from .const import DOMAIN, LOGGER, ENABLE_MEDIA_SYNC, MEDIA_SYNC_HOURS
99
from .tapo.entities import TapoSwitchEntity
1010
from .utils import (
11+
async_force_entry_refresh,
1112
check_and_create,
1213
check_functionality,
1314
getColdDirPathForEntry,
@@ -959,7 +960,7 @@ async def async_turn_on(self) -> None:
959960
if "error_code" not in result or result["error_code"] == 0:
960961
self._attr_state = "on"
961962
self.async_write_ha_state()
962-
await self._coordinator.async_request_refresh()
963+
await async_force_entry_refresh(self._hass, self._entry)
963964

964965
async def async_turn_off(self) -> None:
965966
result = await self._hass.async_add_executor_job(
@@ -969,7 +970,7 @@ async def async_turn_off(self) -> None:
969970
if "error_code" not in result or result["error_code"] == 0:
970971
self._attr_state = "off"
971972
self.async_write_ha_state()
972-
await self._coordinator.async_request_refresh()
973+
await async_force_entry_refresh(self._hass, self._entry)
973974

974975
def updateTapo(self, camData):
975976
if not camData:

custom_components/tapo_control/utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
from homeassistant.helpers.entity import DeviceInfo
2828
from homeassistant.components.ffmpeg import DATA_FFMPEG
29+
2930
try:
3031
# Home Assistant moved EventManager from `event` to `event_manager` in 2026.5.
3132
from homeassistant.components.onvif.event_manager import EventManager
@@ -88,6 +89,24 @@ def isUsingHTTPS(hass):
8889
return URL(base_url).scheme == "https"
8990

9091

92+
def mark_entry_data_for_refresh(hass: HomeAssistant, entry: dict) -> None:
93+
config_entry = entry.get("entry")
94+
root_entry = (
95+
hass.data.get(DOMAIN, {}).get(config_entry.entry_id) if config_entry else None
96+
)
97+
if root_entry is None:
98+
root_entry = entry
99+
100+
root_entry["lastUpdate"] = 0
101+
for child in root_entry.get("childDevices", []):
102+
child["lastUpdate"] = 0
103+
104+
105+
async def async_force_entry_refresh(hass: HomeAssistant, entry: dict) -> None:
106+
mark_entry_data_for_refresh(hass, entry)
107+
await entry["coordinator"].async_request_refresh()
108+
109+
91110
def getStreamSource(entry, stream):
92111
custom_stream_hd = entry.data.get(CONF_CUSTOM_STREAM_HD, "")
93112
custom_stream_sd = entry.data.get(CONF_CUSTOM_STREAM_SD, "")

0 commit comments

Comments
 (0)