1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-15 04:51:20 +01:00

Update afsapi to v1.0.0 (#168414)

This commit is contained in:
Thijs W.
2026-04-17 12:57:06 +02:00
committed by GitHub
parent 02c6af8be2
commit 0824142b9c
8 changed files with 39 additions and 45 deletions
@@ -4,7 +4,7 @@ from __future__ import annotations
import logging
from afsapi import AFSAPI, ConnectionError as FSConnectionError
from afsapi import AFSAPI, FSConnectionError
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PIN, Platform
@@ -2,7 +2,7 @@
import logging
from afsapi import AFSAPI, FSApiException, OutOfRangeException, Preset
from afsapi import AFSAPI, FSApiError, OutOfRangeError, Preset
from homeassistant.components.media_player import (
BrowseError,
@@ -136,11 +136,11 @@ async def browse_node(
# Return items in this folder
children = [
_item_payload(key, item, player_mode, parent_keys=parent_keys)
async for key, item in await afsapi.nav_list()
async for key, item in afsapi.nav_list()
]
except OutOfRangeException as err:
except OutOfRangeError as err:
raise BrowseError("The requested item is out of range") from err
except FSApiException as err:
except FSApiError as err:
raise BrowseError(str(err)) from err
return BrowseMedia(
@@ -7,12 +7,7 @@ import logging
from typing import Any
from urllib.parse import urlparse
from afsapi import (
AFSAPI,
ConnectionError as FSConnectionError,
InvalidPinException,
NotImplementedException,
)
from afsapi import AFSAPI, FSConnectionError, FSNotImplementedError, InvalidPinError
import voluptuous as vol
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlow, ConfigFlowResult
@@ -116,12 +111,12 @@ class FrontierSiliconConfigFlow(ConfigFlow, domain=DOMAIN):
afsapi = AFSAPI(self._webfsapi_url, DEFAULT_PIN)
try:
await afsapi.get_friendly_name()
except InvalidPinException:
except InvalidPinError:
return self.async_abort(reason="invalid_auth")
try:
unique_id = await afsapi.get_radio_id()
except NotImplementedException:
except FSNotImplementedError:
unique_id = None
await self.async_set_unique_id(unique_id)
@@ -144,7 +139,7 @@ class FrontierSiliconConfigFlow(ConfigFlow, domain=DOMAIN):
afsapi = AFSAPI(self._webfsapi_url, DEFAULT_PIN)
self._name = await afsapi.get_friendly_name()
except InvalidPinException:
except InvalidPinError:
# Ask for a PIN
return await self.async_step_device_config()
@@ -152,7 +147,7 @@ class FrontierSiliconConfigFlow(ConfigFlow, domain=DOMAIN):
try:
unique_id = await afsapi.get_radio_id()
except NotImplementedException:
except FSNotImplementedError:
unique_id = None
await self.async_set_unique_id(unique_id)
self._abort_if_unique_id_configured()
@@ -201,7 +196,7 @@ class FrontierSiliconConfigFlow(ConfigFlow, domain=DOMAIN):
except FSConnectionError:
errors["base"] = "cannot_connect"
except InvalidPinException:
except InvalidPinError:
errors["base"] = "invalid_auth"
except Exception:
_LOGGER.exception("Unexpected exception")
@@ -215,7 +210,7 @@ class FrontierSiliconConfigFlow(ConfigFlow, domain=DOMAIN):
try:
unique_id = await afsapi.get_radio_id()
except NotImplementedException:
except FSNotImplementedError:
unique_id = None
await self.async_set_unique_id(unique_id, raise_on_progress=False)
self._abort_if_unique_id_configured()
@@ -6,7 +6,8 @@
"documentation": "https://www.home-assistant.io/integrations/frontier_silicon",
"integration_type": "device",
"iot_class": "local_polling",
"requirements": ["afsapi==0.3.1"],
"loggers": ["afsapi"],
"requirements": ["afsapi==1.0.0"],
"ssdp": [
{
"st": "urn:schemas-frontier-silicon-com:undok:fsapi:1"
@@ -5,12 +5,7 @@ from __future__ import annotations
import logging
from typing import Any
from afsapi import (
AFSAPI,
ConnectionError as FSConnectionError,
NotImplementedException as FSNotImplementedException,
PlayState,
)
from afsapi import AFSAPI, FSConnectionError, FSNotImplementedError, PlayState
from homeassistant.components.media_player import (
BrowseError,
@@ -100,12 +95,13 @@ class AFSAPIDevice(MediaPlayerEntity):
if await afsapi.get_power():
status = await afsapi.get_play_status()
self._attr_state = {
PlayState.IDLE: MediaPlayerState.IDLE,
PlayState.BUFFERING: MediaPlayerState.BUFFERING,
PlayState.PLAYING: MediaPlayerState.PLAYING,
PlayState.PAUSED: MediaPlayerState.PAUSED,
PlayState.REBUFFERING: MediaPlayerState.BUFFERING,
PlayState.STOPPED: MediaPlayerState.IDLE,
PlayState.LOADING: MediaPlayerState.BUFFERING,
None: MediaPlayerState.IDLE,
}.get(status)
}.get(status, MediaPlayerState.IDLE)
else:
self._attr_state = MediaPlayerState.OFF
except FSConnectionError:
@@ -115,7 +111,9 @@ class AFSAPIDevice(MediaPlayerEntity):
self.name or afsapi.webfsapi_endpoint,
)
self._attr_available = False
return
# Device is not available, stop the update
return
if not self._attr_available:
_LOGGER.warning(
@@ -134,7 +132,7 @@ class AFSAPIDevice(MediaPlayerEntity):
if not self._attr_sound_mode_list and self._supports_sound_mode:
try:
equalisers = await afsapi.get_equalisers()
except FSNotImplementedException:
except FSNotImplementedError:
self._supports_sound_mode = False
# Remove SELECT_SOUND_MODE from the advertised supported features
self._attr_supported_features ^= (
@@ -169,7 +167,7 @@ class AFSAPIDevice(MediaPlayerEntity):
if self._supports_sound_mode:
try:
eq_preset = await afsapi.get_eq_preset()
except FSNotImplementedException:
except FSNotImplementedError:
self._supports_sound_mode = False
# Remove SELECT_SOUND_MODE from the advertised supported features
self._attr_supported_features ^= (
+1 -1
View File
@@ -151,7 +151,7 @@ adguardhome==0.8.1
advantage-air==0.4.4
# homeassistant.components.frontier_silicon
afsapi==0.3.1
afsapi==1.0.0
# homeassistant.components.agent_dvr
agent-py==0.0.24
+1 -1
View File
@@ -142,7 +142,7 @@ adguardhome==0.8.1
advantage-air==0.4.4
# homeassistant.components.frontier_silicon
afsapi==0.3.1
afsapi==1.0.0
# homeassistant.components.agent_dvr
agent-py==0.0.24
@@ -2,7 +2,7 @@
from unittest.mock import AsyncMock, patch
from afsapi import ConnectionError, InvalidPinException, NotImplementedException
from afsapi import FSConnectionError, FSNotImplementedError, InvalidPinError
import pytest
from homeassistant import config_entries
@@ -42,7 +42,7 @@ INVALID_MOCK_DISCOVERY = SsdpServiceInfo(
@pytest.mark.parametrize(
("radio_id_return_value", "radio_id_side_effect"),
[("mock_radio_id", None), (None, NotImplementedException)],
[("mock_radio_id", None), (None, FSNotImplementedError)],
)
async def test_form_default_pin(
hass: HomeAssistant,
@@ -80,7 +80,7 @@ async def test_form_default_pin(
@pytest.mark.parametrize(
("radio_id_return_value", "radio_id_side_effect"),
[("mock_radio_id", None), (None, NotImplementedException)],
[("mock_radio_id", None), (None, FSNotImplementedError)],
)
async def test_form_nondefault_pin(
hass: HomeAssistant,
@@ -98,7 +98,7 @@ async def test_form_nondefault_pin(
with patch(
"homeassistant.components.frontier_silicon.config_flow.AFSAPI.get_friendly_name",
side_effect=InvalidPinException,
side_effect=InvalidPinError,
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
@@ -133,8 +133,8 @@ async def test_form_nondefault_pin(
@pytest.mark.parametrize(
("friendly_name_error", "result_error"),
[
(ConnectionError, "cannot_connect"),
(InvalidPinException, "invalid_auth"),
(FSConnectionError, "cannot_connect"),
(InvalidPinError, "invalid_auth"),
(ValueError, "unknown"),
],
)
@@ -154,7 +154,7 @@ async def test_form_nondefault_pin_invalid(
with patch(
"homeassistant.components.frontier_silicon.config_flow.AFSAPI.get_friendly_name",
side_effect=InvalidPinException,
side_effect=InvalidPinError,
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
@@ -198,7 +198,7 @@ async def test_form_nondefault_pin_invalid(
@pytest.mark.parametrize(
("webfsapi_endpoint_error", "result_error"),
[
(ConnectionError, "cannot_connect"),
(FSConnectionError, "cannot_connect"),
(ValueError, "unknown"),
],
)
@@ -247,7 +247,7 @@ async def test_invalid_device_url(
@pytest.mark.parametrize(
("radio_id_return_value", "radio_id_side_effect"),
[("mock_radio_id", None), (None, NotImplementedException)],
[("mock_radio_id", None), (None, FSNotImplementedError)],
)
async def test_ssdp(
hass: HomeAssistant,
@@ -321,7 +321,7 @@ async def test_ssdp_already_configured(
@pytest.mark.parametrize(
("webfsapi_endpoint_error", "result_error"),
[(ValueError, "unknown"), (ConnectionError, "cannot_connect")],
[(ValueError, "unknown"), (FSConnectionError, "cannot_connect")],
)
async def test_ssdp_fail(
hass: HomeAssistant, webfsapi_endpoint_error: Exception, result_error: str
@@ -346,7 +346,7 @@ async def test_ssdp_nondefault_pin(hass: HomeAssistant) -> None:
with patch(
"homeassistant.components.frontier_silicon.config_flow.AFSAPI.get_friendly_name",
side_effect=InvalidPinException,
side_effect=InvalidPinError,
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
@@ -379,8 +379,8 @@ async def test_reauth_flow(hass: HomeAssistant, config_entry: MockConfigEntry) -
@pytest.mark.parametrize(
("exception", "reason"),
[
(ConnectionError, "cannot_connect"),
(InvalidPinException, "invalid_auth"),
(FSConnectionError, "cannot_connect"),
(InvalidPinError, "invalid_auth"),
(ValueError, "unknown"),
],
)