1 """The Rituals Perfume Genie integration."""
6 from pyrituals
import Account, Diffuser
15 from .const
import ACCOUNT_HASH, DOMAIN, UPDATE_INTERVAL
16 from .coordinator
import RitualsDataUpdateCoordinator
19 Platform.BINARY_SENSOR,
28 """Set up Rituals Perfume Genie from a config entry."""
30 account = Account(session=session, account_hash=entry.data[ACCOUNT_HASH])
33 account_devices = await account.get_devices()
34 except aiohttp.ClientError
as err:
35 raise ConfigEntryNotReady
from err
43 update_interval = UPDATE_INTERVAL * len(account_devices)
48 for diffuser
in account_devices
54 coordinator.async_config_entry_first_refresh()
55 for coordinator
in coordinators.values()
59 hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinators
60 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
66 """Unload a config entry."""
67 unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
69 hass.data[DOMAIN].pop(entry.entry_id)
76 hass: HomeAssistant, config_entry: ConfigEntry, diffusers: list[Diffuser]
78 """Migrate unique_ids in the entity registry to the new format."""
79 entity_registry = er.async_get(hass)
80 registry_entries = er.async_entries_for_config_entry(
81 entity_registry, config_entry.entry_id
84 conversion: dict[tuple[str, str], str] = {
85 (Platform.BINARY_SENSOR,
" Battery Charging"):
"charging",
86 (Platform.NUMBER,
" Perfume Amount"):
"perfume_amount",
87 (Platform.SELECT,
" Room Size"):
"room_size_square_meter",
88 (Platform.SENSOR,
" Battery"):
"battery_percentage",
89 (Platform.SENSOR,
" Fill"):
"fill",
90 (Platform.SENSOR,
" Perfume"):
"perfume",
91 (Platform.SENSOR,
" Wifi"):
"wifi_percentage",
92 (Platform.SWITCH,
""):
"is_on",
95 for diffuser
in diffusers:
96 for registry_entry
in registry_entries:
97 if new_unique_id := conversion.get(
99 registry_entry.domain,
100 registry_entry.unique_id.removeprefix(diffuser.hublot),
103 entity_registry.async_update_entity(
104 registry_entry.entity_id,
105 new_unique_id=f
"{diffuser.hublot}-{new_unique_id}",
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
None async_migrate_entities_unique_ids(HomeAssistant hass, ConfigEntry config_entry, list[Diffuser] diffusers)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)