mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Add FTTH information to SFR Box (#89781)
This commit is contained in:
parent
49f08ad71d
commit
18df3a22ca
@ -36,6 +36,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
data = DomainData(
|
||||
box=box,
|
||||
dsl=SFRDataUpdateCoordinator(hass, box, "dsl", lambda b: b.dsl_get_info()),
|
||||
ftth=SFRDataUpdateCoordinator(hass, box, "ftth", lambda b: b.ftth_get_info()),
|
||||
system=SFRDataUpdateCoordinator(
|
||||
hass, box, "system", lambda b: b.system_get_info()
|
||||
),
|
||||
@ -47,8 +48,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
||||
# Preload other coordinators (based on net infrastructure)
|
||||
tasks = [data.wan.async_config_entry_first_refresh()]
|
||||
if system_info.net_infra == "adsl":
|
||||
if (net_infra := system_info.net_infra) == "adsl":
|
||||
tasks.append(data.dsl.async_config_entry_first_refresh())
|
||||
elif net_infra == "ftth":
|
||||
tasks.append(data.ftth.async_config_entry_first_refresh())
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = data
|
||||
|
@ -5,7 +5,7 @@ from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from typing import Generic, TypeVar
|
||||
|
||||
from sfrbox_api.models import DslInfo, SystemInfo, WanInfo
|
||||
from sfrbox_api.models import DslInfo, FtthInfo, SystemInfo, WanInfo
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
@ -48,6 +48,15 @@ DSL_SENSOR_TYPES: tuple[SFRBoxBinarySensorEntityDescription[DslInfo], ...] = (
|
||||
value_fn=lambda x: x.status == "up",
|
||||
),
|
||||
)
|
||||
FTTH_SENSOR_TYPES: tuple[SFRBoxBinarySensorEntityDescription[FtthInfo], ...] = (
|
||||
SFRBoxBinarySensorEntityDescription[FtthInfo](
|
||||
key="status",
|
||||
name="FTTH status",
|
||||
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value_fn=lambda x: x.status == "up",
|
||||
),
|
||||
)
|
||||
WAN_SENSOR_TYPES: tuple[SFRBoxBinarySensorEntityDescription[WanInfo], ...] = (
|
||||
SFRBoxBinarySensorEntityDescription[WanInfo](
|
||||
key="status",
|
||||
@ -69,11 +78,16 @@ async def async_setup_entry(
|
||||
SFRBoxBinarySensor(data.wan, description, data.system.data)
|
||||
for description in WAN_SENSOR_TYPES
|
||||
]
|
||||
if data.system.data.net_infra == "adsl":
|
||||
if (net_infra := data.system.data.net_infra) == "adsl":
|
||||
entities.extend(
|
||||
SFRBoxBinarySensor(data.dsl, description, data.system.data)
|
||||
for description in DSL_SENSOR_TYPES
|
||||
)
|
||||
elif net_infra == "ftth":
|
||||
entities.extend(
|
||||
SFRBoxBinarySensor(data.ftth, description, data.system.data)
|
||||
for description in FTTH_SENSOR_TYPES
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
from sfrbox_api.bridge import SFRBox
|
||||
from sfrbox_api.models import DslInfo, SystemInfo, WanInfo
|
||||
from sfrbox_api.models import DslInfo, FtthInfo, SystemInfo, WanInfo
|
||||
|
||||
from .coordinator import SFRDataUpdateCoordinator
|
||||
|
||||
@ -13,5 +13,6 @@ class DomainData:
|
||||
|
||||
box: SFRBox
|
||||
dsl: SFRDataUpdateCoordinator[DslInfo]
|
||||
ftth: SFRDataUpdateCoordinator[FtthInfo]
|
||||
system: SFRDataUpdateCoordinator[SystemInfo]
|
||||
wan: SFRDataUpdateCoordinator[WanInfo]
|
||||
|
@ -1,5 +1,5 @@
|
||||
# serializer version: 1
|
||||
# name: test_binary_sensors
|
||||
# name: test_binary_sensors[adsl]
|
||||
list([
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
@ -28,7 +28,7 @@
|
||||
}),
|
||||
])
|
||||
# ---
|
||||
# name: test_binary_sensors.1
|
||||
# name: test_binary_sensors[adsl].1
|
||||
list([
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
@ -88,7 +88,7 @@
|
||||
}),
|
||||
])
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.sfr_box_dsl_status]
|
||||
# name: test_binary_sensors[adsl][binary_sensor.sfr_box_dsl_status]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'connectivity',
|
||||
@ -101,7 +101,122 @@
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[binary_sensor.sfr_box_wan_status]
|
||||
# name: test_binary_sensors[adsl][binary_sensor.sfr_box_wan_status]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'connectivity',
|
||||
'friendly_name': 'SFR Box WAN status',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.sfr_box_wan_status',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[ftth]
|
||||
list([
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': 'http://192.168.0.1',
|
||||
'connections': set({
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': None,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'sfr_box',
|
||||
'e4:5d:51:00:11:22',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'manufacturer': None,
|
||||
'model': 'NB6VAC-FXC-r0',
|
||||
'name': 'SFR Box',
|
||||
'name_by_user': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': 'NB6VAC-MAIN-R4.0.44k',
|
||||
'via_device_id': None,
|
||||
}),
|
||||
])
|
||||
# ---
|
||||
# name: test_binary_sensors[ftth].1
|
||||
list([
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'binary_sensor.sfr_box_wan_status',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.CONNECTIVITY: 'connectivity'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'WAN status',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'e4:5d:51:00:11:22_wan_status',
|
||||
'unit_of_measurement': None,
|
||||
}),
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'binary_sensor.sfr_box_ftth_status',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.CONNECTIVITY: 'connectivity'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'FTTH status',
|
||||
'platform': 'sfr_box',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'e4:5d:51:00:11:22_ftth_status',
|
||||
'unit_of_measurement': None,
|
||||
}),
|
||||
])
|
||||
# ---
|
||||
# name: test_binary_sensors[ftth][binary_sensor.sfr_box_ftth_status]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'connectivity',
|
||||
'friendly_name': 'SFR Box FTTH status',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.sfr_box_ftth_status',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensors[ftth][binary_sensor.sfr_box_wan_status]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'connectivity',
|
||||
|
@ -3,6 +3,7 @@ from collections.abc import Generator
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from sfrbox_api.models import SystemInfo
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
@ -10,7 +11,9 @@ from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("system_get_info", "dsl_get_info", "wan_get_info")
|
||||
pytestmark = pytest.mark.usefixtures(
|
||||
"system_get_info", "dsl_get_info", "ftth_get_info", "wan_get_info"
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@ -20,14 +23,18 @@ def override_platforms() -> Generator[None, None, None]:
|
||||
yield
|
||||
|
||||
|
||||
@pytest.mark.parametrize("net_infra", ["adsl", "ftth"])
|
||||
async def test_binary_sensors(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
system_get_info: SystemInfo,
|
||||
net_infra: str,
|
||||
) -> None:
|
||||
"""Test for SFR Box binary sensors."""
|
||||
system_get_info.net_infra = net_infra
|
||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user