Bump aiovodafone to 0.4.1 (#102180)

This commit is contained in:
Simone Chemelli 2023-10-18 10:56:48 +02:00 committed by GitHub
parent 3cedfbcc66
commit 6c1bcae291
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 32 deletions

View File

@ -4,7 +4,7 @@ from __future__ import annotations
from collections.abc import Mapping from collections.abc import Mapping
from typing import Any from typing import Any
from aiovodafone import VodafoneStationApi, exceptions as aiovodafone_exceptions from aiovodafone import VodafoneStationSercommApi, exceptions as aiovodafone_exceptions
import voluptuous as vol import voluptuous as vol
from homeassistant import core from homeassistant import core
@ -35,7 +35,9 @@ async def validate_input(
) -> dict[str, str]: ) -> dict[str, str]:
"""Validate the user input allows us to connect.""" """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: try:
await api.login() await api.login()

View File

@ -3,7 +3,7 @@ from dataclasses import dataclass
from datetime import datetime, timedelta from datetime import datetime, timedelta
from typing import Any 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.components.device_tracker import DEFAULT_CONSIDER_HOME
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -48,7 +48,7 @@ class VodafoneStationRouter(DataUpdateCoordinator[UpdateCoordinatorDataType]):
"""Initialize the scanner.""" """Initialize the scanner."""
self._host = host 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 # Last resort as no MAC or S/N can be retrieved via API
self._id = config_entry_unique_id self._id = config_entry_unique_id

View File

@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/vodafone_station", "documentation": "https://www.home-assistant.io/integrations/vodafone_station",
"iot_class": "local_polling", "iot_class": "local_polling",
"loggers": ["aiovodafone"], "loggers": ["aiovodafone"],
"requirements": ["aiovodafone==0.3.1"] "requirements": ["aiovodafone==0.4.1"]
} }

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from collections.abc import Callable from collections.abc import Callable
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime, timedelta from datetime import datetime
from typing import Any, Final from typing import Any, Final
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
@ -17,7 +17,6 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType from homeassistant.helpers.typing import StateType
from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util.dt import utcnow
from .const import _LOGGER, DOMAIN, LINE_TYPES from .const import _LOGGER, DOMAIN, LINE_TYPES
from .coordinator import VodafoneStationRouter from .coordinator import VodafoneStationRouter
@ -29,7 +28,9 @@ NOT_AVAILABLE: list = ["", "N/A", "0.0.0.0"]
class VodafoneStationBaseEntityDescription: class VodafoneStationBaseEntityDescription:
"""Vodafone Station entity base description.""" """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 is_suitable: Callable[[dict], bool] = lambda val: True
@ -40,18 +41,16 @@ class VodafoneStationEntityDescription(
"""Vodafone Station entity description.""" """Vodafone Station entity description."""
def _calculate_uptime(value: dict, key: str) -> datetime: def _calculate_uptime(coordinator: VodafoneStationRouter, key: str) -> datetime:
"""Calculate device uptime.""" """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.""" """Identify line type."""
value = coordinator.data.sensors
internet_ip = value[key] internet_ip = value[key]
dsl_ip = value.get("dsl_ipaddr") dsl_ip = value.get("dsl_ipaddr")
fiber_ip = value.get("fiber_ipaddr") fiber_ip = value.get("fiber_ipaddr")
@ -141,7 +140,7 @@ SENSOR_TYPES: Final = (
icon="mdi:chip", icon="mdi:chip",
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
value=lambda value, key: float(value[key][:-1]), value=lambda coordinator, key: float(coordinator.data.sensors[key][:-1]),
), ),
VodafoneStationEntityDescription( VodafoneStationEntityDescription(
key="sys_memory_usage", key="sys_memory_usage",
@ -149,7 +148,7 @@ SENSOR_TYPES: Final = (
icon="mdi:memory", icon="mdi:memory",
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
value=lambda value, key: float(value[key][:-1]), value=lambda coordinator, key: float(coordinator.data.sensors[key][:-1]),
), ),
VodafoneStationEntityDescription( VodafoneStationEntityDescription(
key="sys_reboot_cause", key="sys_reboot_cause",
@ -200,5 +199,5 @@ class VodafoneStationSensorEntity(
def native_value(self) -> StateType: def native_value(self) -> StateType:
"""Sensor value.""" """Sensor value."""
return self.entity_description.value( return self.entity_description.value(
self.coordinator.data.sensors, self.entity_description.key self.coordinator, self.entity_description.key
) )

View File

@ -375,7 +375,7 @@ aiounifi==63
aiovlc==0.1.0 aiovlc==0.1.0
# homeassistant.components.vodafone_station # homeassistant.components.vodafone_station
aiovodafone==0.3.1 aiovodafone==0.4.1
# homeassistant.components.waqi # homeassistant.components.waqi
aiowaqi==2.0.0 aiowaqi==2.0.0

View File

@ -350,7 +350,7 @@ aiounifi==63
aiovlc==0.1.0 aiovlc==0.1.0
# homeassistant.components.vodafone_station # homeassistant.components.vodafone_station
aiovodafone==0.3.1 aiovodafone==0.4.1
# homeassistant.components.waqi # homeassistant.components.waqi
aiowaqi==2.0.0 aiowaqi==2.0.0

View File

@ -18,9 +18,9 @@ from tests.common import MockConfigEntry
async def test_user(hass: HomeAssistant) -> None: async def test_user(hass: HomeAssistant) -> None:
"""Test starting a flow by user.""" """Test starting a flow by user."""
with patch( with patch(
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.login", "homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.login",
), patch( ), patch(
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.logout", "homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.logout",
), patch( ), patch(
"homeassistant.components.vodafone_station.async_setup_entry" "homeassistant.components.vodafone_station.async_setup_entry"
) as mock_setup_entry, patch( ) as mock_setup_entry, patch(
@ -67,7 +67,7 @@ async def test_exception_connection(hass: HomeAssistant, side_effect, error) ->
assert result["step_id"] == "user" assert result["step_id"] == "user"
with patch( with patch(
"aiovodafone.api.VodafoneStationApi.login", "aiovodafone.api.VodafoneStationSercommApi.login",
side_effect=side_effect, side_effect=side_effect,
): ):
result = await hass.config_entries.flow.async_configure( 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 # Should be recoverable after hits error
with patch( with patch(
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.get_devices_data", "homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.get_devices_data",
return_value={ return_value={
"wifi_user": "on|laptop|device-1|xx:xx:xx:xx:xx:xx|192.168.100.1||2.4G", "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|;", "ethernet": "laptop|device-2|yy:yy:yy:yy:yy:yy|192.168.100.2|;",
}, },
), patch( ), patch(
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.login", "homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.login",
), patch( ), patch(
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.logout", "homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.logout",
), patch( ), patch(
"homeassistant.components.vodafone_station.async_setup_entry" "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) mock_config.add_to_hass(hass)
with patch( with patch(
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.login", "homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.login",
), patch( ), patch(
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.logout", "homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.logout",
), patch( ), patch(
"homeassistant.components.vodafone_station.async_setup_entry" "homeassistant.components.vodafone_station.async_setup_entry"
), patch( ), patch(
@ -165,10 +165,10 @@ async def test_reauth_not_successful(hass: HomeAssistant, side_effect, error) ->
mock_config.add_to_hass(hass) mock_config.add_to_hass(hass)
with patch( with patch(
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.login", "homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.login",
side_effect=side_effect, side_effect=side_effect,
), patch( ), patch(
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.logout", "homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.logout",
), patch( ), patch(
"homeassistant.components.vodafone_station.async_setup_entry" "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 # Should be recoverable after hits error
with patch( with patch(
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.get_devices_data", "homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.get_devices_data",
return_value={ return_value={
"wifi_user": "on|laptop|device-1|xx:xx:xx:xx:xx:xx|192.168.100.1||2.4G", "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|;", "ethernet": "laptop|device-2|yy:yy:yy:yy:yy:yy|192.168.100.2|;",
}, },
), patch( ), patch(
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.login", "homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.login",
), patch( ), patch(
"homeassistant.components.vodafone_station.config_flow.VodafoneStationApi.logout", "homeassistant.components.vodafone_station.config_flow.VodafoneStationSercommApi.logout",
), patch( ), patch(
"homeassistant.components.vodafone_station.async_setup_entry" "homeassistant.components.vodafone_station.async_setup_entry"
): ):