mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
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:
parent
bba9ad3243
commit
b86c58b0ea
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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"],
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user