Ignore DSL entities if SFR box is not adsl (#89291)
parent
0b5ddd9cbf
commit
f982af2412
|
@ -1,13 +1,11 @@
|
|||
"""SFR Box."""
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
from sfrbox_api.bridge import SFRBox
|
||||
from sfrbox_api.exceptions import SFRBoxAuthenticationError, SFRBoxError
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
|
@ -40,15 +38,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
hass, box, "system", lambda b: b.system_get_info()
|
||||
),
|
||||
)
|
||||
tasks = [
|
||||
data.dsl.async_config_entry_first_refresh(),
|
||||
data.system.async_config_entry_first_refresh(),
|
||||
]
|
||||
await asyncio.gather(*tasks)
|
||||
await data.system.async_config_entry_first_refresh()
|
||||
system_info = data.system.data
|
||||
|
||||
if system_info.net_infra == "adsl":
|
||||
await data.dsl.async_config_entry_first_refresh()
|
||||
else:
|
||||
platforms = list(platforms)
|
||||
platforms.remove(Platform.BINARY_SENSOR)
|
||||
|
||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = data
|
||||
|
||||
system_info = data.system.data
|
||||
device_registry = dr.async_get(hass)
|
||||
device_registry.async_get_or_create(
|
||||
config_entry_id=entry.entry_id,
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""SFR Box sensor platform."""
|
||||
from collections.abc import Callable, Iterable
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from itertools import chain
|
||||
from typing import Generic, TypeVar
|
||||
|
||||
from sfrbox_api.models import DslInfo, SystemInfo
|
||||
|
@ -204,16 +203,15 @@ async def async_setup_entry(
|
|||
"""Set up the sensors."""
|
||||
data: DomainData = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
entities: Iterable[SFRBoxSensor] = chain(
|
||||
(
|
||||
entities: list[SFRBoxSensor] = [
|
||||
SFRBoxSensor(data.system, description, data.system.data)
|
||||
for description in SYSTEM_SENSOR_TYPES
|
||||
]
|
||||
if data.system.data.net_infra == "adsl":
|
||||
entities.extend(
|
||||
SFRBoxSensor(data.dsl, description, data.system.data)
|
||||
for description in DSL_SENSOR_TYPES
|
||||
),
|
||||
(
|
||||
SFRBoxSensor(data.system, description, data.system.data)
|
||||
for description in SYSTEM_SENSOR_TYPES
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(entities)
|
||||
|
||||
|
|
Loading…
Reference in New Issue