From e2e19cf4b44cc7669f3e6cbb5461db0f2003dd55 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Tue, 26 Oct 2021 17:44:40 -0600 Subject: [PATCH] Bump aioambient to 2021.10.0 (#58494) --- .../components/ambient_station/__init__.py | 31 +++++++++---------- .../components/ambient_station/config_flow.py | 8 ++--- .../components/ambient_station/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- .../ambient_station/test_config_flow.py | 7 +++-- 6 files changed, 24 insertions(+), 28 deletions(-) diff --git a/homeassistant/components/ambient_station/__init__.py b/homeassistant/components/ambient_station/__init__.py index bd509722f93..190ed6dc59e 100644 --- a/homeassistant/components/ambient_station/__init__.py +++ b/homeassistant/components/ambient_station/__init__.py @@ -3,7 +3,7 @@ from __future__ import annotations from typing import Any -from aioambient import Client +from aioambient import Websocket from aioambient.errors import WebsocketError from homeassistant.config_entries import ConfigEntry @@ -15,7 +15,7 @@ from homeassistant.const import ( ) from homeassistant.core import Event, HomeAssistant, callback from homeassistant.exceptions import ConfigEntryNotReady -from homeassistant.helpers import aiohttp_client, config_validation as cv +from homeassistant.helpers import config_validation as cv from homeassistant.helpers.dispatcher import ( async_dispatcher_connect, async_dispatcher_send, @@ -65,17 +65,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass.config_entries.async_update_entry( entry, unique_id=entry.data[CONF_APP_KEY] ) - session = aiohttp_client.async_get_clientsession(hass) try: ambient = AmbientStation( hass, entry, - Client( - entry.data[CONF_API_KEY], - entry.data[CONF_APP_KEY], - session=session, - ), + Websocket(entry.data[CONF_APP_KEY], entry.data[CONF_API_KEY]), ) hass.loop.create_task(ambient.ws_connect()) hass.data[DOMAIN][entry.entry_id] = ambient @@ -84,7 +79,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: raise ConfigEntryNotReady from err async def _async_disconnect_websocket(_: Event) -> None: - await ambient.client.websocket.disconnect() + await ambient.websocket.disconnect() entry.async_on_unload( hass.bus.async_listen_once( @@ -129,21 +124,23 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: class AmbientStation: """Define a class to handle the Ambient websocket.""" - def __init__(self, hass: HomeAssistant, entry: ConfigEntry, client: Client) -> None: + def __init__( + self, hass: HomeAssistant, entry: ConfigEntry, websocket: Websocket + ) -> None: """Initialize.""" self._entry = entry self._entry_setup_complete = False self._hass = hass self._ws_reconnect_delay = DEFAULT_SOCKET_MIN_RETRY - self.client = client self.stations: dict[str, dict] = {} + self.websocket = websocket async def _attempt_connect(self) -> None: """Attempt to connect to the socket (retrying later on fail).""" async def connect(timestamp: int | None = None) -> None: """Connect.""" - await self.client.websocket.connect() + await self.websocket.connect() try: await connect() @@ -197,16 +194,16 @@ class AmbientStation: self._entry_setup_complete = True self._ws_reconnect_delay = DEFAULT_SOCKET_MIN_RETRY - self.client.websocket.on_connect(on_connect) - self.client.websocket.on_data(on_data) - self.client.websocket.on_disconnect(on_disconnect) - self.client.websocket.on_subscribed(on_subscribed) + self.websocket.on_connect(on_connect) + self.websocket.on_data(on_data) + self.websocket.on_disconnect(on_disconnect) + self.websocket.on_subscribed(on_subscribed) await self._attempt_connect() async def ws_disconnect(self) -> None: """Disconnect from the websocket.""" - await self.client.websocket.disconnect() + await self.websocket.disconnect() class AmbientWeatherEntity(Entity): diff --git a/homeassistant/components/ambient_station/config_flow.py b/homeassistant/components/ambient_station/config_flow.py index d93d502ac92..2c2d231b33e 100644 --- a/homeassistant/components/ambient_station/config_flow.py +++ b/homeassistant/components/ambient_station/config_flow.py @@ -1,7 +1,7 @@ """Config flow to configure the Ambient PWS component.""" from __future__ import annotations -from aioambient import Client +from aioambient import API from aioambient.errors import AmbientError import voluptuous as vol @@ -41,12 +41,10 @@ class AmbientStationFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): self._abort_if_unique_id_configured() session = aiohttp_client.async_get_clientsession(self.hass) - client = Client( - user_input[CONF_API_KEY], user_input[CONF_APP_KEY], session=session - ) + api = API(user_input[CONF_APP_KEY], user_input[CONF_API_KEY], session=session) try: - devices = await client.api.get_devices() + devices = await api.get_devices() except AmbientError: return await self._show_form({"base": "invalid_key"}) diff --git a/homeassistant/components/ambient_station/manifest.json b/homeassistant/components/ambient_station/manifest.json index b95f4a8f13c..116a52f58c5 100644 --- a/homeassistant/components/ambient_station/manifest.json +++ b/homeassistant/components/ambient_station/manifest.json @@ -3,7 +3,7 @@ "name": "Ambient Weather Station", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/ambient_station", - "requirements": ["aioambient==1.3.0"], + "requirements": ["aioambient==2021.10.0"], "codeowners": ["@bachya"], "iot_class": "cloud_push" } diff --git a/requirements_all.txt b/requirements_all.txt index 71b3d73a761..f03e19f535c 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -133,7 +133,7 @@ aio_geojson_nsw_rfs_incidents==0.4 aio_georss_gdacs==0.5 # homeassistant.components.ambient_station -aioambient==1.3.0 +aioambient==2021.10.0 # homeassistant.components.asuswrt aioasuswrt==1.3.4 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index bf73128d453..b77e9f5a0e9 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -81,7 +81,7 @@ aio_geojson_nsw_rfs_incidents==0.4 aio_georss_gdacs==0.5 # homeassistant.components.ambient_station -aioambient==1.3.0 +aioambient==2021.10.0 # homeassistant.components.asuswrt aioasuswrt==1.3.4 diff --git a/tests/components/ambient_station/test_config_flow.py b/tests/components/ambient_station/test_config_flow.py index 806d31b5386..27dbac9faed 100644 --- a/tests/components/ambient_station/test_config_flow.py +++ b/tests/components/ambient_station/test_config_flow.py @@ -22,9 +22,10 @@ def get_devices_response(): @pytest.fixture def mock_aioambient(get_devices_response): """Mock the aioambient library.""" - with patch("homeassistant.components.ambient_station.config_flow.Client") as Client: - Client().api.get_devices.return_value = get_devices_response - yield Client + with patch("homeassistant.components.ambient_station.config_flow.API") as API: + api = API() + api.get_devices.return_value = get_devices_response + yield api async def test_duplicate_error(hass):