Convert Anova to cloud push (#109508)
* current state * finish refactor * Apply suggestions from code review Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * address MR comments * Change to sensor setup to be listener based. * remove assert for websocket handler * added assert for log * remove mixin * fix linting * fix merge change * Add clarifying comment * Apply suggestions from code review Co-authored-by: Erik Montnemery <erik@montnemery.com> * Address MR comments * bump version and fix typing check --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
parent
de62e205dd
commit
22bc11f397
17 changed files with 387 additions and 304 deletions
|
@ -1,14 +1,13 @@
|
|||
"""Support for Anova Coordinators."""
|
||||
|
||||
from asyncio import timeout
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
from anova_wifi import AnovaOffline, AnovaPrecisionCooker, APCUpdate
|
||||
from anova_wifi import APCUpdate, APCWifiDevice
|
||||
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
|
@ -18,37 +17,24 @@ _LOGGER = logging.getLogger(__name__)
|
|||
class AnovaCoordinator(DataUpdateCoordinator[APCUpdate]):
|
||||
"""Anova custom coordinator."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
anova_device: AnovaPrecisionCooker,
|
||||
) -> None:
|
||||
config_entry: ConfigEntry
|
||||
|
||||
def __init__(self, hass: HomeAssistant, anova_device: APCWifiDevice) -> 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
|
||||
self.device_unique_id = anova_device.device_key
|
||||
self.device_unique_id = anova_device.cooker_id
|
||||
self.anova_device = anova_device
|
||||
self.anova_device.set_update_listener(self.async_set_updated_data)
|
||||
self.device_info: DeviceInfo | None = None
|
||||
|
||||
@callback
|
||||
def async_setup(self, firmware_version: str) -> None:
|
||||
"""Set the firmware version info."""
|
||||
self.device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, self.device_unique_id)},
|
||||
name="Anova Precision Cooker",
|
||||
manufacturer="Anova",
|
||||
model="Precision Cooker",
|
||||
sw_version=firmware_version,
|
||||
)
|
||||
|
||||
async def _async_update_data(self) -> APCUpdate:
|
||||
try:
|
||||
async with timeout(5):
|
||||
return await self.anova_device.update()
|
||||
except AnovaOffline as err:
|
||||
raise UpdateFailed(err) from err
|
||||
self.sensor_data_set: bool = False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue