1 """Support for Vodafone Station."""
3 from dataclasses
import dataclass
4 from datetime
import datetime, timedelta
7 from aiovodafone
import VodafoneStationDevice, VodafoneStationSercommApi, exceptions
16 from .const
import _LOGGER, DOMAIN
18 CONSIDER_HOME_SECONDS = DEFAULT_CONSIDER_HOME.total_seconds()
21 @dataclass(slots=True)
23 """Representation of a device connected to the Vodafone Station."""
25 device: VodafoneStationDevice
26 update_time: datetime |
None
30 @dataclass(slots=True)
32 """Update coordinator data type."""
34 devices: dict[str, VodafoneStationDeviceInfo]
35 sensors: dict[str, Any]
39 """Queries router running Vodafone Station firmware."""
47 config_entry_unique_id: str |
None,
49 """Initialize the scanner."""
52 self.
apiapi = VodafoneStationSercommApi(host, username, password)
55 self.
_id_id = config_entry_unique_id
60 name=f
"{DOMAIN}-{host}-coordinator",
65 self, device: VodafoneStationDevice, utc_point_in_time: datetime
66 ) -> tuple[datetime |
None, bool]:
67 """Return update time and consider home.
69 If the device is connected, return the current time and True.
71 If the device is not connected, return the last update time and
72 whether the device was considered home at that time.
74 If the device is not connected and there is no last update time,
75 return None and False.
78 return utc_point_in_time,
True
81 (data := self.
datadata)
82 and (stored_device := data.devices.get(device.mac))
83 and (update_time := stored_device.update_time)
88 (utc_point_in_time - update_time).total_seconds()
89 < CONSIDER_HOME_SECONDS
96 """Update router data."""
97 _LOGGER.debug(
"Polling Vodafone Station host: %s", self.
_host_host)
100 await self.
apiapi.login()
101 raw_data_devices = await self.
apiapi.get_devices_data()
102 data_sensors = await self.
apiapi.get_sensor_data()
103 await self.
apiapi.logout()
104 except exceptions.CannotAuthenticate
as err:
105 raise ConfigEntryAuthFailed
from err
107 exceptions.CannotConnect,
108 exceptions.AlreadyLogged,
109 exceptions.GenericLoginError,
111 raise UpdateFailed(f
"Error fetching data: {err!r}")
from err
112 except (ConfigEntryAuthFailed, UpdateFailed):
113 await self.
apiapi.close()
116 utc_point_in_time = dt_util.utcnow()
121 dev_info, utc_point_in_time
124 for dev_info
in (raw_data_devices).values()
130 """Event specific per Vodafone Station entry to signal new device."""
131 return f
"{DOMAIN}-device-new-{self._id}"
135 """Device serial number."""
136 return self.
datadata.sensors[
"sys_serial_number"]
140 """Set device info."""
141 sensors_data = self.
datadata.sensors
143 configuration_url=self.
apiapi.base_url,
145 name=f
"Vodafone Station ({self.serial_number})",
146 manufacturer=
"Vodafone",
147 model=sensors_data.get(
"sys_model_name"),
148 hw_version=sensors_data[
"sys_hardware_version"],
149 sw_version=sensors_data[
"sys_firmware_version"],
tuple[datetime|None, bool] _calculate_update_time_and_consider_home(self, VodafoneStationDevice device, datetime utc_point_in_time)
UpdateCoordinatorDataType _async_update_data(self)
str signal_device_new(self)
None __init__(self, HomeAssistant hass, str host, str username, str password, str|None config_entry_unique_id)
DeviceInfo device_info(self)