mirror of
https://github.com/home-assistant/core.git
synced 2026-05-08 17:49:37 +01:00
Add base entity to sfr_box (#155418)
This commit is contained in:
@@ -6,7 +6,7 @@ from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sfrbox_api.models import DslInfo, FtthInfo, SystemInfo, WanInfo
|
||||
from sfrbox_api.models import DslInfo, FtthInfo, WanInfo
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
@@ -15,12 +15,10 @@ from homeassistant.components.binary_sensor import (
|
||||
)
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import SFRConfigEntry, SFRDataUpdateCoordinator
|
||||
from .coordinator import SFRConfigEntry
|
||||
from .entity import SFRCoordinatorEntity
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
@@ -88,29 +86,10 @@ async def async_setup_entry(
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class SFRBoxBinarySensor[_T](
|
||||
CoordinatorEntity[SFRDataUpdateCoordinator[_T]], BinarySensorEntity
|
||||
):
|
||||
"""SFR Box sensor."""
|
||||
class SFRBoxBinarySensor[_T](SFRCoordinatorEntity[_T], BinarySensorEntity):
|
||||
"""SFR Box binary sensor."""
|
||||
|
||||
entity_description: SFRBoxBinarySensorEntityDescription[_T]
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: SFRDataUpdateCoordinator[_T],
|
||||
description: SFRBoxBinarySensorEntityDescription,
|
||||
system_info: SystemInfo,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator)
|
||||
self.entity_description = description
|
||||
self._attr_unique_id = (
|
||||
f"{system_info.mac_addr}_{coordinator.name}_{description.key}"
|
||||
)
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, system_info.mac_addr)},
|
||||
)
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool | None:
|
||||
|
||||
@@ -19,11 +19,10 @@ from homeassistant.components.button import (
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import SFRConfigEntry
|
||||
from .entity import SFREntity
|
||||
|
||||
|
||||
def with_error_wrapping[**_P, _R](
|
||||
@@ -80,11 +79,10 @@ async def async_setup_entry(
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class SFRBoxButton(ButtonEntity):
|
||||
"""Mixin for button specific attributes."""
|
||||
class SFRBoxButton(SFREntity, ButtonEntity):
|
||||
"""SFR Box button."""
|
||||
|
||||
entity_description: SFRBoxButtonEntityDescription
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -92,13 +90,9 @@ class SFRBoxButton(ButtonEntity):
|
||||
description: SFRBoxButtonEntityDescription,
|
||||
system_info: SystemInfo,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
self.entity_description = description
|
||||
"""Initialize the button."""
|
||||
super().__init__(description, system_info)
|
||||
self._box = box
|
||||
self._attr_unique_id = f"{system_info.mac_addr}_{description.key}"
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, system_info.mac_addr)},
|
||||
)
|
||||
|
||||
@with_error_wrapping
|
||||
async def async_press(self) -> None:
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
"""SFR Box base entity."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from sfrbox_api.models import SystemInfo
|
||||
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity import Entity, EntityDescription
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import SFRDataUpdateCoordinator
|
||||
|
||||
|
||||
class SFREntity(Entity):
|
||||
"""SFR Box entity."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, description: EntityDescription, system_info: SystemInfo) -> None:
|
||||
"""Initialize the entity."""
|
||||
self.entity_description = description
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, system_info.mac_addr)},
|
||||
)
|
||||
self._attr_unique_id = f"{system_info.mac_addr}_{description.key}"
|
||||
|
||||
|
||||
class SFRCoordinatorEntity[_T](
|
||||
CoordinatorEntity[SFRDataUpdateCoordinator[_T]], SFREntity
|
||||
):
|
||||
"""SFR Box coordinator entity."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: SFRDataUpdateCoordinator[_T],
|
||||
description: EntityDescription,
|
||||
system_info: SystemInfo,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator)
|
||||
SFREntity.__init__(self, description, system_info)
|
||||
self._attr_unique_id = (
|
||||
f"{system_info.mac_addr}_{coordinator.name}_{description.key}"
|
||||
)
|
||||
@@ -20,13 +20,11 @@ from homeassistant.const import (
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import SFRConfigEntry, SFRDataUpdateCoordinator
|
||||
from .coordinator import SFRConfigEntry
|
||||
from .entity import SFRCoordinatorEntity
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
@@ -244,27 +242,10 @@ async def async_setup_entry(
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class SFRBoxSensor[_T](CoordinatorEntity[SFRDataUpdateCoordinator[_T]], SensorEntity):
|
||||
class SFRBoxSensor[_T](SFRCoordinatorEntity[_T], SensorEntity):
|
||||
"""SFR Box sensor."""
|
||||
|
||||
entity_description: SFRBoxSensorEntityDescription[_T]
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: SFRDataUpdateCoordinator[_T],
|
||||
description: SFRBoxSensorEntityDescription,
|
||||
system_info: SystemInfo,
|
||||
) -> None:
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(coordinator)
|
||||
self.entity_description = description
|
||||
self._attr_unique_id = (
|
||||
f"{system_info.mac_addr}_{coordinator.name}_{description.key}"
|
||||
)
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, system_info.mac_addr)},
|
||||
)
|
||||
|
||||
@property
|
||||
def native_value(self) -> StateType:
|
||||
|
||||
Reference in New Issue
Block a user