1 """Coordinator for Acaia integration."""
3 from __future__
import annotations
5 from datetime
import timedelta
8 from aioacaia.acaiascale
import AcaiaScale
9 from aioacaia.exceptions
import AcaiaDeviceNotFound, AcaiaError
16 from .const
import CONF_IS_NEW_STYLE_SCALE
20 _LOGGER = logging.getLogger(__name__)
22 type AcaiaConfigEntry = ConfigEntry[AcaiaCoordinator]
26 """Class to handle fetching data from the scale."""
28 config_entry: AcaiaConfigEntry
30 def __init__(self, hass: HomeAssistant, entry: AcaiaConfigEntry) ->
None:
31 """Initialize coordinator."""
35 name=
"acaia coordinator",
36 update_interval=SCAN_INTERVAL,
41 address_or_ble_device=entry.data[CONF_ADDRESS],
43 is_new_style_scale=entry.data[CONF_IS_NEW_STYLE_SCALE],
49 """Return the scale object."""
56 if self.
_scale_scale.connected:
61 await self.
_scale_scale.connect(setup_tasks=
False)
62 except (AcaiaDeviceNotFound, AcaiaError, TimeoutError)
as ex:
64 "Could not connect to scale: %s, Error: %s",
68 self.
_scale_scale.device_disconnected_handler(notify=
False)
72 if not self.
_scale_scale.heartbeat_task
or self.
_scale_scale.heartbeat_task.done():
73 self.
_scale_scale.heartbeat_task = self.
config_entryconfig_entry.async_create_background_task(
75 target=self.
_scale_scale.send_heartbeats(),
76 name=
"acaia_heartbeat_task",
79 if not self.
_scale_scale.process_queue_task
or self.
_scale_scale.process_queue_task.done():
80 self.
_scale_scale.process_queue_task = (
81 self.
config_entryconfig_entry.async_create_background_task(
83 target=self.
_scale_scale.process_queue(),
84 name=
"acaia_process_queue_task",
None __init__(self, HomeAssistant hass, AcaiaConfigEntry entry)
None _async_update_data(self)
None async_update_listeners(self)