1 """Support for tracking for iCloud devices."""
3 from __future__
import annotations
14 from .account
import IcloudAccount, IcloudDevice
16 DEVICE_LOCATION_HORIZONTAL_ACCURACY,
17 DEVICE_LOCATION_LATITUDE,
18 DEVICE_LOCATION_LONGITUDE,
24 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
26 """Set up device tracker for iCloud component."""
27 account: IcloudAccount = hass.data[DOMAIN][entry.unique_id]
32 """Update the values of the account."""
35 account.listeners.append(
43 def add_entities(account: IcloudAccount, async_add_entities, tracked):
44 """Add new tracker entities from the account."""
47 for dev_id, device
in account.devices.items():
48 if dev_id
in tracked
or device.location
is None:
58 """Represent a tracked device."""
60 _attr_has_entity_name =
True
63 def __init__(self, account: IcloudAccount, device: IcloudDevice) ->
None:
64 """Set up the iCloud tracker entity."""
72 """Return the location accuracy of the device."""
73 return self.
_device_device.location[DEVICE_LOCATION_HORIZONTAL_ACCURACY]
77 """Return latitude value of the device."""
78 return self.
_device_device.location[DEVICE_LOCATION_LATITUDE]
82 """Return longitude value of the device."""
83 return self.
_device_device.location[DEVICE_LOCATION_LONGITUDE]
87 """Return the battery level of the device."""
88 return self.
_device_device.battery_level
92 """Return the icon."""
97 """Return the device state attributes."""
98 return self.
_device_device.extra_state_attributes
102 """Return the device information."""
104 configuration_url=
"https://icloud.com/",
105 identifiers={(DOMAIN, self.
_device_device.unique_id)},
106 manufacturer=
"Apple",
107 model=self.
_device_device.device_model,
112 """Register state update callback."""
114 self.hass, self.
_account_account.signal_device_update, self.async_write_ha_state
118 """Clean up after entity before removal."""
124 """Return an icon for the device."""
126 "iPad":
"mdi:tablet",
127 "iPhone":
"mdi:cellphone",
129 "iMac":
"mdi:monitor",
130 "MacBookPro":
"mdi:laptop",
133 return switcher.get(icloud_device.device_class,
"mdi:cellphone-link")
None async_added_to_hass(self)
DeviceInfo device_info(self)
dict[str, Any] extra_state_attributes(self)
def location_accuracy(self)
int|None battery_level(self)
None async_will_remove_from_hass(self)
None __init__(self, IcloudAccount account, IcloudDevice device)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
def add_entities(IcloudAccount account, async_add_entities, tracked)
str icon_for_icloud_device(IcloudDevice icloud_device)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)