From b86c58b0eaa9b4f7ef5a2b2d6fad7576d397b0a0 Mon Sep 17 00:00:00 2001 From: mkmer Date: Tue, 10 Jan 2023 04:41:35 -0500 Subject: [PATCH] Bump whirlpool-sixth-sense to 0.18.1 (#85521) * Bump whirlpool to 0.18.1 Add HASS AIOsession Add unregister to remove_from_hass * remove session from WhirlpoolData class --- homeassistant/components/whirlpool/__init__.py | 16 +++++++++------- homeassistant/components/whirlpool/climate.py | 16 ++++++++++++++-- .../components/whirlpool/config_flow.py | 10 ++++++---- homeassistant/components/whirlpool/manifest.json | 2 +- homeassistant/components/whirlpool/sensor.py | 4 +++- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 7 files changed, 35 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/whirlpool/__init__.py b/homeassistant/components/whirlpool/__init__.py index 2f1e1fbe21e..42ffe7dd77e 100644 --- a/homeassistant/components/whirlpool/__init__.py +++ b/homeassistant/components/whirlpool/__init__.py @@ -3,7 +3,7 @@ import asyncio from dataclasses import dataclass import logging -import aiohttp +from aiohttp import ClientError from whirlpool.appliancesmanager import AppliancesManager from whirlpool.auth import Auth from whirlpool.backendselector import BackendSelector @@ -12,6 +12,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_PASSWORD, CONF_REGION, CONF_USERNAME, Platform from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady +from homeassistant.helpers.aiohttp_client import async_get_clientsession from .const import CONF_REGIONS_MAP, DOMAIN from .util import get_brand_for_region @@ -25,28 +26,29 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Whirlpool Sixth Sense from a config entry.""" hass.data.setdefault(DOMAIN, {}) + session = async_get_clientsession(hass) region = CONF_REGIONS_MAP[entry.data.get(CONF_REGION, "EU")] brand = get_brand_for_region(region) backend_selector = BackendSelector(brand, region) - auth = Auth(backend_selector, entry.data[CONF_USERNAME], entry.data[CONF_PASSWORD]) + auth = Auth( + backend_selector, entry.data[CONF_USERNAME], entry.data[CONF_PASSWORD], session + ) try: await auth.do_auth(store=False) - except (aiohttp.ClientError, asyncio.TimeoutError) as ex: + except (ClientError, asyncio.TimeoutError) as ex: raise ConfigEntryNotReady("Cannot connect") from ex if not auth.is_access_token_valid(): _LOGGER.error("Authentication failed") raise ConfigEntryAuthFailed("Incorrect Password") - appliances_manager = AppliancesManager(backend_selector, auth) + appliances_manager = AppliancesManager(backend_selector, auth, session) if not await appliances_manager.fetch_appliances(): _LOGGER.error("Cannot fetch appliances") return False hass.data[DOMAIN][entry.entry_id] = WhirlpoolData( - appliances_manager, - auth, - backend_selector, + appliances_manager, auth, backend_selector ) await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) diff --git a/homeassistant/components/whirlpool/climate.py b/homeassistant/components/whirlpool/climate.py index 75c8c272bcc..1c6f770c886 100644 --- a/homeassistant/components/whirlpool/climate.py +++ b/homeassistant/components/whirlpool/climate.py @@ -4,6 +4,7 @@ from __future__ import annotations import logging from typing import Any +from aiohttp import ClientSession from whirlpool.aircon import Aircon, FanSpeed as AirconFanSpeed, Mode as AirconMode from whirlpool.auth import Auth from whirlpool.backendselector import BackendSelector @@ -24,6 +25,7 @@ from homeassistant.components.climate import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant +from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.entity import DeviceInfo, generate_entity_id from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -79,6 +81,7 @@ async def async_setup_entry( ac_data["NAME"], whirlpool_data.backend_selector, whirlpool_data.auth, + async_get_clientsession(hass), ) for ac_data in whirlpool_data.appliances_manager.aircons ] @@ -103,9 +106,17 @@ class AirConEntity(ClimateEntity): _attr_target_temperature_step = SUPPORTED_TARGET_TEMPERATURE_STEP _attr_temperature_unit = UnitOfTemperature.CELSIUS - def __init__(self, hass, said, name, backend_selector: BackendSelector, auth: Auth): + def __init__( + self, + hass, + said, + name, + backend_selector: BackendSelector, + auth: Auth, + session: ClientSession, + ): """Initialize the entity.""" - self._aircon = Aircon(backend_selector, auth, said) + self._aircon = Aircon(backend_selector, auth, said, session) self.entity_id = generate_entity_id(ENTITY_ID_FORMAT, said, hass=hass) self._attr_unique_id = said @@ -123,6 +134,7 @@ class AirConEntity(ClimateEntity): async def async_will_remove_from_hass(self) -> None: """Close Whrilpool Appliance sockets before removing.""" + self._aircon.unregister_attr_callback(self.async_write_ha_state) await self._aircon.disconnect() @property diff --git a/homeassistant/components/whirlpool/config_flow.py b/homeassistant/components/whirlpool/config_flow.py index 17ace442cac..fbbb670b6da 100644 --- a/homeassistant/components/whirlpool/config_flow.py +++ b/homeassistant/components/whirlpool/config_flow.py @@ -6,7 +6,7 @@ from collections.abc import Mapping import logging from typing import Any -import aiohttp +from aiohttp import ClientError import voluptuous as vol from whirlpool.appliancesmanager import AppliancesManager from whirlpool.auth import Auth @@ -15,6 +15,7 @@ from whirlpool.backendselector import BackendSelector from homeassistant import config_entries, core, exceptions from homeassistant.const import CONF_PASSWORD, CONF_REGION, CONF_USERNAME from homeassistant.data_entry_flow import FlowResult +from homeassistant.helpers.aiohttp_client import async_get_clientsession from .const import CONF_REGIONS_MAP, DOMAIN from .util import get_brand_for_region @@ -40,19 +41,20 @@ async def validate_input( Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user. """ + session = async_get_clientsession(hass) region = CONF_REGIONS_MAP[data[CONF_REGION]] brand = get_brand_for_region(region) backend_selector = BackendSelector(brand, region) - auth = Auth(backend_selector, data[CONF_USERNAME], data[CONF_PASSWORD]) + auth = Auth(backend_selector, data[CONF_USERNAME], data[CONF_PASSWORD], session) try: await auth.do_auth() - except (asyncio.TimeoutError, aiohttp.ClientError) as exc: + except (asyncio.TimeoutError, ClientError) as exc: raise CannotConnect from exc if not auth.is_access_token_valid(): raise InvalidAuth - appliances_manager = AppliancesManager(backend_selector, auth) + appliances_manager = AppliancesManager(backend_selector, auth, session) await appliances_manager.fetch_appliances() if appliances_manager.aircons is None and appliances_manager.washer_dryers is None: raise NoAppliances diff --git a/homeassistant/components/whirlpool/manifest.json b/homeassistant/components/whirlpool/manifest.json index 13a1107c23e..03506658c9c 100644 --- a/homeassistant/components/whirlpool/manifest.json +++ b/homeassistant/components/whirlpool/manifest.json @@ -3,7 +3,7 @@ "name": "Whirlpool Appliances", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/whirlpool", - "requirements": ["whirlpool-sixth-sense==0.18.0"], + "requirements": ["whirlpool-sixth-sense==0.18.1"], "codeowners": ["@abmantis", "@mkmer"], "iot_class": "cloud_push", "loggers": ["whirlpool"], diff --git a/homeassistant/components/whirlpool/sensor.py b/homeassistant/components/whirlpool/sensor.py index ee2adb55a0f..f88d39e3004 100644 --- a/homeassistant/components/whirlpool/sensor.py +++ b/homeassistant/components/whirlpool/sensor.py @@ -16,6 +16,7 @@ from homeassistant.components.sensor import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType @@ -148,6 +149,7 @@ async def async_setup_entry( whirlpool_data.backend_selector, whirlpool_data.auth, appliance["SAID"], + async_get_clientsession(hass), ) await _wd.connect() @@ -211,7 +213,7 @@ class WasherDryerClass(SensorEntity): async def async_will_remove_from_hass(self) -> None: """Close Whrilpool Appliance sockets before removing.""" - await self._wd.disconnect() + self._wd.unregister_attr_callback(self.async_write_ha_state) @property def available(self) -> bool: diff --git a/requirements_all.txt b/requirements_all.txt index 295e489ea6a..09b428ea642 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2592,7 +2592,7 @@ waterfurnace==1.1.0 webexteamssdk==1.1.1 # homeassistant.components.whirlpool -whirlpool-sixth-sense==0.18.0 +whirlpool-sixth-sense==0.18.1 # homeassistant.components.whois whois==0.9.16 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index bfe079f2b64..b6ed778f33d 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1820,7 +1820,7 @@ wallbox==0.4.12 watchdog==2.2.1 # homeassistant.components.whirlpool -whirlpool-sixth-sense==0.18.0 +whirlpool-sixth-sense==0.18.1 # homeassistant.components.whois whois==0.9.16