mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Add some huawei_lte sensor state classifications (#55601)
This commit is contained in:
parent
a035615016
commit
4c854a06d9
@ -13,6 +13,8 @@ from homeassistant.components.sensor import (
|
|||||||
DEVICE_CLASS_BATTERY,
|
DEVICE_CLASS_BATTERY,
|
||||||
DEVICE_CLASS_SIGNAL_STRENGTH,
|
DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||||
DOMAIN as SENSOR_DOMAIN,
|
DOMAIN as SENSOR_DOMAIN,
|
||||||
|
STATE_CLASS_MEASUREMENT,
|
||||||
|
STATE_CLASS_TOTAL_INCREASING,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -54,6 +56,7 @@ class SensorMeta(NamedTuple):
|
|||||||
device_class: str | None = None
|
device_class: str | None = None
|
||||||
icon: str | Callable[[StateType], str] | None = None
|
icon: str | Callable[[StateType], str] | None = None
|
||||||
unit: str | None = None
|
unit: str | None = None
|
||||||
|
state_class: str | None = None
|
||||||
enabled_default: bool = False
|
enabled_default: bool = False
|
||||||
include: re.Pattern[str] | None = None
|
include: re.Pattern[str] | None = None
|
||||||
exclude: re.Pattern[str] | None = None
|
exclude: re.Pattern[str] | None = None
|
||||||
@ -123,6 +126,7 @@ SENSOR_META: dict[str | tuple[str, str], SensorMeta] = {
|
|||||||
"mdi:signal-cellular-2",
|
"mdi:signal-cellular-2",
|
||||||
"mdi:signal-cellular-3",
|
"mdi:signal-cellular-3",
|
||||||
)[bisect((-11, -8, -5), x if x is not None else -1000)],
|
)[bisect((-11, -8, -5), x if x is not None else -1000)],
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
enabled_default=True,
|
enabled_default=True,
|
||||||
),
|
),
|
||||||
(KEY_DEVICE_SIGNAL, "rsrp"): SensorMeta(
|
(KEY_DEVICE_SIGNAL, "rsrp"): SensorMeta(
|
||||||
@ -135,6 +139,7 @@ SENSOR_META: dict[str | tuple[str, str], SensorMeta] = {
|
|||||||
"mdi:signal-cellular-2",
|
"mdi:signal-cellular-2",
|
||||||
"mdi:signal-cellular-3",
|
"mdi:signal-cellular-3",
|
||||||
)[bisect((-110, -95, -80), x if x is not None else -1000)],
|
)[bisect((-110, -95, -80), x if x is not None else -1000)],
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
enabled_default=True,
|
enabled_default=True,
|
||||||
),
|
),
|
||||||
(KEY_DEVICE_SIGNAL, "rssi"): SensorMeta(
|
(KEY_DEVICE_SIGNAL, "rssi"): SensorMeta(
|
||||||
@ -147,6 +152,7 @@ SENSOR_META: dict[str | tuple[str, str], SensorMeta] = {
|
|||||||
"mdi:signal-cellular-2",
|
"mdi:signal-cellular-2",
|
||||||
"mdi:signal-cellular-3",
|
"mdi:signal-cellular-3",
|
||||||
)[bisect((-80, -70, -60), x if x is not None else -1000)],
|
)[bisect((-80, -70, -60), x if x is not None else -1000)],
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
enabled_default=True,
|
enabled_default=True,
|
||||||
),
|
),
|
||||||
(KEY_DEVICE_SIGNAL, "sinr"): SensorMeta(
|
(KEY_DEVICE_SIGNAL, "sinr"): SensorMeta(
|
||||||
@ -159,6 +165,7 @@ SENSOR_META: dict[str | tuple[str, str], SensorMeta] = {
|
|||||||
"mdi:signal-cellular-2",
|
"mdi:signal-cellular-2",
|
||||||
"mdi:signal-cellular-3",
|
"mdi:signal-cellular-3",
|
||||||
)[bisect((0, 5, 10), x if x is not None else -1000)],
|
)[bisect((0, 5, 10), x if x is not None else -1000)],
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
enabled_default=True,
|
enabled_default=True,
|
||||||
),
|
),
|
||||||
(KEY_DEVICE_SIGNAL, "rscp"): SensorMeta(
|
(KEY_DEVICE_SIGNAL, "rscp"): SensorMeta(
|
||||||
@ -171,6 +178,7 @@ SENSOR_META: dict[str | tuple[str, str], SensorMeta] = {
|
|||||||
"mdi:signal-cellular-2",
|
"mdi:signal-cellular-2",
|
||||||
"mdi:signal-cellular-3",
|
"mdi:signal-cellular-3",
|
||||||
)[bisect((-95, -85, -75), x if x is not None else -1000)],
|
)[bisect((-95, -85, -75), x if x is not None else -1000)],
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
),
|
),
|
||||||
(KEY_DEVICE_SIGNAL, "ecio"): SensorMeta(
|
(KEY_DEVICE_SIGNAL, "ecio"): SensorMeta(
|
||||||
name="EC/IO",
|
name="EC/IO",
|
||||||
@ -182,6 +190,7 @@ SENSOR_META: dict[str | tuple[str, str], SensorMeta] = {
|
|||||||
"mdi:signal-cellular-2",
|
"mdi:signal-cellular-2",
|
||||||
"mdi:signal-cellular-3",
|
"mdi:signal-cellular-3",
|
||||||
)[bisect((-20, -10, -6), x if x is not None else -1000)],
|
)[bisect((-20, -10, -6), x if x is not None else -1000)],
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
),
|
),
|
||||||
(KEY_DEVICE_SIGNAL, "transmode"): SensorMeta(name="Transmission mode"),
|
(KEY_DEVICE_SIGNAL, "transmode"): SensorMeta(name="Transmission mode"),
|
||||||
(KEY_DEVICE_SIGNAL, "cqi0"): SensorMeta(
|
(KEY_DEVICE_SIGNAL, "cqi0"): SensorMeta(
|
||||||
@ -219,10 +228,16 @@ SENSOR_META: dict[str | tuple[str, str], SensorMeta] = {
|
|||||||
exclude=re.compile(r"^month(duration|lastcleartime)$", re.IGNORECASE)
|
exclude=re.compile(r"^month(duration|lastcleartime)$", re.IGNORECASE)
|
||||||
),
|
),
|
||||||
(KEY_MONITORING_MONTH_STATISTICS, "CurrentMonthDownload"): SensorMeta(
|
(KEY_MONITORING_MONTH_STATISTICS, "CurrentMonthDownload"): SensorMeta(
|
||||||
name="Current month download", unit=DATA_BYTES, icon="mdi:download"
|
name="Current month download",
|
||||||
|
unit=DATA_BYTES,
|
||||||
|
icon="mdi:download",
|
||||||
|
state_class=STATE_CLASS_TOTAL_INCREASING,
|
||||||
),
|
),
|
||||||
(KEY_MONITORING_MONTH_STATISTICS, "CurrentMonthUpload"): SensorMeta(
|
(KEY_MONITORING_MONTH_STATISTICS, "CurrentMonthUpload"): SensorMeta(
|
||||||
name="Current month upload", unit=DATA_BYTES, icon="mdi:upload"
|
name="Current month upload",
|
||||||
|
unit=DATA_BYTES,
|
||||||
|
icon="mdi:upload",
|
||||||
|
state_class=STATE_CLASS_TOTAL_INCREASING,
|
||||||
),
|
),
|
||||||
KEY_MONITORING_STATUS: SensorMeta(
|
KEY_MONITORING_STATUS: SensorMeta(
|
||||||
include=re.compile(
|
include=re.compile(
|
||||||
@ -257,29 +272,43 @@ SENSOR_META: dict[str | tuple[str, str], SensorMeta] = {
|
|||||||
name="Current connection duration", unit=TIME_SECONDS, icon="mdi:timer-outline"
|
name="Current connection duration", unit=TIME_SECONDS, icon="mdi:timer-outline"
|
||||||
),
|
),
|
||||||
(KEY_MONITORING_TRAFFIC_STATISTICS, "CurrentDownload"): SensorMeta(
|
(KEY_MONITORING_TRAFFIC_STATISTICS, "CurrentDownload"): SensorMeta(
|
||||||
name="Current connection download", unit=DATA_BYTES, icon="mdi:download"
|
name="Current connection download",
|
||||||
|
unit=DATA_BYTES,
|
||||||
|
icon="mdi:download",
|
||||||
|
state_class=STATE_CLASS_TOTAL_INCREASING,
|
||||||
),
|
),
|
||||||
(KEY_MONITORING_TRAFFIC_STATISTICS, "CurrentDownloadRate"): SensorMeta(
|
(KEY_MONITORING_TRAFFIC_STATISTICS, "CurrentDownloadRate"): SensorMeta(
|
||||||
name="Current download rate",
|
name="Current download rate",
|
||||||
unit=DATA_RATE_BYTES_PER_SECOND,
|
unit=DATA_RATE_BYTES_PER_SECOND,
|
||||||
icon="mdi:download",
|
icon="mdi:download",
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
),
|
),
|
||||||
(KEY_MONITORING_TRAFFIC_STATISTICS, "CurrentUpload"): SensorMeta(
|
(KEY_MONITORING_TRAFFIC_STATISTICS, "CurrentUpload"): SensorMeta(
|
||||||
name="Current connection upload", unit=DATA_BYTES, icon="mdi:upload"
|
name="Current connection upload",
|
||||||
|
unit=DATA_BYTES,
|
||||||
|
icon="mdi:upload",
|
||||||
|
state_class=STATE_CLASS_TOTAL_INCREASING,
|
||||||
),
|
),
|
||||||
(KEY_MONITORING_TRAFFIC_STATISTICS, "CurrentUploadRate"): SensorMeta(
|
(KEY_MONITORING_TRAFFIC_STATISTICS, "CurrentUploadRate"): SensorMeta(
|
||||||
name="Current upload rate",
|
name="Current upload rate",
|
||||||
unit=DATA_RATE_BYTES_PER_SECOND,
|
unit=DATA_RATE_BYTES_PER_SECOND,
|
||||||
icon="mdi:upload",
|
icon="mdi:upload",
|
||||||
|
state_class=STATE_CLASS_MEASUREMENT,
|
||||||
),
|
),
|
||||||
(KEY_MONITORING_TRAFFIC_STATISTICS, "TotalConnectTime"): SensorMeta(
|
(KEY_MONITORING_TRAFFIC_STATISTICS, "TotalConnectTime"): SensorMeta(
|
||||||
name="Total connected duration", unit=TIME_SECONDS, icon="mdi:timer-outline"
|
name="Total connected duration", unit=TIME_SECONDS, icon="mdi:timer-outline"
|
||||||
),
|
),
|
||||||
(KEY_MONITORING_TRAFFIC_STATISTICS, "TotalDownload"): SensorMeta(
|
(KEY_MONITORING_TRAFFIC_STATISTICS, "TotalDownload"): SensorMeta(
|
||||||
name="Total download", unit=DATA_BYTES, icon="mdi:download"
|
name="Total download",
|
||||||
|
unit=DATA_BYTES,
|
||||||
|
icon="mdi:download",
|
||||||
|
state_class=STATE_CLASS_TOTAL_INCREASING,
|
||||||
),
|
),
|
||||||
(KEY_MONITORING_TRAFFIC_STATISTICS, "TotalUpload"): SensorMeta(
|
(KEY_MONITORING_TRAFFIC_STATISTICS, "TotalUpload"): SensorMeta(
|
||||||
name="Total upload", unit=DATA_BYTES, icon="mdi:upload"
|
name="Total upload",
|
||||||
|
unit=DATA_BYTES,
|
||||||
|
icon="mdi:upload",
|
||||||
|
state_class=STATE_CLASS_TOTAL_INCREASING,
|
||||||
),
|
),
|
||||||
KEY_NET_CURRENT_PLMN: SensorMeta(
|
KEY_NET_CURRENT_PLMN: SensorMeta(
|
||||||
exclude=re.compile(r"^(Rat|ShortName|Spn)$", re.IGNORECASE)
|
exclude=re.compile(r"^(Rat|ShortName|Spn)$", re.IGNORECASE)
|
||||||
@ -455,6 +484,11 @@ class HuaweiLteSensor(HuaweiLteBaseEntity, SensorEntity):
|
|||||||
return icon(self.state)
|
return icon(self.state)
|
||||||
return icon
|
return icon
|
||||||
|
|
||||||
|
@property
|
||||||
|
def state_class(self) -> str | None:
|
||||||
|
"""Return sensor state class."""
|
||||||
|
return self.meta.state_class
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def entity_registry_enabled_default(self) -> bool:
|
def entity_registry_enabled_default(self) -> bool:
|
||||||
"""Return if the entity should be enabled when first added to the entity registry."""
|
"""Return if the entity should be enabled when first added to the entity registry."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user