mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 10:47:10 +00:00
Bump aioambient to 2021.10.0 (#58494)
This commit is contained in:
parent
de4a4c3ba9
commit
e2e19cf4b4
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from aioambient import Client
|
from aioambient import Websocket
|
||||||
from aioambient.errors import WebsocketError
|
from aioambient.errors import WebsocketError
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -15,7 +15,7 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import Event, HomeAssistant, callback
|
from homeassistant.core import Event, HomeAssistant, callback
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
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 (
|
from homeassistant.helpers.dispatcher import (
|
||||||
async_dispatcher_connect,
|
async_dispatcher_connect,
|
||||||
async_dispatcher_send,
|
async_dispatcher_send,
|
||||||
@ -65,17 +65,12 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
hass.config_entries.async_update_entry(
|
hass.config_entries.async_update_entry(
|
||||||
entry, unique_id=entry.data[CONF_APP_KEY]
|
entry, unique_id=entry.data[CONF_APP_KEY]
|
||||||
)
|
)
|
||||||
session = aiohttp_client.async_get_clientsession(hass)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ambient = AmbientStation(
|
ambient = AmbientStation(
|
||||||
hass,
|
hass,
|
||||||
entry,
|
entry,
|
||||||
Client(
|
Websocket(entry.data[CONF_APP_KEY], entry.data[CONF_API_KEY]),
|
||||||
entry.data[CONF_API_KEY],
|
|
||||||
entry.data[CONF_APP_KEY],
|
|
||||||
session=session,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
hass.loop.create_task(ambient.ws_connect())
|
hass.loop.create_task(ambient.ws_connect())
|
||||||
hass.data[DOMAIN][entry.entry_id] = ambient
|
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
|
raise ConfigEntryNotReady from err
|
||||||
|
|
||||||
async def _async_disconnect_websocket(_: Event) -> None:
|
async def _async_disconnect_websocket(_: Event) -> None:
|
||||||
await ambient.client.websocket.disconnect()
|
await ambient.websocket.disconnect()
|
||||||
|
|
||||||
entry.async_on_unload(
|
entry.async_on_unload(
|
||||||
hass.bus.async_listen_once(
|
hass.bus.async_listen_once(
|
||||||
@ -129,21 +124,23 @@ async def async_migrate_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
class AmbientStation:
|
class AmbientStation:
|
||||||
"""Define a class to handle the Ambient websocket."""
|
"""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."""
|
"""Initialize."""
|
||||||
self._entry = entry
|
self._entry = entry
|
||||||
self._entry_setup_complete = False
|
self._entry_setup_complete = False
|
||||||
self._hass = hass
|
self._hass = hass
|
||||||
self._ws_reconnect_delay = DEFAULT_SOCKET_MIN_RETRY
|
self._ws_reconnect_delay = DEFAULT_SOCKET_MIN_RETRY
|
||||||
self.client = client
|
|
||||||
self.stations: dict[str, dict] = {}
|
self.stations: dict[str, dict] = {}
|
||||||
|
self.websocket = websocket
|
||||||
|
|
||||||
async def _attempt_connect(self) -> None:
|
async def _attempt_connect(self) -> None:
|
||||||
"""Attempt to connect to the socket (retrying later on fail)."""
|
"""Attempt to connect to the socket (retrying later on fail)."""
|
||||||
|
|
||||||
async def connect(timestamp: int | None = None) -> None:
|
async def connect(timestamp: int | None = None) -> None:
|
||||||
"""Connect."""
|
"""Connect."""
|
||||||
await self.client.websocket.connect()
|
await self.websocket.connect()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await connect()
|
await connect()
|
||||||
@ -197,16 +194,16 @@ class AmbientStation:
|
|||||||
self._entry_setup_complete = True
|
self._entry_setup_complete = True
|
||||||
self._ws_reconnect_delay = DEFAULT_SOCKET_MIN_RETRY
|
self._ws_reconnect_delay = DEFAULT_SOCKET_MIN_RETRY
|
||||||
|
|
||||||
self.client.websocket.on_connect(on_connect)
|
self.websocket.on_connect(on_connect)
|
||||||
self.client.websocket.on_data(on_data)
|
self.websocket.on_data(on_data)
|
||||||
self.client.websocket.on_disconnect(on_disconnect)
|
self.websocket.on_disconnect(on_disconnect)
|
||||||
self.client.websocket.on_subscribed(on_subscribed)
|
self.websocket.on_subscribed(on_subscribed)
|
||||||
|
|
||||||
await self._attempt_connect()
|
await self._attempt_connect()
|
||||||
|
|
||||||
async def ws_disconnect(self) -> None:
|
async def ws_disconnect(self) -> None:
|
||||||
"""Disconnect from the websocket."""
|
"""Disconnect from the websocket."""
|
||||||
await self.client.websocket.disconnect()
|
await self.websocket.disconnect()
|
||||||
|
|
||||||
|
|
||||||
class AmbientWeatherEntity(Entity):
|
class AmbientWeatherEntity(Entity):
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"""Config flow to configure the Ambient PWS component."""
|
"""Config flow to configure the Ambient PWS component."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from aioambient import Client
|
from aioambient import API
|
||||||
from aioambient.errors import AmbientError
|
from aioambient.errors import AmbientError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -41,12 +41,10 @@ class AmbientStationFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
session = aiohttp_client.async_get_clientsession(self.hass)
|
session = aiohttp_client.async_get_clientsession(self.hass)
|
||||||
client = Client(
|
api = API(user_input[CONF_APP_KEY], user_input[CONF_API_KEY], session=session)
|
||||||
user_input[CONF_API_KEY], user_input[CONF_APP_KEY], session=session
|
|
||||||
)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
devices = await client.api.get_devices()
|
devices = await api.get_devices()
|
||||||
except AmbientError:
|
except AmbientError:
|
||||||
return await self._show_form({"base": "invalid_key"})
|
return await self._show_form({"base": "invalid_key"})
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "Ambient Weather Station",
|
"name": "Ambient Weather Station",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/ambient_station",
|
"documentation": "https://www.home-assistant.io/integrations/ambient_station",
|
||||||
"requirements": ["aioambient==1.3.0"],
|
"requirements": ["aioambient==2021.10.0"],
|
||||||
"codeowners": ["@bachya"],
|
"codeowners": ["@bachya"],
|
||||||
"iot_class": "cloud_push"
|
"iot_class": "cloud_push"
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ aio_geojson_nsw_rfs_incidents==0.4
|
|||||||
aio_georss_gdacs==0.5
|
aio_georss_gdacs==0.5
|
||||||
|
|
||||||
# homeassistant.components.ambient_station
|
# homeassistant.components.ambient_station
|
||||||
aioambient==1.3.0
|
aioambient==2021.10.0
|
||||||
|
|
||||||
# homeassistant.components.asuswrt
|
# homeassistant.components.asuswrt
|
||||||
aioasuswrt==1.3.4
|
aioasuswrt==1.3.4
|
||||||
|
@ -81,7 +81,7 @@ aio_geojson_nsw_rfs_incidents==0.4
|
|||||||
aio_georss_gdacs==0.5
|
aio_georss_gdacs==0.5
|
||||||
|
|
||||||
# homeassistant.components.ambient_station
|
# homeassistant.components.ambient_station
|
||||||
aioambient==1.3.0
|
aioambient==2021.10.0
|
||||||
|
|
||||||
# homeassistant.components.asuswrt
|
# homeassistant.components.asuswrt
|
||||||
aioasuswrt==1.3.4
|
aioasuswrt==1.3.4
|
||||||
|
@ -22,9 +22,10 @@ def get_devices_response():
|
|||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_aioambient(get_devices_response):
|
def mock_aioambient(get_devices_response):
|
||||||
"""Mock the aioambient library."""
|
"""Mock the aioambient library."""
|
||||||
with patch("homeassistant.components.ambient_station.config_flow.Client") as Client:
|
with patch("homeassistant.components.ambient_station.config_flow.API") as API:
|
||||||
Client().api.get_devices.return_value = get_devices_response
|
api = API()
|
||||||
yield Client
|
api.get_devices.return_value = get_devices_response
|
||||||
|
yield api
|
||||||
|
|
||||||
|
|
||||||
async def test_duplicate_error(hass):
|
async def test_duplicate_error(hass):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user