88from homeassistant .helpers import config_validation as cv
99from homeassistant .util import slugify
1010
11- from .account import IcloudAccount
11+ from .account import IcloudAccount , IcloudConfigEntry
1212from .const import (
1313 ATTR_ACCOUNT ,
1414 ATTR_DEVICE_NAME ,
@@ -92,8 +92,10 @@ def lost_device(service: ServiceCall) -> None:
9292def update_account (service : ServiceCall ) -> None :
9393 """Call the update function of an iCloud account."""
9494 if (account := service .data .get (ATTR_ACCOUNT )) is None :
95- for account in service .hass .data [DOMAIN ].values ():
96- account .keep_alive ()
95+ # Update all accounts when no specific account is provided
96+ entry : IcloudConfigEntry
97+ for entry in service .hass .config_entries .async_loaded_entries (DOMAIN ):
98+ entry .runtime_data .keep_alive ()
9799 else :
98100 _get_account (service .hass , account ).keep_alive ()
99101
@@ -102,17 +104,12 @@ def _get_account(hass: HomeAssistant, account_identifier: str) -> IcloudAccount:
102104 if account_identifier is None :
103105 return None
104106
105- icloud_account : IcloudAccount | None = hass .data [DOMAIN ].get (account_identifier )
106- if icloud_account is None :
107- for account in hass .data [DOMAIN ].values ():
108- if account .username == account_identifier :
109- icloud_account = account
110-
111- if icloud_account is None :
112- raise ValueError (
113- f"No iCloud account with username or name { account_identifier } "
114- )
115- return icloud_account
107+ entry : IcloudConfigEntry
108+ for entry in hass .config_entries .async_loaded_entries (DOMAIN ):
109+ if entry .runtime_data .username == account_identifier :
110+ return entry .runtime_data
111+
112+ raise ValueError (f"No iCloud account with username or name { account_identifier } " )
116113
117114
118115@callback
0 commit comments