Fix management of Fritz repeaters (#63110)
parent
a2b611d9d9
commit
fc02260146
|
@ -1,6 +1,7 @@
|
||||||
"""AVM FRITZ!Box connectivity sensor."""
|
"""AVM FRITZ!Box connectivity sensor."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
|
@ -14,29 +15,37 @@ from homeassistant.helpers.entity import EntityCategory
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .common import FritzBoxBaseEntity, FritzBoxTools
|
from .common import FritzBoxBaseEntity, FritzBoxTools
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN, MeshRoles
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
|
@dataclass
|
||||||
BinarySensorEntityDescription(
|
class FritzBinarySensorEntityDescription(BinarySensorEntityDescription):
|
||||||
|
"""Describes Fritz sensor entity."""
|
||||||
|
|
||||||
|
exclude_mesh_role: MeshRoles = MeshRoles.SLAVE
|
||||||
|
|
||||||
|
|
||||||
|
SENSOR_TYPES: tuple[FritzBinarySensorEntityDescription, ...] = (
|
||||||
|
FritzBinarySensorEntityDescription(
|
||||||
key="is_connected",
|
key="is_connected",
|
||||||
name="Connection",
|
name="Connection",
|
||||||
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
),
|
),
|
||||||
BinarySensorEntityDescription(
|
FritzBinarySensorEntityDescription(
|
||||||
key="is_linked",
|
key="is_linked",
|
||||||
name="Link",
|
name="Link",
|
||||||
device_class=BinarySensorDeviceClass.PLUG,
|
device_class=BinarySensorDeviceClass.PLUG,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
),
|
),
|
||||||
BinarySensorEntityDescription(
|
FritzBinarySensorEntityDescription(
|
||||||
key="firmware_update",
|
key="firmware_update",
|
||||||
name="Firmware Update",
|
name="Firmware Update",
|
||||||
device_class=BinarySensorDeviceClass.UPDATE,
|
device_class=BinarySensorDeviceClass.UPDATE,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
exclude_mesh_role=MeshRoles.NONE,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -48,16 +57,10 @@ async def async_setup_entry(
|
||||||
_LOGGER.debug("Setting up FRITZ!Box binary sensors")
|
_LOGGER.debug("Setting up FRITZ!Box binary sensors")
|
||||||
fritzbox_tools: FritzBoxTools = hass.data[DOMAIN][entry.entry_id]
|
fritzbox_tools: FritzBoxTools = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
|
||||||
if (
|
|
||||||
not fritzbox_tools.connection
|
|
||||||
or "WANIPConn1" not in fritzbox_tools.connection.services
|
|
||||||
):
|
|
||||||
# Only routers are supported at the moment
|
|
||||||
return
|
|
||||||
|
|
||||||
entities = [
|
entities = [
|
||||||
FritzBoxBinarySensor(fritzbox_tools, entry.title, description)
|
FritzBoxBinarySensor(fritzbox_tools, entry.title, description)
|
||||||
for description in SENSOR_TYPES
|
for description in SENSOR_TYPES
|
||||||
|
if (description.exclude_mesh_role != fritzbox_tools.mesh_role)
|
||||||
]
|
]
|
||||||
|
|
||||||
async_add_entities(entities, True)
|
async_add_entities(entities, True)
|
||||||
|
@ -82,13 +85,13 @@ class FritzBoxBinarySensor(FritzBoxBaseEntity, BinarySensorEntity):
|
||||||
"""Update data."""
|
"""Update data."""
|
||||||
_LOGGER.debug("Updating FRITZ!Box binary sensors")
|
_LOGGER.debug("Updating FRITZ!Box binary sensors")
|
||||||
|
|
||||||
if self.entity_description.key == "is_connected":
|
if self.entity_description.key == "firmware_update":
|
||||||
self._attr_is_on = bool(self._fritzbox_tools.fritz_status.is_connected)
|
|
||||||
elif self.entity_description.key == "is_linked":
|
|
||||||
self._attr_is_on = bool(self._fritzbox_tools.fritz_status.is_linked)
|
|
||||||
elif self.entity_description.key == "firmware_update":
|
|
||||||
self._attr_is_on = self._fritzbox_tools.update_available
|
self._attr_is_on = self._fritzbox_tools.update_available
|
||||||
self._attr_extra_state_attributes = {
|
self._attr_extra_state_attributes = {
|
||||||
"installed_version": self._fritzbox_tools.current_firmware,
|
"installed_version": self._fritzbox_tools.current_firmware,
|
||||||
"latest_available_version": self._fritzbox_tools.latest_firmware,
|
"latest_available_version": self._fritzbox_tools.latest_firmware,
|
||||||
}
|
}
|
||||||
|
if self.entity_description.key == "is_connected":
|
||||||
|
self._attr_is_on = bool(self._fritzbox_tools.fritz_status.is_connected)
|
||||||
|
elif self.entity_description.key == "is_linked":
|
||||||
|
self._attr_is_on = bool(self._fritzbox_tools.fritz_status.is_linked)
|
||||||
|
|
|
@ -35,7 +35,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
from .common import FritzBoxBaseEntity, FritzBoxTools
|
from .common import FritzBoxBaseEntity, FritzBoxTools
|
||||||
from .const import DOMAIN, DSL_CONNECTION, UPTIME_DEVIATION
|
from .const import DOMAIN, DSL_CONNECTION, UPTIME_DEVIATION, MeshRoles
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -152,6 +152,7 @@ class FritzSensorEntityDescription(SensorEntityDescription, FritzRequireKeysMixi
|
||||||
"""Describes Fritz sensor entity."""
|
"""Describes Fritz sensor entity."""
|
||||||
|
|
||||||
connection_type: Literal["dsl"] | None = None
|
connection_type: Literal["dsl"] | None = None
|
||||||
|
exclude_mesh_role: MeshRoles = MeshRoles.SLAVE
|
||||||
|
|
||||||
|
|
||||||
SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
|
SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
|
||||||
|
@ -167,6 +168,7 @@ SENSOR_TYPES: tuple[FritzSensorEntityDescription, ...] = (
|
||||||
device_class=SensorDeviceClass.TIMESTAMP,
|
device_class=SensorDeviceClass.TIMESTAMP,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
value_fn=_retrieve_device_uptime_state,
|
value_fn=_retrieve_device_uptime_state,
|
||||||
|
exclude_mesh_role=MeshRoles.NONE,
|
||||||
),
|
),
|
||||||
FritzSensorEntityDescription(
|
FritzSensorEntityDescription(
|
||||||
key="connection_uptime",
|
key="connection_uptime",
|
||||||
|
@ -281,13 +283,6 @@ async def async_setup_entry(
|
||||||
_LOGGER.debug("Setting up FRITZ!Box sensors")
|
_LOGGER.debug("Setting up FRITZ!Box sensors")
|
||||||
fritzbox_tools: FritzBoxTools = hass.data[DOMAIN][entry.entry_id]
|
fritzbox_tools: FritzBoxTools = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
|
||||||
if (
|
|
||||||
not fritzbox_tools.connection
|
|
||||||
or "WANIPConn1" not in fritzbox_tools.connection.services
|
|
||||||
):
|
|
||||||
# Only routers are supported at the moment
|
|
||||||
return
|
|
||||||
|
|
||||||
dsl: bool = False
|
dsl: bool = False
|
||||||
try:
|
try:
|
||||||
dslinterface = await hass.async_add_executor_job(
|
dslinterface = await hass.async_add_executor_job(
|
||||||
|
@ -307,7 +302,8 @@ async def async_setup_entry(
|
||||||
entities = [
|
entities = [
|
||||||
FritzBoxSensor(fritzbox_tools, entry.title, description)
|
FritzBoxSensor(fritzbox_tools, entry.title, description)
|
||||||
for description in SENSOR_TYPES
|
for description in SENSOR_TYPES
|
||||||
if dsl or description.connection_type != DSL_CONNECTION
|
if (dsl or description.connection_type != DSL_CONNECTION)
|
||||||
|
and description.exclude_mesh_role != fritzbox_tools.mesh_role
|
||||||
]
|
]
|
||||||
|
|
||||||
async_add_entities(entities, True)
|
async_add_entities(entities, True)
|
||||||
|
|
|
@ -39,6 +39,7 @@ from .const import (
|
||||||
SWITCH_TYPE_DEFLECTION,
|
SWITCH_TYPE_DEFLECTION,
|
||||||
SWITCH_TYPE_PORTFORWARD,
|
SWITCH_TYPE_PORTFORWARD,
|
||||||
SWITCH_TYPE_WIFINETWORK,
|
SWITCH_TYPE_WIFINETWORK,
|
||||||
|
MeshRoles,
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -310,6 +311,10 @@ def all_entities_list(
|
||||||
local_ip: str,
|
local_ip: str,
|
||||||
) -> list[Entity]:
|
) -> list[Entity]:
|
||||||
"""Get a list of all entities."""
|
"""Get a list of all entities."""
|
||||||
|
|
||||||
|
if fritzbox_tools.mesh_role == MeshRoles.SLAVE:
|
||||||
|
return []
|
||||||
|
|
||||||
return [
|
return [
|
||||||
*deflection_entities_list(fritzbox_tools, device_friendly_name),
|
*deflection_entities_list(fritzbox_tools, device_friendly_name),
|
||||||
*port_entities_list(fritzbox_tools, device_friendly_name, local_ip),
|
*port_entities_list(fritzbox_tools, device_friendly_name, local_ip),
|
||||||
|
|
Loading…
Reference in New Issue