1 """Tado Connector a class to store the data as an object."""
3 from datetime
import datetime, timedelta
7 from PyTado.interface
import Tado
8 from requests
import RequestException
17 INSIDE_TEMPERATURE_MEASUREMENT,
19 SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED,
20 SIGNAL_TADO_UPDATE_RECEIVED,
29 _LOGGER = logging.getLogger(__name__)
33 """An object to store the Tado data."""
36 self, hass: HomeAssistant, username: str, password: str, fallback: str
38 """Initialize Tado Connector."""
47 self.
zoneszones: list[dict[Any, Any]] = []
48 self.
devicesdevices: list[dict[Any, Any]] = []
49 self.data: dict[str, dict] = {
59 """Return fallback flag to Smart Schedule."""
63 """Connect to Tado and fetch the zones."""
68 tado_home = self.
tadotado.get_me()[
"homes"][0]
70 self.
home_namehome_name = tado_home[
"name"]
73 """Return the Tado mobile devices."""
76 @Throttle(MIN_TIME_BETWEEN_UPDATES)
78 """Update the registered zones."""
85 """Update the mobile devices."""
89 _LOGGER.error(
"Unable to connect to Tado while updating mobile devices")
92 if not mobile_devices:
93 _LOGGER.debug(
"No linked mobile devices found for home ID %s", self.
home_idhome_id)
98 if isinstance(mobile_devices, dict)
and mobile_devices.get(
"errors"):
100 "Error for home ID %s while updating mobile devices: %s",
102 mobile_devices[
"errors"],
106 for mobile_device
in mobile_devices:
107 self.data[
"mobile_device"][mobile_device[
"id"]] = mobile_device
109 "Dispatching update to %s mobile device: %s",
116 SIGNAL_TADO_MOBILE_DEVICE_UPDATE_RECEIVED.format(self.
home_idhome_id),
120 """Update the device data from Tado."""
122 devices = self.
tadotado.get_devices()
124 _LOGGER.error(
"Unable to connect to Tado while updating devices")
128 _LOGGER.debug(
"No linked devices found for home ID %s", self.
home_idhome_id)
133 if isinstance(devices, dict)
and devices.get(
"errors"):
135 "Error for home ID %s while updating devices: %s",
141 for device
in devices:
142 device_short_serial_no = device[
"shortSerialNo"]
143 _LOGGER.debug(
"Updating device %s", device_short_serial_no)
146 INSIDE_TEMPERATURE_MEASUREMENT
147 in device[
"characteristics"][
"capabilities"]
150 device_short_serial_no, TEMP_OFFSET
154 "Unable to connect to Tado while updating device %s",
155 device_short_serial_no,
159 self.data[
"device"][device_short_serial_no] = device
162 "Dispatching update to %s device %s: %s",
164 device_short_serial_no,
169 SIGNAL_TADO_UPDATE_RECEIVED.format(
170 self.
home_idhome_id,
"device", device_short_serial_no
175 """Update the zone data from Tado."""
177 zone_states = self.
tadotado.get_zone_states()[
"zoneStates"]
179 _LOGGER.error(
"Unable to connect to Tado while updating zones")
182 for zone
in zone_states:
186 """Update the internal data from Tado."""
187 _LOGGER.debug(
"Updating zone %s", zone_id)
189 data = self.
tadotado.get_zone_state(zone_id)
191 _LOGGER.error(
"Unable to connect to Tado while updating zone %s", zone_id)
194 self.data[
"zone"][zone_id] = data
197 "Dispatching update to %s zone %s: %s",
204 SIGNAL_TADO_UPDATE_RECEIVED.format(self.
home_idhome_id,
"zone", zone_id),
208 """Update the home data from Tado."""
210 self.data[
"weather"] = self.
tadotado.get_weather()
211 self.data[
"geofence"] = self.
tadotado.get_home_state()
214 SIGNAL_TADO_UPDATE_RECEIVED.format(self.
home_idhome_id,
"home",
"data"),
218 "Unable to connect to Tado while updating weather and geofence data"
223 """Return the capabilities of the devices."""
227 """Return whether the Tado Home supports auto geofencing."""
231 """Reset the zone back to the default operation."""
237 presence=PRESET_HOME,
239 """Set the presence to home, away or auto."""
240 if presence == PRESET_AWAY:
241 self.
tadotado.set_away()
242 elif presence == PRESET_HOME:
243 self.
tadotado.set_home()
244 elif presence == PRESET_AUTO:
245 self.
tadotado.set_auto()
257 device_type="HEATING",
263 horizontal_swing=None,
265 """Set a zone overlay."""
268 "Set overlay for zone %s: overlay_mode=%s, temp=%s, duration=%s,"
269 " type=%s, mode=%s fan_speed=%s swing=%s fan_level=%s vertical_swing=%s horizontal_swing=%s"
296 vertical_swing=vertical_swing,
297 horizontal_swing=horizontal_swing,
300 except RequestException
as exc:
301 _LOGGER.error(
"Could not set zone overlay: %s", exc)
306 """Set a zone to off."""
309 zone_id, overlay_mode,
None,
None, device_type,
"OFF"
311 except RequestException
as exc:
312 _LOGGER.error(
"Could not set zone overlay: %s", exc)
317 """Set temperature offset of device."""
319 self.
tadotado.set_temp_offset(device_id, offset)
320 except RequestException
as exc:
321 _LOGGER.error(
"Could not set temperature offset: %s", exc)
324 """Send meter reading to Tado."""
325 dt: str = datetime.now().strftime(
"%Y-%m-%d")
326 if self.
tadotado
is None:
330 return self.
tadotado.set_eiq_meter_readings(date=dt, reading=reading)
331 except RequestException
as exc:
None __init__(self, HomeAssistant hass, str username, str password, str fallback)
dict[str, Any] set_meter_reading(self, int reading)
def get_mobile_devices(self)
def set_zone_off(self, zone_id, overlay_mode, device_type="HEATING")
def update_zone(self, zone_id)
def reset_zone_overlay(self, zone_id)
def set_presence(self, presence=PRESET_HOME)
def get_capabilities(self, zone_id)
def set_zone_overlay(self, zone_id=None, overlay_mode=None, temperature=None, duration=None, device_type="HEATING", mode=None, fan_speed=None, swing=None, fan_level=None, vertical_swing=None, horizontal_swing=None)
def get_auto_geofencing_supported(self)
def set_temperature_offset(self, device_id, offset)
None update_mobile_devices(self)
DeviceInfo get_device_info(str coordinates, str name)
None dispatcher_send(HomeAssistant hass, str signal, *Any args)