mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Ignore DSL entities if SFR box is not adsl (#89291)
This commit is contained in:
parent
0b5ddd9cbf
commit
f982af2412
@ -1,13 +1,11 @@
|
|||||||
"""SFR Box."""
|
"""SFR Box."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from sfrbox_api.bridge import SFRBox
|
from sfrbox_api.bridge import SFRBox
|
||||||
from sfrbox_api.exceptions import SFRBoxAuthenticationError, SFRBoxError
|
from sfrbox_api.exceptions import SFRBoxAuthenticationError, SFRBoxError
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
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.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
from homeassistant.helpers import device_registry as dr
|
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()
|
hass, box, "system", lambda b: b.system_get_info()
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
tasks = [
|
await data.system.async_config_entry_first_refresh()
|
||||||
data.dsl.async_config_entry_first_refresh(),
|
system_info = data.system.data
|
||||||
data.system.async_config_entry_first_refresh(),
|
|
||||||
]
|
if system_info.net_infra == "adsl":
|
||||||
await asyncio.gather(*tasks)
|
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
|
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = data
|
||||||
|
|
||||||
system_info = data.system.data
|
|
||||||
device_registry = dr.async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
device_registry.async_get_or_create(
|
device_registry.async_get_or_create(
|
||||||
config_entry_id=entry.entry_id,
|
config_entry_id=entry.entry_id,
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
"""SFR Box sensor platform."""
|
"""SFR Box sensor platform."""
|
||||||
from collections.abc import Callable, Iterable
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from itertools import chain
|
|
||||||
from typing import Generic, TypeVar
|
from typing import Generic, TypeVar
|
||||||
|
|
||||||
from sfrbox_api.models import DslInfo, SystemInfo
|
from sfrbox_api.models import DslInfo, SystemInfo
|
||||||
@ -204,16 +203,15 @@ async def async_setup_entry(
|
|||||||
"""Set up the sensors."""
|
"""Set up the sensors."""
|
||||||
data: DomainData = hass.data[DOMAIN][entry.entry_id]
|
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)
|
SFRBoxSensor(data.dsl, description, data.system.data)
|
||||||
for description in DSL_SENSOR_TYPES
|
for description in DSL_SENSOR_TYPES
|
||||||
),
|
)
|
||||||
(
|
|
||||||
SFRBoxSensor(data.system, description, data.system.data)
|
|
||||||
for description in SYSTEM_SENSOR_TYPES
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
async_add_entities(entities)
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user