1 """Provides the DataUpdateCoordinator."""
3 from __future__
import annotations
5 from datetime
import timedelta
7 from automower_ble.mower
import Mower
8 from bleak
import BleakError
9 from bleak_retry_connector
import close_stale_connections_by_address
15 from .const
import DOMAIN, LOGGER
21 """Class to manage fetching data."""
31 """Initialize global data updater."""
36 update_interval=SCAN_INTERVAL,
44 """Shutdown coordinator and any connection."""
45 LOGGER.debug(
"Shutdown")
48 await self.
mowermower.disconnect()
51 LOGGER.debug(
"Trying to reconnect")
52 await close_stale_connections_by_address(self.
addressaddress)
54 device = bluetooth.async_ble_device_from_address(
55 self.
hasshass, self.
addressaddress, connectable=
True
59 if not await self.
mowermower.connect(device):
61 except BleakError
as err:
65 """Poll the device."""
66 LOGGER.debug(
"Polling device")
68 data: dict[str, bytes] = {}
73 except BleakError
as err:
77 data[
"battery_level"] = await self.
mowermower.battery_level()
78 LOGGER.debug(
"battery_level" +
str(data[
"battery_level"]))
79 if data[
"battery_level"]
is None:
83 data[
"activity"] = await self.
mowermower.mower_activity()
84 LOGGER.debug(
"activity:" +
str(data[
"activity"]))
85 if data[
"activity"]
is None:
89 data[
"state"] = await self.
mowermower.mower_state()
90 LOGGER.debug(
"state:" +
str(data[
"state"]))
91 if data[
"state"]
is None:
95 except BleakError
as err:
96 LOGGER.error(
"Error getting data from device")
98 raise UpdateFailed(
"Error getting data from device")
from err
dict[str, bytes] _async_update_data(self)
None __init__(self, HomeAssistant hass, Mower mower, str address, str channel_id, str model)
def _async_find_device(self)
None async_shutdown(self)