1 """The Fjäråskupan data update coordinator."""
3 from __future__
import annotations
5 from collections.abc
import AsyncIterator
6 from contextlib
import asynccontextmanager, contextmanager
7 from datetime
import timedelta
10 from fjaraskupan
import (
12 FjaraskupanConnectionError,
15 FjaraskupanWriteError,
20 BluetoothServiceInfoBleak,
21 async_address_present,
22 async_ble_device_from_address,
29 from .const
import DOMAIN
31 _LOGGER = logging.getLogger(__name__)
36 """Convert exception so home assistant translated ones."""
40 except FjaraskupanWriteError
as exception:
42 translation_domain=DOMAIN, translation_key=
"write_error"
44 except FjaraskupanReadError
as exception:
46 translation_domain=DOMAIN, translation_key=
"read_error"
48 except FjaraskupanConnectionError
as exception:
50 translation_domain=DOMAIN, translation_key=
"connection_error"
52 except FjaraskupanError
as exception:
54 translation_domain=DOMAIN,
55 translation_key=
"unexpected_error",
56 translation_placeholders={
"msg":
str(exception)},
61 """Exception to indicate that we cannot connect to device."""
65 """Update coordinator for each device."""
68 self, hass: HomeAssistant, device: Device, device_info: DeviceInfo
70 """Initialize the coordinator."""
76 hass, _LOGGER, name=
"Fjäråskupan", update_interval=
timedelta(seconds=120)
81 log_failures: bool =
True,
82 raise_on_auth_failed: bool =
False,
83 scheduled: bool =
False,
84 raise_on_entry_error: bool =
False,
88 log_failures=log_failures,
89 raise_on_auth_failed=raise_on_auth_failed,
91 raise_on_entry_error=raise_on_entry_error,
95 """Handle an explicit update request."""
98 return self.
devicedevice.state
100 "No data received within schedule, and device is no longer present"
105 self.
hasshass, self.
devicedevice.address,
True
111 async
with self.
devicedevice.connect(ble_device)
as device:
112 await device.update()
114 return self.
devicedevice.state
117 """Handle a new announcement of data."""
123 """Provide an up-to-date device for use during connections."""
126 self.
hasshass, self.
devicedevice.address,
True
132 async
with self.
devicedevice.connect(ble_device)
as device:
None _async_refresh(self, bool log_failures=True, bool raise_on_auth_failed=False, bool scheduled=False, bool raise_on_entry_error=False)
AsyncIterator[Device] async_connect_and_update(self)
None detection_callback(self, BluetoothServiceInfoBleak service_info)
State _async_update_data(self)
None __init__(self, HomeAssistant hass, Device device, DeviceInfo device_info)
None async_set_updated_data(self, _DataT data)
BLEDevice|None async_ble_device_from_address(HomeAssistant hass, str address, bool connectable=True)
bool async_address_present(HomeAssistant hass, str address, bool connectable=True)
def exception_converter()