2023-04-22 23:05:14 +00:00
|
|
|
"""Support for Anova Coordinators."""
|
2024-03-08 13:51:32 +00:00
|
|
|
|
2023-08-15 08:29:28 +00:00
|
|
|
from asyncio import timeout
|
2023-04-22 23:05:14 +00:00
|
|
|
from datetime import timedelta
|
|
|
|
import logging
|
|
|
|
|
2023-05-01 09:15:29 +00:00
|
|
|
from anova_wifi import AnovaOffline, AnovaPrecisionCooker, APCUpdate
|
2023-04-22 23:05:14 +00:00
|
|
|
|
|
|
|
from homeassistant.core import HomeAssistant, callback
|
2023-08-11 02:04:26 +00:00
|
|
|
from homeassistant.helpers.device_registry import DeviceInfo
|
2023-04-22 23:05:14 +00:00
|
|
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
|
|
|
|
|
|
|
from .const import DOMAIN
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2023-05-01 09:15:29 +00:00
|
|
|
class AnovaCoordinator(DataUpdateCoordinator[APCUpdate]):
|
2023-04-22 23:05:14 +00:00
|
|
|
"""Anova custom coordinator."""
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
hass: HomeAssistant,
|
|
|
|
anova_device: AnovaPrecisionCooker,
|
|
|
|
) -> None:
|
|
|
|
"""Set up Anova Coordinator."""
|
|
|
|
super().__init__(
|
|
|
|
hass,
|
|
|
|
name="Anova Precision Cooker",
|
|
|
|
logger=_LOGGER,
|
|
|
|
update_interval=timedelta(seconds=30),
|
|
|
|
)
|
|
|
|
assert self.config_entry is not None
|
2023-08-27 18:10:08 +00:00
|
|
|
self.device_unique_id = anova_device.device_key
|
2023-04-22 23:05:14 +00:00
|
|
|
self.anova_device = anova_device
|
|
|
|
self.device_info: DeviceInfo | None = None
|
|
|
|
|
|
|
|
@callback
|
|
|
|
def async_setup(self, firmware_version: str) -> None:
|
|
|
|
"""Set the firmware version info."""
|
|
|
|
self.device_info = DeviceInfo(
|
2023-08-27 18:10:08 +00:00
|
|
|
identifiers={(DOMAIN, self.device_unique_id)},
|
2023-04-22 23:05:14 +00:00
|
|
|
name="Anova Precision Cooker",
|
|
|
|
manufacturer="Anova",
|
|
|
|
model="Precision Cooker",
|
|
|
|
sw_version=firmware_version,
|
|
|
|
)
|
|
|
|
|
2023-05-01 09:15:29 +00:00
|
|
|
async def _async_update_data(self) -> APCUpdate:
|
2023-04-22 23:05:14 +00:00
|
|
|
try:
|
2023-08-15 08:29:28 +00:00
|
|
|
async with timeout(5):
|
2023-04-22 23:05:14 +00:00
|
|
|
return await self.anova_device.update()
|
|
|
|
except AnovaOffline as err:
|
|
|
|
raise UpdateFailed(err) from err
|