1 """Support for Tado Smart device trackers."""
3 from __future__
import annotations
8 DOMAIN
as DEVICE_TRACKER_DOMAIN,
17 from .
import TadoConfigEntry
18 from .const
import DOMAIN, SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED
19 from .tado_connector
import TadoConnector
21 _LOGGER = logging.getLogger(__name__)
26 entry: TadoConfigEntry,
27 async_add_entities: AddEntitiesCallback,
29 """Set up the Tado device scannery entity."""
30 _LOGGER.debug(
"Setting up Tado device scanner entity")
31 tado = entry.runtime_data
36 entity_registry = er.async_get(hass)
37 for device_key
in tado.data[
"mobile_device"]:
38 if entity_id := entity_registry.async_get_entity_id(
39 DEVICE_TRACKER_DOMAIN, DOMAIN, device_key
41 entity_registry.async_update_entity(
42 entity_id, new_unique_id=
str(device_key)
47 """Update the values of the devices."""
52 entry.async_on_unload(
55 SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED.format(tado.home_id),
65 async_add_entities: AddEntitiesCallback,
68 """Add new tracker entities from Tado."""
69 _LOGGER.debug(
"Fetching Tado devices from API for (newly) tracked entities")
71 for device_key, device
in tado.data[
"mobile_device"].items():
72 if device_key
in tracked:
76 "Adding Tado device %s with deviceID %s", device[
"name"], device_key
79 tracked.add(device_key)
85 """A Tado Device Tracker entity."""
87 _attr_should_poll =
False
88 _attr_available =
False
96 """Initialize a Tado Device Tracker entity."""
106 """Update the Tado device."""
108 "Updating Tado mobile device: %s (ID: %s)",
112 device = self.
_tado_tado.data[
"mobile_device"][self.
_device_id_device_id]
116 "Tado device %s has geoTracking state %s",
118 device[
"settings"][
"geoTrackingEnabled"],
121 if device[
"settings"][
"geoTrackingEnabled"]
is False:
126 if device.get(
"location")
is not None and device[
"location"][
"atHome"]:
127 _LOGGER.debug(
"Tado device %s is at home", device[
"name"])
130 _LOGGER.debug(
"Tado device %s is not at home", device[
"name"])
134 """Update state on demand."""
136 self.async_write_ha_state()
139 """Register state update callback."""
140 _LOGGER.debug(
"Registering Tado device tracker entity")
141 self.async_on_remove(
144 SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED.format(self.
_tado_tado.home_id),
153 """Return the name of the device."""
158 """Return the state of the device."""
159 return STATE_HOME
if self.
_active_active
else STATE_NOT_HOME
None async_added_to_hass(self)
None __init__(self, str device_id, str device_name, TadoConnector tado)
None on_demand_update(self)
None update_devices(HomeAssistant hass, ConfigEntry config_entry, dict[int, Roller] api)
None async_setup_entry(HomeAssistant hass, TadoConfigEntry entry, AddEntitiesCallback async_add_entities)
None add_tracked_entities(HomeAssistant hass, TadoConnector tado, AddEntitiesCallback async_add_entities, set[str] tracked)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)