Bump aiovodafone to 0.4.1 (#102180)
This commit is contained in:
parent
3cedfbcc66
commit
6c1bcae291
7 changed files with 33 additions and 32 deletions
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||
from collections.abc import Mapping
|
||||
from typing import Any
|
||||
|
||||
from aiovodafone import VodafoneStationApi, exceptions as aiovodafone_exceptions
|
||||
from aiovodafone import VodafoneStationSercommApi, exceptions as aiovodafone_exceptions
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import core
|
||||
|
@ -35,7 +35,9 @@ async def validate_input(
|
|||
) -> dict[str, str]:
|
||||
"""Validate the user input allows us to connect."""
|
||||
|
||||
api = VodafoneStationApi(data[CONF_HOST], data[CONF_USERNAME], data[CONF_PASSWORD])
|
||||
api = VodafoneStationSercommApi(
|
||||
data[CONF_HOST], data[CONF_USERNAME], data[CONF_PASSWORD]
|
||||
)
|
||||
|
||||
try:
|
||||
await api.login()
|
||||
|
|
|
@ -3,7 +3,7 @@ from dataclasses import dataclass
|
|||
from datetime import datetime, timedelta
|
||||
from typing import Any
|
||||
|
||||
from aiovodafone import VodafoneStationApi, VodafoneStationDevice, exceptions
|
||||
from aiovodafone import VodafoneStationDevice, VodafoneStationSercommApi, exceptions
|
||||
|
||||
from homeassistant.components.device_tracker import DEFAULT_CONSIDER_HOME
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
@ -48,7 +48,7 @@ class VodafoneStationRouter(DataUpdateCoordinator[UpdateCoordinatorDataType]):
|
|||
"""Initialize the scanner."""
|
||||
|
||||
self._host = host
|
||||
self.api = VodafoneStationApi(host, username, password)
|
||||
self.api = VodafoneStationSercommApi(host, username, password)
|
||||
|
||||
# Last resort as no MAC or S/N can be retrieved via API
|
||||
self._id = config_entry_unique_id
|
||||
|
|
|
@ -6,5 +6,5 @@
|
|||
"documentation": "https://www.home-assistant.io/integrations/vodafone_station",
|
||||
"iot_class": "local_polling",
|
||||
"loggers": ["aiovodafone"],
|
||||
"requirements": ["aiovodafone==0.3.1"]
|
||||
"requirements": ["aiovodafone==0.4.1"]
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime
|
||||
from typing import Any, Final
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
|
@ -17,7 +17,6 @@ from homeassistant.core import HomeAssistant
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from .const import _LOGGER, DOMAIN, LINE_TYPES
|
||||
from .coordinator import VodafoneStationRouter
|
||||
|
@ -29,7 +28,9 @@ NOT_AVAILABLE: list = ["", "N/A", "0.0.0.0"]
|
|||
class VodafoneStationBaseEntityDescription:
|
||||
"""Vodafone Station entity base description."""
|
||||
|
||||
value: Callable[[Any, Any], Any] = lambda val, key: val[key]
|
||||
value: Callable[
|
||||
[Any, Any], Any
|
||||
] = lambda coordinator, key: coordinator.data.sensors[key]
|
||||
is_suitable: Callable[[dict], bool] = lambda val: True
|
||||
|
||||
|
||||
|
@ -40,18 +41,16 @@ class VodafoneStationEntityDescription(
|
|||
"""Vodafone Station entity description."""
|
||||
|
||||
|
||||
def _calculate_uptime(value: dict, key: str) -> datetime:
|
||||
def _calculate_uptime(coordinator: VodafoneStationRouter, key: str) -> datetime:
|
||||
"""Calculate device uptime."""
|
||||
d = int(value[key].split(":")[0])
|
||||
h = int(value[key].split(":")[1])
|
||||
m = int(value[key].split(":")[2])
|
||||
|
||||
return utcnow() - timedelta(days=d, hours=h, minutes=m)
|
||||
return coordinator.api.convert_uptime(coordinator.data.sensors[key])
|
||||
|
||||
|
||||
def _line_connection(value: dict, key: str) -> str | None:
|
||||
def _line_connection(coordinator: VodafoneStationRouter, key: str) -> str | None:
|
||||
"""Identify line type."""
|
||||
|
||||
value = coordinator.data.sensors
|
||||
internet_ip = value[key]
|
||||
dsl_ip = value.get("dsl_ipaddr")
|
||||
fiber_ip = value.get("fiber_ipaddr")
|
||||
|
@ -141,7 +140,7 @@ SENSOR_TYPES: Final = (
|
|||
icon="mdi:chip",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value=lambda value, key: float(value[key][:-1]),
|
||||
value=lambda coordinator, key: float(coordinator.data.sensors[key][:-1]),
|
||||
),
|
||||
VodafoneStationEntityDescription(
|
||||
key="sys_memory_usage",
|
||||
|
@ -149,7 +148,7 @@ SENSOR_TYPES: Final = (
|
|||
icon="mdi:memory",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value=lambda value, key: float(value[key][:-1]),
|
||||
value=lambda coordinator, key: float(coordinator.data.sensors[key][:-1]),
|
||||
),
|
||||
VodafoneStationEntityDescription(
|
||||
key="sys_reboot_cause",
|
||||
|
@ -200,5 +199,5 @@ class VodafoneStationSensorEntity(
|
|||
def native_value(self) -> StateType:
|
||||
"""Sensor value."""
|
||||
return self.entity_description.value(
|
||||
self.coordinator.data.sensors, self.entity_description.key
|
||||
self.coordinator, self.entity_description.key
|
||||
)
|
||||
|
|
|
@ -375,7 +375,7 @@ aiounifi==63
|
|||
aiovlc==0.1.0
|
||||
|
||||
# homeassistant.components.vodafone_station
|
||||
aiovodafone==0.3.1
|
||||
aiovodafone==0.4.1
|
||||
|
||||
# homeassistant.components.waqi
|
||||
aiowaqi==2.0.0
|
||||
|
|
|
@ -350,7 +350,7 @@ aiounifi==63
|
|||
aiovlc==0.1.0
|
||||
|
||||
# homeassistant.components.vodafone_station
|
||||
aiovodafone==0.3.1
|
||||
aiovodafone==0.4.1
|
||||
|
||||
# homeassistant.components.waqi
|
||||
aiowaqi==2.0.0
|
||||
|
|
|
@ -18,9 +18,9 @@ from tests.common import MockConfigEntry
|
|||
async def test_user(hass: HomeAssistant) -> None:
|
||||
"""Test starting a flow by user."""
|
||||
with patch(
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.login",
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.login",
|
||||
), patch(
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.logout",
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.logout",
|
||||
), patch(
|
||||
"homeassistant.components.vodafone_station.async_setup_entry"
|
||||
) as mock_setup_entry, patch(
|
||||
|
@ -67,7 +67,7 @@ async def test_exception_connection(hass: HomeAssistant, side_effect, error) ->
|
|||
assert result["step_id"] == "user"
|
||||
|
||||
with patch(
|
||||
"aiovodafone.api.VodafoneStationApi.login",
|
||||
"aiovodafone.api.VodafoneStationSercommApi.login",
|
||||
side_effect=side_effect,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
|
@ -80,15 +80,15 @@ async def test_exception_connection(hass: HomeAssistant, side_effect, error) ->
|
|||
|
||||
# Should be recoverable after hits error
|
||||
with patch(
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.get_devices_data",
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.get_devices_data",
|
||||
return_value={
|
||||
"wifi_user": "on|laptop|device-1|xx:xx:xx:xx:xx:xx|192.168.100.1||2.4G",
|
||||
"ethernet": "laptop|device-2|yy:yy:yy:yy:yy:yy|192.168.100.2|;",
|
||||
},
|
||||
), patch(
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.login",
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.login",
|
||||
), patch(
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.logout",
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.logout",
|
||||
), patch(
|
||||
"homeassistant.components.vodafone_station.async_setup_entry"
|
||||
):
|
||||
|
@ -118,9 +118,9 @@ async def test_reauth_successful(hass: HomeAssistant) -> None:
|
|||
mock_config.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.login",
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.login",
|
||||
), patch(
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.logout",
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.logout",
|
||||
), patch(
|
||||
"homeassistant.components.vodafone_station.async_setup_entry"
|
||||
), patch(
|
||||
|
@ -165,10 +165,10 @@ async def test_reauth_not_successful(hass: HomeAssistant, side_effect, error) ->
|
|||
mock_config.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.login",
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.login",
|
||||
side_effect=side_effect,
|
||||
), patch(
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.logout",
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.logout",
|
||||
), patch(
|
||||
"homeassistant.components.vodafone_station.async_setup_entry"
|
||||
):
|
||||
|
@ -194,15 +194,15 @@ async def test_reauth_not_successful(hass: HomeAssistant, side_effect, error) ->
|
|||
|
||||
# Should be recoverable after hits error
|
||||
with patch(
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.get_devices_data",
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.get_devices_data",
|
||||
return_value={
|
||||
"wifi_user": "on|laptop|device-1|xx:xx:xx:xx:xx:xx|192.168.100.1||2.4G",
|
||||
"ethernet": "laptop|device-2|yy:yy:yy:yy:yy:yy|192.168.100.2|;",
|
||||
},
|
||||
), patch(
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.login",
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.login",
|
||||
), patch(
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.logout",
|
||||
"homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.logout",
|
||||
), patch(
|
||||
"homeassistant.components.vodafone_station.async_setup_entry"
|
||||
):
|
||||
|
|
Loading…
Add table
Reference in a new issue