From 7b5d26d3faf537ba616894ec9d7a070afbb67a31 Mon Sep 17 00:00:00 2001 From: Luke Date: Mon, 1 May 2023 05:15:29 -0400 Subject: [PATCH] Bump anova version (#92206) Co-authored-by: Franck Nijhof --- homeassistant/components/anova/__init__.py | 12 +--- homeassistant/components/anova/coordinator.py | 8 +-- homeassistant/components/anova/manifest.json | 2 +- homeassistant/components/anova/sensor.py | 64 +++++++++++++------ requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/anova/__init__.py | 32 ++-------- 7 files changed, 61 insertions(+), 61 deletions(-) diff --git a/homeassistant/components/anova/__init__.py b/homeassistant/components/anova/__init__.py index 7810e00ded0..2fee8a6beeb 100644 --- a/homeassistant/components/anova/__init__.py +++ b/homeassistant/components/anova/__init__.py @@ -3,13 +3,7 @@ from __future__ import annotations import logging -from anova_wifi import ( - AnovaApi, - AnovaPrecisionCooker, - AnovaPrecisionCookerSensor, - InvalidLogin, - NoDevicesFound, -) +from anova_wifi import AnovaApi, AnovaPrecisionCooker, InvalidLogin, NoDevicesFound from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, Platform @@ -67,9 +61,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: coordinators = [AnovaCoordinator(hass, device) for device in devices] for coordinator in coordinators: await coordinator.async_config_entry_first_refresh() - firmware_version = coordinator.data["sensors"][ - AnovaPrecisionCookerSensor.FIRMWARE_VERSION - ] + firmware_version = coordinator.data.sensor.firmware_version coordinator.async_setup(str(firmware_version)) hass.data.setdefault(DOMAIN, {})[entry.entry_id] = AnovaData( api_jwt=api.jwt, precision_cookers=devices, coordinators=coordinators diff --git a/homeassistant/components/anova/coordinator.py b/homeassistant/components/anova/coordinator.py index cd4eab9c2e5..2e5505a9fdd 100644 --- a/homeassistant/components/anova/coordinator.py +++ b/homeassistant/components/anova/coordinator.py @@ -2,7 +2,7 @@ from datetime import timedelta import logging -from anova_wifi import AnovaOffline, AnovaPrecisionCooker +from anova_wifi import AnovaOffline, AnovaPrecisionCooker, APCUpdate import async_timeout from homeassistant.core import HomeAssistant, callback @@ -14,11 +14,9 @@ from .const import DOMAIN _LOGGER = logging.getLogger(__name__) -class AnovaCoordinator(DataUpdateCoordinator): +class AnovaCoordinator(DataUpdateCoordinator[APCUpdate]): """Anova custom coordinator.""" - data: dict[str, dict[str, str | int | float]] - def __init__( self, hass: HomeAssistant, @@ -47,7 +45,7 @@ class AnovaCoordinator(DataUpdateCoordinator): sw_version=firmware_version, ) - async def _async_update_data(self) -> dict[str, dict[str, str | int | float]]: + async def _async_update_data(self) -> APCUpdate: try: async with async_timeout.timeout(5): return await self.anova_device.update() diff --git a/homeassistant/components/anova/manifest.json b/homeassistant/components/anova/manifest.json index d307a9314f9..39608011a03 100644 --- a/homeassistant/components/anova/manifest.json +++ b/homeassistant/components/anova/manifest.json @@ -6,5 +6,5 @@ "documentation": "https://www.home-assistant.io/integrations/anova", "iot_class": "cloud_polling", "loggers": ["anova_wifi"], - "requirements": ["anova-wifi==0.8.0"] + "requirements": ["anova-wifi==0.9.0"] } diff --git a/homeassistant/components/anova/sensor.py b/homeassistant/components/anova/sensor.py index a5ea3ee2fd8..6336aa61e1c 100644 --- a/homeassistant/components/anova/sensor.py +++ b/homeassistant/components/anova/sensor.py @@ -1,7 +1,10 @@ """Support for Anova Sensors.""" from __future__ import annotations -from anova_wifi import AnovaPrecisionCookerSensor +from collections.abc import Callable +from dataclasses import dataclass + +from anova_wifi import APCUpdateSensor from homeassistant import config_entries from homeassistant.components.sensor import ( @@ -19,57 +22,80 @@ from .const import DOMAIN from .entity import AnovaDescriptionEntity from .models import AnovaData + +@dataclass +class AnovaSensorEntityDescriptionMixin: + """Describes the mixin variables for anova sensors.""" + + value_fn: Callable[[APCUpdateSensor], float | int | str] + + +@dataclass +class AnovaSensorEntityDescription( + SensorEntityDescription, AnovaSensorEntityDescriptionMixin +): + """Describes a Anova sensor.""" + + SENSOR_DESCRIPTIONS: list[SensorEntityDescription] = [ - SensorEntityDescription( - key=AnovaPrecisionCookerSensor.COOK_TIME, + AnovaSensorEntityDescription( + key="cook_time", state_class=SensorStateClass.TOTAL_INCREASING, native_unit_of_measurement=UnitOfTime.SECONDS, icon="mdi:clock-outline", translation_key="cook_time", + device_class=SensorDeviceClass.DURATION, + value_fn=lambda data: data.cook_time, ), - SensorEntityDescription( - key=AnovaPrecisionCookerSensor.STATE, translation_key="state" + AnovaSensorEntityDescription( + key="state", translation_key="state", value_fn=lambda data: data.state ), - SensorEntityDescription( - key=AnovaPrecisionCookerSensor.MODE, translation_key="mode" + AnovaSensorEntityDescription( + key="mode", translation_key="mode", value_fn=lambda data: data.mode ), - SensorEntityDescription( - key=AnovaPrecisionCookerSensor.TARGET_TEMPERATURE, + AnovaSensorEntityDescription( + key="target_temperature", native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, icon="mdi:thermometer", translation_key="target_temperature", + value_fn=lambda data: data.target_temperature, ), - SensorEntityDescription( - key=AnovaPrecisionCookerSensor.COOK_TIME_REMAINING, + AnovaSensorEntityDescription( + key="cook_time_remaining", native_unit_of_measurement=UnitOfTime.SECONDS, icon="mdi:clock-outline", translation_key="cook_time_remaining", + device_class=SensorDeviceClass.DURATION, + value_fn=lambda data: data.cook_time_remaining, ), - SensorEntityDescription( - key=AnovaPrecisionCookerSensor.HEATER_TEMPERATURE, + AnovaSensorEntityDescription( + key="heater_temperature", native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, icon="mdi:thermometer", translation_key="heater_temperature", + value_fn=lambda data: data.heater_temperature, ), - SensorEntityDescription( - key=AnovaPrecisionCookerSensor.TRIAC_TEMPERATURE, + AnovaSensorEntityDescription( + key="triac_temperature", native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, icon="mdi:thermometer", translation_key="triac_temperature", + value_fn=lambda data: data.triac_temperature, ), - SensorEntityDescription( - key=AnovaPrecisionCookerSensor.WATER_TEMPERATURE, + AnovaSensorEntityDescription( + key="water_temperature", native_unit_of_measurement=UnitOfTemperature.CELSIUS, device_class=SensorDeviceClass.TEMPERATURE, state_class=SensorStateClass.MEASUREMENT, icon="mdi:thermometer", translation_key="water_temperature", + value_fn=lambda data: data.water_temperature, ), ] @@ -91,7 +117,9 @@ async def async_setup_entry( class AnovaSensor(AnovaDescriptionEntity, SensorEntity): """A sensor using Anova coordinator.""" + entity_description: AnovaSensorEntityDescription + @property def native_value(self) -> StateType: """Return the state.""" - return self.coordinator.data["sensors"][self.entity_description.key] + return self.entity_description.value_fn(self.coordinator.data.sensor) diff --git a/requirements_all.txt b/requirements_all.txt index 3d2a33c7c96..be3c22bb762 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -339,7 +339,7 @@ androidtvremote2==0.0.7 anel_pwrctrl-homeassistant==0.0.1.dev2 # homeassistant.components.anova -anova-wifi==0.8.0 +anova-wifi==0.9.0 # homeassistant.components.anthemav anthemav==1.4.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index b90e6ff1f42..fd56a9e8f40 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -311,7 +311,7 @@ androidtv[async]==0.0.70 androidtvremote2==0.0.7 # homeassistant.components.anova -anova-wifi==0.8.0 +anova-wifi==0.9.0 # homeassistant.components.anthemav anthemav==1.4.1 diff --git a/tests/components/anova/__init__.py b/tests/components/anova/__init__.py index e0e31c84b7b..5bcb84cb974 100644 --- a/tests/components/anova/__init__.py +++ b/tests/components/anova/__init__.py @@ -3,11 +3,7 @@ from __future__ import annotations from unittest.mock import patch -from anova_wifi import ( - AnovaPrecisionCooker, - AnovaPrecisionCookerBinarySensor, - AnovaPrecisionCookerSensor, -) +from anova_wifi import AnovaPrecisionCooker, APCUpdate, APCUpdateBinary, APCUpdateSensor from homeassistant.components.anova.const import DOMAIN from homeassistant.config_entries import ConfigEntry @@ -20,26 +16,12 @@ DEVICE_UNIQUE_ID = "abc123def" CONF_INPUT = {CONF_USERNAME: "sample@gmail.com", CONF_PASSWORD: "sample"} -ONLINE_UPDATE = { - "sensors": { - AnovaPrecisionCookerSensor.COOK_TIME: 0, - AnovaPrecisionCookerSensor.MODE: "Low water", - AnovaPrecisionCookerSensor.STATE: "No state", - AnovaPrecisionCookerSensor.TARGET_TEMPERATURE: 23.33, - AnovaPrecisionCookerSensor.COOK_TIME_REMAINING: 0, - AnovaPrecisionCookerSensor.FIRMWARE_VERSION: "2.2.0", - AnovaPrecisionCookerSensor.HEATER_TEMPERATURE: 20.87, - AnovaPrecisionCookerSensor.TRIAC_TEMPERATURE: 21.79, - AnovaPrecisionCookerSensor.WATER_TEMPERATURE: 21.33, - }, - "binary_sensors": { - AnovaPrecisionCookerBinarySensor.COOKING: False, - AnovaPrecisionCookerBinarySensor.DEVICE_SAFE: True, - AnovaPrecisionCookerBinarySensor.WATER_LEAK: False, - AnovaPrecisionCookerBinarySensor.WATER_LEVEL_CRITICAL: True, - AnovaPrecisionCookerBinarySensor.WATER_TEMP_TOO_HIGH: False, - }, -} +ONLINE_UPDATE = APCUpdate( + sensor=APCUpdateSensor( + 0, "Low water", "No state", 23.33, 0, "2.2.0", 20.87, 21.79, 21.33 + ), + binary_sensor=APCUpdateBinary(False, False, False, True, False, True, False), +) def create_entry(hass: HomeAssistant, device_id: str = DEVICE_UNIQUE_ID) -> ConfigEntry: