Huawei LTE misc improvements (#26203)
* Constant and whitespace cleanups * Upgrade huawei_lte_api to 1.3.0 https://github.com/Salamek/huawei-lte-api/releases * Hush traceback if device does not support logout
This commit is contained in:
1 parent
bde572c91a
commit
0c49c82015
9 files changed
+80
-46
No files matched your search
@@ -1,4 +1,5 @@
|
||||
"""Support for Huawei LTE sensors."""
|
||||
|
||||
import logging
|
||||
import re
|
||||
from typing import Optional
|
||||
@@ -15,7 +16,14 @@ from homeassistant.helpers import entity_registry
|
||||
from homeassistant.helpers.entity import Entity
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
from . import DATA_KEY, RouterData
|
||||
from . import RouterData
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
KEY_DEVICE_INFORMATION,
|
||||
KEY_DEVICE_SIGNAL,
|
||||
KEY_MONITORING_TRAFFIC_STATISTICS,
|
||||
)
|
||||
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -23,26 +31,30 @@ DEFAULT_NAME_TEMPLATE = "Huawei {} {}"
|
||||
DEFAULT_DEVICE_NAME = "LTE"
|
||||
|
||||
DEFAULT_SENSORS = [
|
||||
"device_information.WanIPAddress",
|
||||
"device_signal.rsrq",
|
||||
"device_signal.rsrp",
|
||||
"device_signal.rssi",
|
||||
"device_signal.sinr",
|
||||
f"{KEY_DEVICE_INFORMATION}.WanIPAddress",
|
||||
f"{KEY_DEVICE_SIGNAL}.rsrq",
|
||||
f"{KEY_DEVICE_SIGNAL}.rsrp",
|
||||
f"{KEY_DEVICE_SIGNAL}.rssi",
|
||||
f"{KEY_DEVICE_SIGNAL}.sinr",
|
||||
]
|
||||
|
||||
SENSOR_META = {
|
||||
"device_information.SoftwareVersion": dict(name="Software version"),
|
||||
"device_information.WanIPAddress": dict(name="WAN IP address", icon="mdi:ip"),
|
||||
"device_information.WanIPv6Address": dict(name="WAN IPv6 address", icon="mdi:ip"),
|
||||
"device_signal.band": dict(name="Band"),
|
||||
"device_signal.cell_id": dict(name="Cell ID"),
|
||||
"device_signal.lac": dict(name="LAC"),
|
||||
"device_signal.mode": dict(
|
||||
f"{KEY_DEVICE_INFORMATION}.SoftwareVersion": dict(name="Software version"),
|
||||
f"{KEY_DEVICE_INFORMATION}.WanIPAddress": dict(
|
||||
name="WAN IP address", icon="mdi:ip"
|
||||
),
|
||||
f"{KEY_DEVICE_INFORMATION}.WanIPv6Address": dict(
|
||||
name="WAN IPv6 address", icon="mdi:ip"
|
||||
),
|
||||
f"{KEY_DEVICE_SIGNAL}.band": dict(name="Band"),
|
||||
f"{KEY_DEVICE_SIGNAL}.cell_id": dict(name="Cell ID"),
|
||||
f"{KEY_DEVICE_SIGNAL}.lac": dict(name="LAC"),
|
||||
f"{KEY_DEVICE_SIGNAL}.mode": dict(
|
||||
name="Mode",
|
||||
formatter=lambda x: ({"0": "2G", "2": "3G", "7": "4G"}.get(x, "Unknown"), None),
|
||||
),
|
||||
"device_signal.pci": dict(name="PCI"),
|
||||
"device_signal.rsrq": dict(
|
||||
f"{KEY_DEVICE_SIGNAL}.pci": dict(name="PCI"),
|
||||
f"{KEY_DEVICE_SIGNAL}.rsrq": dict(
|
||||
name="RSRQ",
|
||||
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
# http://www.lte-anbieter.info/technik/rsrq.php
|
||||
@@ -54,7 +66,7 @@ SENSOR_META = {
|
||||
and "mdi:signal-cellular-2"
|
||||
or "mdi:signal-cellular-3",
|
||||
),
|
||||
"device_signal.rsrp": dict(
|
||||
f"{KEY_DEVICE_SIGNAL}.rsrp": dict(
|
||||
name="RSRP",
|
||||
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
# http://www.lte-anbieter.info/technik/rsrp.php
|
||||
@@ -66,7 +78,7 @@ SENSOR_META = {
|
||||
and "mdi:signal-cellular-2"
|
||||
or "mdi:signal-cellular-3",
|
||||
),
|
||||
"device_signal.rssi": dict(
|
||||
f"{KEY_DEVICE_SIGNAL}.rssi": dict(
|
||||
name="RSSI",
|
||||
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
# https://eyesaas.com/wi-fi-signal-strength/
|
||||
@@ -78,7 +90,7 @@ SENSOR_META = {
|
||||
and "mdi:signal-cellular-2"
|
||||
or "mdi:signal-cellular-3",
|
||||
),
|
||||
"device_signal.sinr": dict(
|
||||
f"{KEY_DEVICE_SIGNAL}.sinr": dict(
|
||||
name="SINR",
|
||||
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
# http://www.lte-anbieter.info/technik/sinr.php
|
||||
@@ -104,11 +116,11 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Set up Huawei LTE sensor devices."""
|
||||
data = hass.data[DATA_KEY].get_data(config)
|
||||
data = hass.data[DOMAIN].get_data(config)
|
||||
sensors = []
|
||||
for path in config.get(CONF_MONITORED_CONDITIONS):
|
||||
if path == "traffic_statistics": # backwards compatibility
|
||||
path = "monitoring_traffic_statistics"
|
||||
path = KEY_MONITORING_TRAFFIC_STATISTICS
|
||||
data.subscribe(path)
|
||||
sensors.append(HuaweiLteSensor(data, path, SENSOR_META.get(path, {})))
|
||||
|
||||
@@ -119,7 +131,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||
# *_d.e.v.i.c.e._.s.i.g.n.a.l...s.i.n.r
|
||||
entreg = await entity_registry.async_get_registry(hass)
|
||||
for entid, ent in entreg.entities.items():
|
||||
if ent.platform != "huawei_lte":
|
||||
if ent.platform != DOMAIN:
|
||||
continue
|
||||
for sensor in sensors:
|
||||
oldsuf = ".".join(sensor.path)
|
||||
@@ -169,7 +181,7 @@ class HuaweiLteSensor(Entity):
|
||||
def name(self) -> str:
|
||||
"""Return sensor name."""
|
||||
try:
|
||||
dname = self.data["device_information.DeviceName"]
|
||||
dname = self.data[f"{KEY_DEVICE_INFORMATION}.DeviceName"]
|
||||
except KeyError:
|
||||
dname = None
|
||||
vname = self.meta.get("name", self.path)
|
||||
|
||||
Reference in new issue
Block a user