async def unregister_webhook( call_or_event: ServiceCall | Event | None) -> None: if CONF_WEBHOOK_ID not in entry.data: return _LOGGER.debug("Unregister Netatmo webhook (%s)", entry.data[CONF_WEBHOOK_ID]) async_dispatcher_send( hass, f"signal-{DOMAIN}-webhook-None", { "type": "None", "data": { WEBHOOK_PUSH_TYPE: WEBHOOK_DEACTIVATION } }, ) webhook_unregister(hass, entry.data[CONF_WEBHOOK_ID]) try: await hass.data[DOMAIN][entry.entry_id][AUTH].async_dropwebhook() except pyatmo.ApiError: _LOGGER.debug("No webhook to be dropped for %s", entry.data[CONF_WEBHOOK_ID]) nonlocal _webhook_retries if _webhook_retries < MAX_WEBHOOK_RETRIES: _webhook_retries += 1 async_call_later(hass, 30, register_webhook)
async def unregister_webhook(self, event: Optional[Event] = None) -> None: """Remove / Unregister webhook for toon.""" _LOGGER.debug("Unregistering Toon webhook (%s)", self.entry.data[CONF_WEBHOOK_ID]) try: await self.toon.unsubscribe_webhook(self.entry.entry_id) except ToonError as err: _LOGGER.error("Failed unregistering Toon webhook - %s", err) webhook_unregister(self.hass, self.entry.data[CONF_WEBHOOK_ID])
async def unregister_webhook(_): if CONF_WEBHOOK_ID not in entry.data: return _LOGGER.debug("Unregister Netatmo webhook (%s)", entry.data[CONF_WEBHOOK_ID]) async_dispatcher_send( hass, f"signal-{DOMAIN}-webhook-None", {"type": "None", "data": {"push_type": "webhook_deactivation"}}, ) webhook_unregister(hass, entry.data[CONF_WEBHOOK_ID])
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" webhook_unregister(hass, entry.data[CONF_WEBHOOK_ID]) unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: config_data = hass.data[DOMAIN].pop(entry.entry_id) await config_data[CONF_CLIENT].async_client_close() return unload_ok
async def async_unload_entry(hass, entry): """Unload a mobile app entry.""" unload_ok = all(await asyncio.gather(*[ hass.config_entries.async_forward_entry_unload(entry, component) for component in PLATFORMS ])) if not unload_ok: return False webhook_unregister(hass, entry.data[CONF_WEBHOOK_ID]) return True
async def async_unload_entry(hass, entry): """Unload a mobile app entry.""" unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if not unload_ok: return False webhook_id = entry.data[CONF_WEBHOOK_ID] webhook_unregister(hass, webhook_id) del hass.data[DOMAIN][DATA_CONFIG_ENTRIES][webhook_id] del hass.data[DOMAIN][DATA_DEVICES][webhook_id] await hass_notify.async_reload(hass, DOMAIN) return True
async def register_webhook(self, event: Event | None = None) -> None: """Register a webhook with Toon to get live updates.""" if CONF_WEBHOOK_ID not in self.entry.data: data = {**self.entry.data, CONF_WEBHOOK_ID: secrets.token_hex()} self.hass.config_entries.async_update_entry(self.entry, data=data) if cloud.async_active_subscription(self.hass): if CONF_CLOUDHOOK_URL not in self.entry.data: try: webhook_url = await cloud.async_create_cloudhook( self.hass, self.entry.data[CONF_WEBHOOK_ID] ) except cloud.CloudNotConnected: webhook_url = webhook.async_generate_url( self.hass, self.entry.data[CONF_WEBHOOK_ID] ) else: data = {**self.entry.data, CONF_CLOUDHOOK_URL: webhook_url} self.hass.config_entries.async_update_entry(self.entry, data=data) else: webhook_url = self.entry.data[CONF_CLOUDHOOK_URL] else: webhook_url = webhook.async_generate_url( self.hass, self.entry.data[CONF_WEBHOOK_ID] ) # Ensure the webhook is not registered already webhook_unregister(self.hass, self.entry.data[CONF_WEBHOOK_ID]) webhook_register( self.hass, DOMAIN, "Toon", self.entry.data[CONF_WEBHOOK_ID], self.handle_webhook, ) try: await self.toon.subscribe_webhook( application_id=self.entry.entry_id, url=webhook_url ) _LOGGER.info("Registered Toon webhook: %s", webhook_url) except ToonError as err: _LOGGER.error("Error during webhook registration - %s", err) self.hass.bus.async_listen_once( EVENT_HOMEASSISTANT_STOP, self.unregister_webhook )
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" data = hass.data[DOMAIN] if CONF_WEBHOOK_ID in entry.data: webhook_unregister(hass, entry.data[CONF_WEBHOOK_ID]) await data[entry.entry_id][AUTH].async_dropwebhook() _LOGGER.info("Unregister Netatmo webhook") unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok and entry.entry_id in data: data.pop(entry.entry_id) return unload_ok
async def unregister_webhook(_: None) -> None: if CONF_WEBHOOK_ID not in entry.data: return _LOGGER.debug("Unregister Netatmo webhook (%s)", entry.data[CONF_WEBHOOK_ID]) async_dispatcher_send( hass, f"signal-{DOMAIN}-webhook-None", {"type": "None", "data": {WEBHOOK_PUSH_TYPE: WEBHOOK_DEACTIVATION}}, ) webhook_unregister(hass, entry.data[CONF_WEBHOOK_ID]) try: await hass.data[DOMAIN][entry.entry_id][AUTH].async_dropwebhook() except pyatmo.ApiError: _LOGGER.debug( "No webhook to be dropped for %s", entry.data[CONF_WEBHOOK_ID] )
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): """Unload a config entry.""" if CONF_WEBHOOK_ID in entry.data: webhook_unregister(hass, entry.data[CONF_WEBHOOK_ID]) await hass.data[DOMAIN][entry.entry_id][AUTH].async_dropwebhook() _LOGGER.info("Unregister Netatmo webhook") await hass.data[DOMAIN][entry.entry_id][DATA_HANDLER].async_cleanup() unload_ok = await hass.config_entries.async_unload_platforms( entry, PLATFORMS) if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) return unload_ok
async def async_unload_entry(hass, entry): """Unload a mobile app entry.""" unload_ok = all(await asyncio.gather(*[ hass.config_entries.async_forward_entry_unload(entry, component) for component in PLATFORMS ])) if not unload_ok: return False webhook_id = entry.data[CONF_WEBHOOK_ID] webhook_unregister(hass, webhook_id) del hass.data[DOMAIN][DATA_CONFIG_ENTRIES][webhook_id] await hass_notify.async_reload(hass, DOMAIN) return True
async def unregister_webhook(event): _LOGGER.debug("Unregister Netatmo webhook (%s)", entry.data[CONF_WEBHOOK_ID]) webhook_unregister(hass, entry.data[CONF_WEBHOOK_ID])
async def unregister_webhook(_): if CONF_WEBHOOK_ID not in entry.data: return _LOGGER.debug("Unregister Netatmo webhook (%s)", entry.data[CONF_WEBHOOK_ID]) webhook_unregister(hass, entry.data[CONF_WEBHOOK_ID])