forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove Aladdin Connect integration (home-assistant#120980)
- Loading branch information
Showing
20 changed files
with
89 additions
and
738 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,38 @@ | ||
"""The Aladdin Connect Genie integration.""" | ||
|
||
# mypy: ignore-errors | ||
from __future__ import annotations | ||
|
||
# from genie_partner_sdk.client import AladdinConnectClient | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.const import Platform | ||
from homeassistant.config_entries import ConfigEntry, ConfigEntryState | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers import device_registry as dr | ||
from homeassistant.helpers.aiohttp_client import async_get_clientsession | ||
from homeassistant.helpers.config_entry_oauth2_flow import ( | ||
OAuth2Session, | ||
async_get_config_entry_implementation, | ||
) | ||
|
||
from .api import AsyncConfigEntryAuth | ||
from .const import DOMAIN | ||
from .coordinator import AladdinConnectCoordinator | ||
|
||
PLATFORMS: list[Platform] = [Platform.COVER, Platform.SENSOR] | ||
|
||
type AladdinConnectConfigEntry = ConfigEntry[AladdinConnectCoordinator] | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, entry: AladdinConnectConfigEntry | ||
) -> bool: | ||
"""Set up Aladdin Connect Genie from a config entry.""" | ||
implementation = await async_get_config_entry_implementation(hass, entry) | ||
|
||
session = OAuth2Session(hass, entry, implementation) | ||
auth = AsyncConfigEntryAuth(async_get_clientsession(hass), session) | ||
coordinator = AladdinConnectCoordinator(hass, AladdinConnectClient(auth)) | ||
|
||
await coordinator.async_setup() | ||
await coordinator.async_config_entry_first_refresh() | ||
|
||
entry.runtime_data = coordinator | ||
|
||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) | ||
|
||
async_remove_stale_devices(hass, entry) | ||
from homeassistant.helpers import issue_registry as ir | ||
|
||
DOMAIN = "aladdin_connect" | ||
|
||
|
||
async def async_setup_entry(hass: HomeAssistant, _: ConfigEntry) -> bool: | ||
"""Set up Aladdin Connect from a config entry.""" | ||
ir.async_create_issue( | ||
hass, | ||
DOMAIN, | ||
DOMAIN, | ||
is_fixable=False, | ||
severity=ir.IssueSeverity.ERROR, | ||
translation_key="integration_removed", | ||
translation_placeholders={ | ||
"entries": "/config/integrations/integration/aladdin_connect", | ||
}, | ||
) | ||
|
||
return True | ||
|
||
|
||
async def async_unload_entry( | ||
hass: HomeAssistant, entry: AladdinConnectConfigEntry | ||
) -> bool: | ||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: | ||
"""Unload a config entry.""" | ||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) | ||
|
||
|
||
async def async_migrate_entry( | ||
hass: HomeAssistant, config_entry: AladdinConnectConfigEntry | ||
) -> bool: | ||
"""Migrate old config.""" | ||
if config_entry.version < 2: | ||
config_entry.async_start_reauth(hass) | ||
hass.config_entries.async_update_entry( | ||
config_entry, | ||
version=2, | ||
minor_version=1, | ||
) | ||
if all( | ||
config_entry.state is ConfigEntryState.NOT_LOADED | ||
for config_entry in hass.config_entries.async_entries(DOMAIN) | ||
if config_entry.entry_id != entry.entry_id | ||
): | ||
ir.async_delete_issue(hass, DOMAIN, DOMAIN) | ||
|
||
return True | ||
|
||
|
||
def async_remove_stale_devices( | ||
hass: HomeAssistant, config_entry: AladdinConnectConfigEntry | ||
) -> None: | ||
"""Remove stale devices from device registry.""" | ||
device_registry = dr.async_get(hass) | ||
device_entries = dr.async_entries_for_config_entry( | ||
device_registry, config_entry.entry_id | ||
) | ||
all_device_ids = {door.unique_id for door in config_entry.runtime_data.doors} | ||
|
||
for device_entry in device_entries: | ||
device_id: str | None = None | ||
|
||
for identifier in device_entry.identifiers: | ||
if identifier[0] == DOMAIN: | ||
device_id = identifier[1] | ||
break | ||
|
||
if device_id is None or device_id not in all_device_ids: | ||
# If device_id is None an invalid device entry was found for this config entry. | ||
# If the device_id is not in existing device ids it's a stale device entry. | ||
# Remove config entry from this device entry in either case. | ||
device_registry.async_update_device( | ||
device_entry.id, remove_config_entry_id=config_entry.entry_id | ||
) |
This file was deleted.
Oops, something went wrong.
14 changes: 0 additions & 14 deletions
14
homeassistant/components/aladdin_connect/application_credentials.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,11 @@ | ||
"""Config flow for Aladdin Connect Genie.""" | ||
"""Config flow for Aladdin Connect integration.""" | ||
|
||
from collections.abc import Mapping | ||
import logging | ||
from typing import Any | ||
from homeassistant.config_entries import ConfigFlow | ||
|
||
import jwt | ||
from . import DOMAIN | ||
|
||
from homeassistant.config_entries import ConfigEntry, ConfigFlowResult | ||
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_TOKEN | ||
from homeassistant.helpers.config_entry_oauth2_flow import AbstractOAuth2FlowHandler | ||
|
||
from .const import DOMAIN | ||
class AladdinConnectConfigFlow(ConfigFlow, domain=DOMAIN): | ||
"""Handle a config flow for Aladdin Connect.""" | ||
|
||
|
||
class AladdinConnectOAuth2FlowHandler(AbstractOAuth2FlowHandler, domain=DOMAIN): | ||
"""Config flow to handle Aladdin Connect Genie OAuth2 authentication.""" | ||
|
||
DOMAIN = DOMAIN | ||
VERSION = 2 | ||
MINOR_VERSION = 1 | ||
|
||
reauth_entry: ConfigEntry | None = None | ||
|
||
async def async_step_reauth( | ||
self, user_input: Mapping[str, Any] | ||
) -> ConfigFlowResult: | ||
"""Perform reauth upon API auth error or upgrade from v1 to v2.""" | ||
self.reauth_entry = self.hass.config_entries.async_get_entry( | ||
self.context["entry_id"] | ||
) | ||
return await self.async_step_reauth_confirm() | ||
|
||
async def async_step_reauth_confirm( | ||
self, user_input: Mapping[str, Any] | None = None | ||
) -> ConfigFlowResult: | ||
"""Dialog that informs the user that reauth is required.""" | ||
if user_input is None: | ||
return self.async_show_form(step_id="reauth_confirm") | ||
return await self.async_step_user() | ||
|
||
async def async_oauth_create_entry(self, data: dict[str, Any]) -> ConfigFlowResult: | ||
"""Create an oauth config entry or update existing entry for reauth.""" | ||
token_payload = jwt.decode( | ||
data[CONF_TOKEN][CONF_ACCESS_TOKEN], options={"verify_signature": False} | ||
) | ||
if not self.reauth_entry: | ||
await self.async_set_unique_id(token_payload["sub"]) | ||
self._abort_if_unique_id_configured() | ||
|
||
return self.async_create_entry( | ||
title=token_payload["username"], | ||
data=data, | ||
) | ||
|
||
if self.reauth_entry.unique_id == token_payload["username"]: | ||
return self.async_update_reload_and_abort( | ||
self.reauth_entry, | ||
data=data, | ||
unique_id=token_payload["sub"], | ||
) | ||
if self.reauth_entry.unique_id == token_payload["sub"]: | ||
return self.async_update_reload_and_abort(self.reauth_entry, data=data) | ||
|
||
return self.async_abort(reason="wrong_account") | ||
|
||
@property | ||
def logger(self) -> logging.Logger: | ||
"""Return logger.""" | ||
return logging.getLogger(__name__) | ||
VERSION = 1 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.