Address late feedback in SFR Box sensors (#85038)

This commit is contained in:
epenet 2023-01-03 12:15:03 +01:00 committed by GitHub
parent 8a0fb21988
commit 0d290ac21e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,6 +14,7 @@ from homeassistant.components.sensor import (
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import SIGNAL_STRENGTH_DECIBELS, UnitOfDataRate from homeassistant.const import SIGNAL_STRENGTH_DECIBELS, UnitOfDataRate
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType from homeassistant.helpers.typing import StateType
from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.helpers.update_coordinator import CoordinatorEntity
@ -38,55 +39,62 @@ SENSOR_TYPES: tuple[SFRBoxSensorEntityDescription, ...] = (
SFRBoxSensorEntityDescription( SFRBoxSensorEntityDescription(
key="linemode", key="linemode",
name="Line mode", name="Line mode",
has_entity_name=True, entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
value_fn=lambda x: x.linemode, value_fn=lambda x: x.linemode,
), ),
SFRBoxSensorEntityDescription( SFRBoxSensorEntityDescription(
key="counter", key="counter",
name="Counter", name="Counter",
has_entity_name=True, entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
value_fn=lambda x: x.counter, value_fn=lambda x: x.counter,
), ),
SFRBoxSensorEntityDescription( SFRBoxSensorEntityDescription(
key="crc", key="crc",
name="CRC", name="CRC",
has_entity_name=True, entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
value_fn=lambda x: x.crc, value_fn=lambda x: x.crc,
), ),
SFRBoxSensorEntityDescription( SFRBoxSensorEntityDescription(
key="noise_down", key="noise_down",
name="Noise down", name="Noise down",
device_class=SensorDeviceClass.SIGNAL_STRENGTH, device_class=SensorDeviceClass.SIGNAL_STRENGTH,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS, native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
has_entity_name=True,
value_fn=lambda x: x.noise_down, value_fn=lambda x: x.noise_down,
), ),
SFRBoxSensorEntityDescription( SFRBoxSensorEntityDescription(
key="noise_up", key="noise_up",
name="Noise up", name="Noise up",
device_class=SensorDeviceClass.SIGNAL_STRENGTH, device_class=SensorDeviceClass.SIGNAL_STRENGTH,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS, native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
has_entity_name=True,
value_fn=lambda x: x.noise_up, value_fn=lambda x: x.noise_up,
), ),
SFRBoxSensorEntityDescription( SFRBoxSensorEntityDescription(
key="attenuation_down", key="attenuation_down",
name="Attenuation down", name="Attenuation down",
device_class=SensorDeviceClass.SIGNAL_STRENGTH, device_class=SensorDeviceClass.SIGNAL_STRENGTH,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS, native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
has_entity_name=True,
value_fn=lambda x: x.attenuation_down, value_fn=lambda x: x.attenuation_down,
), ),
SFRBoxSensorEntityDescription( SFRBoxSensorEntityDescription(
key="attenuation_up", key="attenuation_up",
name="Attenuation up", name="Attenuation up",
device_class=SensorDeviceClass.SIGNAL_STRENGTH, device_class=SensorDeviceClass.SIGNAL_STRENGTH,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS, native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
has_entity_name=True,
value_fn=lambda x: x.attenuation_up, value_fn=lambda x: x.attenuation_up,
), ),
SFRBoxSensorEntityDescription( SFRBoxSensorEntityDescription(
@ -95,7 +103,6 @@ SENSOR_TYPES: tuple[SFRBoxSensorEntityDescription, ...] = (
device_class=SensorDeviceClass.DATA_RATE, device_class=SensorDeviceClass.DATA_RATE,
native_unit_of_measurement=UnitOfDataRate.KILOBITS_PER_SECOND, native_unit_of_measurement=UnitOfDataRate.KILOBITS_PER_SECOND,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
has_entity_name=True,
value_fn=lambda x: x.rate_down, value_fn=lambda x: x.rate_down,
), ),
SFRBoxSensorEntityDescription( SFRBoxSensorEntityDescription(
@ -104,13 +111,14 @@ SENSOR_TYPES: tuple[SFRBoxSensorEntityDescription, ...] = (
device_class=SensorDeviceClass.DATA_RATE, device_class=SensorDeviceClass.DATA_RATE,
native_unit_of_measurement=UnitOfDataRate.KILOBITS_PER_SECOND, native_unit_of_measurement=UnitOfDataRate.KILOBITS_PER_SECOND,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
has_entity_name=True,
value_fn=lambda x: x.rate_up, value_fn=lambda x: x.rate_up,
), ),
SFRBoxSensorEntityDescription( SFRBoxSensorEntityDescription(
key="line_status", key="line_status",
name="Line status", name="Line status",
device_class=SensorDeviceClass.ENUM, device_class=SensorDeviceClass.ENUM,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
options=[ options=[
"No Defect", "No Defect",
"Of Frame", "Of Frame",
@ -119,13 +127,14 @@ SENSOR_TYPES: tuple[SFRBoxSensorEntityDescription, ...] = (
"Loss Of Signal Quality", "Loss Of Signal Quality",
"Unknown", "Unknown",
], ],
has_entity_name=True,
value_fn=lambda x: x.line_status, value_fn=lambda x: x.line_status,
), ),
SFRBoxSensorEntityDescription( SFRBoxSensorEntityDescription(
key="training", key="training",
name="Training", name="Training",
device_class=SensorDeviceClass.ENUM, device_class=SensorDeviceClass.ENUM,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
options=[ options=[
"Idle", "Idle",
"G.994 Training", "G.994 Training",
@ -138,7 +147,6 @@ SENSOR_TYPES: tuple[SFRBoxSensorEntityDescription, ...] = (
"Showtime", "Showtime",
"Unknown", "Unknown",
], ],
has_entity_name=True,
value_fn=lambda x: x.training, value_fn=lambda x: x.training,
), ),
) )
@ -163,6 +171,7 @@ class SFRBoxSensor(CoordinatorEntity[DslDataUpdateCoordinator], SensorEntity):
"""SFR Box sensor.""" """SFR Box sensor."""
entity_description: SFRBoxSensorEntityDescription entity_description: SFRBoxSensorEntityDescription
_attr_has_entity_name = True
def __init__( def __init__(
self, self,