Skip to content

Commit

Permalink
Fix #528: Compatibility with HA 2024.4.0.dev20240229
Browse files Browse the repository at this point in the history
  • Loading branch information
JurajNyiri committed Feb 29, 2024
1 parent 7ffb043 commit 0540952
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 33 deletions.
55 changes: 26 additions & 29 deletions custom_components/tapo_control/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
"Home Assistant is running on HTTPS or it was not able to detect base_url schema. Disabling webhooks."
)

# todo: figure out where to set officially?
entry.unique_id = DOMAIN + host

try:
if cloud_password != "":
tapoController = await hass.async_add_executor_job(
Expand Down Expand Up @@ -362,12 +359,12 @@ async def async_update_data():
)
if onvifDevice:
LOGGER.debug(onvifDevice)
hass.data[DOMAIN][entry.entry_id][
"eventsDevice"
] = onvifDevice["device"]
hass.data[DOMAIN][entry.entry_id][
"onvifManagement"
] = onvifDevice["device_mgmt"]
hass.data[DOMAIN][entry.entry_id]["eventsDevice"] = (
onvifDevice["device"]
)
hass.data[DOMAIN][entry.entry_id]["onvifManagement"] = (
onvifDevice["device_mgmt"]
)
if motionSensor:
await setupOnvif(hass, entry)
elif (
Expand All @@ -379,9 +376,9 @@ async def async_update_data():
)
# retry if subscription to events failed
try:
hass.data[DOMAIN][entry.entry_id][
"eventsSetup"
] = await setupEvents(hass, entry)
hass.data[DOMAIN][entry.entry_id]["eventsSetup"] = (
await setupEvents(hass, entry)
)
except AssertionError as e:
if str(e) != "PullPoint manager already started":
raise AssertionError(e)
Expand All @@ -407,24 +404,24 @@ async def async_update_data():
ts - hass.data[DOMAIN][entry.entry_id]["lastFirmwareCheck"]
> UPDATE_CHECK_PERIOD
):
hass.data[DOMAIN][entry.entry_id][
"latestFirmwareVersion"
] = await getLatestFirmwareVersion(
hass,
entry,
hass.data[DOMAIN][entry.entry_id],
tapoController,
hass.data[DOMAIN][entry.entry_id]["latestFirmwareVersion"] = (
await getLatestFirmwareVersion(
hass,
entry,
hass.data[DOMAIN][entry.entry_id],
tapoController,
)
)
for childDevice in hass.data[DOMAIN][entry.entry_id][
"childDevices"
]:
childDevice[
"latestFirmwareVersion"
] = await getLatestFirmwareVersion(
hass,
entry,
hass.data[DOMAIN][entry.entry_id],
childDevice["controller"],
childDevice["latestFirmwareVersion"] = (
await getLatestFirmwareVersion(
hass,
entry,
hass.data[DOMAIN][entry.entry_id],
childDevice["controller"],
)
)

# cameras state
Expand Down Expand Up @@ -463,9 +460,9 @@ async def async_update_data():
raise ConfigEntryAuthFailed(e)
LOGGER.error(e)

hass.data[DOMAIN][entry.entry_id][
"camData"
] = updateDataForAllControllers[tapoController]
hass.data[DOMAIN][entry.entry_id]["camData"] = (
updateDataForAllControllers[tapoController]
)

LOGGER.debug("Updating entities...")

Expand Down
14 changes: 10 additions & 4 deletions custom_components/tapo_control/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ async def async_step_reauth_confirm_stream(self, user_input=None):
self.reauth_entry,
title=tapoHost,
data=allConfigData,
unique_id=DOMAIN + tapoHost,
)
try:
LOGGER.debug(
Expand Down Expand Up @@ -228,6 +229,7 @@ async def async_step_reauth_confirm_cloud(self, user_input=None):
self.reauth_entry,
title=tapoHost,
data=allConfigData,
unique_id=DOMAIN + tapoHost,
)
await self.hass.config_entries.async_reload(self.reauth_entry.entry_id)
return self.async_abort(reason="reauth_successful")
Expand Down Expand Up @@ -387,6 +389,7 @@ async def async_step_other_options(self, user_input=None):
"[ADD DEVICE][%s] Saving entry.",
self.tapoHost,
)
await self.async_set_unique_id(DOMAIN + host)
return self.async_create_entry(
title=host,
data={
Expand Down Expand Up @@ -842,7 +845,7 @@ async def async_step_init(self, user_input=None):
"options": [
"Configure device",
"Configure sound sensor",
"Configure media"
"Configure media",
# "Help me debug motion sensor",
# "incorrect",
],
Expand Down Expand Up @@ -911,6 +914,7 @@ async def async_step_sound_sensor(self, user_input=None):
self.config_entry,
title=ip_address,
data=allConfigData,
unique_id=DOMAIN + ip_address,
)
return self.async_create_entry(title="", data=None)
except Exception as e:
Expand Down Expand Up @@ -998,14 +1002,15 @@ async def async_step_media(self, user_input=None):
allConfigData[MEDIA_VIEW_DAYS_ORDER] = media_view_days_order
allConfigData[MEDIA_VIEW_RECORDINGS_ORDER] = media_view_recordings_order
allConfigData[MEDIA_SYNC_HOURS] = media_sync_hours
allConfigData[
MEDIA_SYNC_COLD_STORAGE_PATH
] = media_sync_cold_storage_path
allConfigData[MEDIA_SYNC_COLD_STORAGE_PATH] = (
media_sync_cold_storage_path
)
# todo also initial setup to add the default values!
self.hass.config_entries.async_update_entry(
self.config_entry,
title=ip_address,
data=allConfigData,
unique_id=DOMAIN + ip_address,
)
return self.async_create_entry(title="", data=None)
except Exception as e:
Expand Down Expand Up @@ -1248,6 +1253,7 @@ async def async_step_auth(self, user_input=None):
self.config_entry,
title=ip_address,
data=allConfigData,
unique_id=DOMAIN + ip_address,
)
if ipChanged:
LOGGER.debug(
Expand Down

0 comments on commit 0540952

Please sign in to comment.