1 """Provides the DataUpdateCoordinator."""
3 from __future__
import annotations
5 from datetime
import timedelta
8 from gardena_bluetooth.client
import Client
9 from gardena_bluetooth.exceptions
import (
10 CharacteristicNoAccess,
11 GardenaBluetoothException,
13 from gardena_bluetooth.parse
import Characteristic, CharacteristicType
21 LOGGER = logging.getLogger(__name__)
25 """Raised if device can't be found."""
29 """Class to manage fetching data."""
34 logger: logging.Logger,
36 characteristics: set[str],
37 device_info: DeviceInfo,
40 """Initialize global data updater."""
44 name=
"Gardena Bluetooth Data Update Coordinator",
45 update_interval=SCAN_INTERVAL,
54 """Shutdown coordinator and any connection."""
56 await self.
clientclient.disconnect()
59 """Poll the device."""
61 uuid
for context
in self.
async_contextsasync_contexts()
for uuid
in context
66 data: dict[str, bytes] = {}
69 data[uuid] = await self.
clientclient.read_char_raw(uuid)
70 except CharacteristicNoAccess
as exception:
71 LOGGER.debug(
"Unable to get data for %s due to %s", uuid, exception)
72 except (GardenaBluetoothException, DeviceUnavailable)
as exception:
74 f
"Unable to update data for {uuid} due to {exception}"
79 self, char: Characteristic[CharacteristicType]
80 ) -> CharacteristicType |
None:
81 """Read cached characteristic."""
83 return char.decode(data)
87 self, char: Characteristic[CharacteristicType], value: CharacteristicType
89 """Write characteristic to device."""
91 await self.
clientclient.write_char(char, value)
92 except (GardenaBluetoothException, DeviceUnavailable)
as exception:
94 f
"Unable to write characteristic {char} dur to {exception}"
97 self.
datadatadata[char.uuid] = char.encode(value)
dict[str, bytes] _async_update_data(self)
CharacteristicType|None get_cached(self, Characteristic[CharacteristicType] char)
None __init__(self, HomeAssistant hass, logging.Logger logger, Client client, set[str] characteristics, DeviceInfo device_info, str address)
None write(self, Characteristic[CharacteristicType] char, CharacteristicType value)
None async_shutdown(self)
Generator[Any] async_contexts(self)
web.Response get(self, web.Request request, str config_key)