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
This commit is contained in:
mkmer 2023-01-10 04:41:35 -05:00 committed by GitHub
parent bba9ad3243
commit b86c58b0ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 17 deletions

View File

@ -3,7 +3,7 @@ import asyncio
from dataclasses import dataclass from dataclasses import dataclass
import logging import logging
import aiohttp from aiohttp import ClientError
from whirlpool.appliancesmanager import AppliancesManager from whirlpool.appliancesmanager import AppliancesManager
from whirlpool.auth import Auth from whirlpool.auth import Auth
from whirlpool.backendselector import BackendSelector 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.const import CONF_PASSWORD, CONF_REGION, CONF_USERNAME, Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import CONF_REGIONS_MAP, DOMAIN from .const import CONF_REGIONS_MAP, DOMAIN
from .util import get_brand_for_region 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.""" """Set up Whirlpool Sixth Sense from a config entry."""
hass.data.setdefault(DOMAIN, {}) hass.data.setdefault(DOMAIN, {})
session = async_get_clientsession(hass)
region = CONF_REGIONS_MAP[entry.data.get(CONF_REGION, "EU")] region = CONF_REGIONS_MAP[entry.data.get(CONF_REGION, "EU")]
brand = get_brand_for_region(region) brand = get_brand_for_region(region)
backend_selector = BackendSelector(brand, 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: try:
await auth.do_auth(store=False) 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 raise ConfigEntryNotReady("Cannot connect") from ex
if not auth.is_access_token_valid(): if not auth.is_access_token_valid():
_LOGGER.error("Authentication failed") _LOGGER.error("Authentication failed")
raise ConfigEntryAuthFailed("Incorrect Password") raise ConfigEntryAuthFailed("Incorrect Password")
appliances_manager = AppliancesManager(backend_selector, auth) appliances_manager = AppliancesManager(backend_selector, auth, session)
if not await appliances_manager.fetch_appliances(): if not await appliances_manager.fetch_appliances():
_LOGGER.error("Cannot fetch appliances") _LOGGER.error("Cannot fetch appliances")
return False return False
hass.data[DOMAIN][entry.entry_id] = WhirlpoolData( hass.data[DOMAIN][entry.entry_id] = WhirlpoolData(
appliances_manager, appliances_manager, auth, backend_selector
auth,
backend_selector,
) )
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

View File

@ -4,6 +4,7 @@ from __future__ import annotations
import logging import logging
from typing import Any from typing import Any
from aiohttp import ClientSession
from whirlpool.aircon import Aircon, FanSpeed as AirconFanSpeed, Mode as AirconMode from whirlpool.aircon import Aircon, FanSpeed as AirconFanSpeed, Mode as AirconMode
from whirlpool.auth import Auth from whirlpool.auth import Auth
from whirlpool.backendselector import BackendSelector from whirlpool.backendselector import BackendSelector
@ -24,6 +25,7 @@ from homeassistant.components.climate import (
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant 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 import DeviceInfo, generate_entity_id
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -79,6 +81,7 @@ async def async_setup_entry(
ac_data["NAME"], ac_data["NAME"],
whirlpool_data.backend_selector, whirlpool_data.backend_selector,
whirlpool_data.auth, whirlpool_data.auth,
async_get_clientsession(hass),
) )
for ac_data in whirlpool_data.appliances_manager.aircons 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_target_temperature_step = SUPPORTED_TARGET_TEMPERATURE_STEP
_attr_temperature_unit = UnitOfTemperature.CELSIUS _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.""" """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.entity_id = generate_entity_id(ENTITY_ID_FORMAT, said, hass=hass)
self._attr_unique_id = said self._attr_unique_id = said
@ -123,6 +134,7 @@ class AirConEntity(ClimateEntity):
async def async_will_remove_from_hass(self) -> None: async def async_will_remove_from_hass(self) -> None:
"""Close Whrilpool Appliance sockets before removing.""" """Close Whrilpool Appliance sockets before removing."""
self._aircon.unregister_attr_callback(self.async_write_ha_state)
await self._aircon.disconnect() await self._aircon.disconnect()
@property @property

View File

@ -6,7 +6,7 @@ from collections.abc import Mapping
import logging import logging
from typing import Any from typing import Any
import aiohttp from aiohttp import ClientError
import voluptuous as vol import voluptuous as vol
from whirlpool.appliancesmanager import AppliancesManager from whirlpool.appliancesmanager import AppliancesManager
from whirlpool.auth import Auth from whirlpool.auth import Auth
@ -15,6 +15,7 @@ from whirlpool.backendselector import BackendSelector
from homeassistant import config_entries, core, exceptions from homeassistant import config_entries, core, exceptions
from homeassistant.const import CONF_PASSWORD, CONF_REGION, CONF_USERNAME from homeassistant.const import CONF_PASSWORD, CONF_REGION, CONF_USERNAME
from homeassistant.data_entry_flow import FlowResult from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import CONF_REGIONS_MAP, DOMAIN from .const import CONF_REGIONS_MAP, DOMAIN
from .util import get_brand_for_region 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. 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]] region = CONF_REGIONS_MAP[data[CONF_REGION]]
brand = get_brand_for_region(region) brand = get_brand_for_region(region)
backend_selector = BackendSelector(brand, 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: try:
await auth.do_auth() await auth.do_auth()
except (asyncio.TimeoutError, aiohttp.ClientError) as exc: except (asyncio.TimeoutError, ClientError) as exc:
raise CannotConnect from exc raise CannotConnect from exc
if not auth.is_access_token_valid(): if not auth.is_access_token_valid():
raise InvalidAuth raise InvalidAuth
appliances_manager = AppliancesManager(backend_selector, auth) appliances_manager = AppliancesManager(backend_selector, auth, session)
await appliances_manager.fetch_appliances() await appliances_manager.fetch_appliances()
if appliances_manager.aircons is None and appliances_manager.washer_dryers is None: if appliances_manager.aircons is None and appliances_manager.washer_dryers is None:
raise NoAppliances raise NoAppliances

View File

@ -3,7 +3,7 @@
"name": "Whirlpool Appliances", "name": "Whirlpool Appliances",
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/whirlpool", "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"], "codeowners": ["@abmantis", "@mkmer"],
"iot_class": "cloud_push", "iot_class": "cloud_push",
"loggers": ["whirlpool"], "loggers": ["whirlpool"],

View File

@ -16,6 +16,7 @@ from homeassistant.components.sensor import (
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback 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 import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType from homeassistant.helpers.typing import StateType
@ -148,6 +149,7 @@ async def async_setup_entry(
whirlpool_data.backend_selector, whirlpool_data.backend_selector,
whirlpool_data.auth, whirlpool_data.auth,
appliance["SAID"], appliance["SAID"],
async_get_clientsession(hass),
) )
await _wd.connect() await _wd.connect()
@ -211,7 +213,7 @@ class WasherDryerClass(SensorEntity):
async def async_will_remove_from_hass(self) -> None: async def async_will_remove_from_hass(self) -> None:
"""Close Whrilpool Appliance sockets before removing.""" """Close Whrilpool Appliance sockets before removing."""
await self._wd.disconnect() self._wd.unregister_attr_callback(self.async_write_ha_state)
@property @property
def available(self) -> bool: def available(self) -> bool:

View File

@ -2592,7 +2592,7 @@ waterfurnace==1.1.0
webexteamssdk==1.1.1 webexteamssdk==1.1.1
# homeassistant.components.whirlpool # homeassistant.components.whirlpool
whirlpool-sixth-sense==0.18.0 whirlpool-sixth-sense==0.18.1
# homeassistant.components.whois # homeassistant.components.whois
whois==0.9.16 whois==0.9.16

View File

@ -1820,7 +1820,7 @@ wallbox==0.4.12
watchdog==2.2.1 watchdog==2.2.1
# homeassistant.components.whirlpool # homeassistant.components.whirlpool
whirlpool-sixth-sense==0.18.0 whirlpool-sixth-sense==0.18.1
# homeassistant.components.whois # homeassistant.components.whois
whois==0.9.16 whois==0.9.16