Improve Netgear logging (#73274)
* improve logging * fix black * invert checks
This commit is contained in:
parent
b3677cdff6
commit
1dc8c085e9
1 changed files with 29 additions and 15 deletions
|
@ -5,6 +5,7 @@ from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
RestoreSensor,
|
RestoreSensor,
|
||||||
|
@ -34,6 +35,8 @@ from .const import (
|
||||||
)
|
)
|
||||||
from .router import NetgearDeviceEntity, NetgearRouter, NetgearRouterEntity
|
from .router import NetgearDeviceEntity, NetgearRouter, NetgearRouterEntity
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
SENSOR_TYPES = {
|
SENSOR_TYPES = {
|
||||||
"type": SensorEntityDescription(
|
"type": SensorEntityDescription(
|
||||||
key="type",
|
key="type",
|
||||||
|
@ -114,7 +117,7 @@ SENSOR_TRAFFIC_TYPES = [
|
||||||
native_unit_of_measurement=DATA_MEGABYTES,
|
native_unit_of_measurement=DATA_MEGABYTES,
|
||||||
icon="mdi:upload",
|
icon="mdi:upload",
|
||||||
index=0,
|
index=0,
|
||||||
value=lambda data: data[0] if data is not None else None,
|
value=lambda data: data[0],
|
||||||
),
|
),
|
||||||
NetgearSensorEntityDescription(
|
NetgearSensorEntityDescription(
|
||||||
key="NewWeekUpload",
|
key="NewWeekUpload",
|
||||||
|
@ -123,7 +126,7 @@ SENSOR_TRAFFIC_TYPES = [
|
||||||
native_unit_of_measurement=DATA_MEGABYTES,
|
native_unit_of_measurement=DATA_MEGABYTES,
|
||||||
icon="mdi:upload",
|
icon="mdi:upload",
|
||||||
index=1,
|
index=1,
|
||||||
value=lambda data: data[1] if data is not None else None,
|
value=lambda data: data[1],
|
||||||
),
|
),
|
||||||
NetgearSensorEntityDescription(
|
NetgearSensorEntityDescription(
|
||||||
key="NewWeekDownload",
|
key="NewWeekDownload",
|
||||||
|
@ -132,7 +135,7 @@ SENSOR_TRAFFIC_TYPES = [
|
||||||
native_unit_of_measurement=DATA_MEGABYTES,
|
native_unit_of_measurement=DATA_MEGABYTES,
|
||||||
icon="mdi:download",
|
icon="mdi:download",
|
||||||
index=0,
|
index=0,
|
||||||
value=lambda data: data[0] if data is not None else None,
|
value=lambda data: data[0],
|
||||||
),
|
),
|
||||||
NetgearSensorEntityDescription(
|
NetgearSensorEntityDescription(
|
||||||
key="NewWeekDownload",
|
key="NewWeekDownload",
|
||||||
|
@ -141,7 +144,7 @@ SENSOR_TRAFFIC_TYPES = [
|
||||||
native_unit_of_measurement=DATA_MEGABYTES,
|
native_unit_of_measurement=DATA_MEGABYTES,
|
||||||
icon="mdi:download",
|
icon="mdi:download",
|
||||||
index=1,
|
index=1,
|
||||||
value=lambda data: data[1] if data is not None else None,
|
value=lambda data: data[1],
|
||||||
),
|
),
|
||||||
NetgearSensorEntityDescription(
|
NetgearSensorEntityDescription(
|
||||||
key="NewMonthUpload",
|
key="NewMonthUpload",
|
||||||
|
@ -150,7 +153,7 @@ SENSOR_TRAFFIC_TYPES = [
|
||||||
native_unit_of_measurement=DATA_MEGABYTES,
|
native_unit_of_measurement=DATA_MEGABYTES,
|
||||||
icon="mdi:upload",
|
icon="mdi:upload",
|
||||||
index=0,
|
index=0,
|
||||||
value=lambda data: data[0] if data is not None else None,
|
value=lambda data: data[0],
|
||||||
),
|
),
|
||||||
NetgearSensorEntityDescription(
|
NetgearSensorEntityDescription(
|
||||||
key="NewMonthUpload",
|
key="NewMonthUpload",
|
||||||
|
@ -159,7 +162,7 @@ SENSOR_TRAFFIC_TYPES = [
|
||||||
native_unit_of_measurement=DATA_MEGABYTES,
|
native_unit_of_measurement=DATA_MEGABYTES,
|
||||||
icon="mdi:upload",
|
icon="mdi:upload",
|
||||||
index=1,
|
index=1,
|
||||||
value=lambda data: data[1] if data is not None else None,
|
value=lambda data: data[1],
|
||||||
),
|
),
|
||||||
NetgearSensorEntityDescription(
|
NetgearSensorEntityDescription(
|
||||||
key="NewMonthDownload",
|
key="NewMonthDownload",
|
||||||
|
@ -168,7 +171,7 @@ SENSOR_TRAFFIC_TYPES = [
|
||||||
native_unit_of_measurement=DATA_MEGABYTES,
|
native_unit_of_measurement=DATA_MEGABYTES,
|
||||||
icon="mdi:download",
|
icon="mdi:download",
|
||||||
index=0,
|
index=0,
|
||||||
value=lambda data: data[0] if data is not None else None,
|
value=lambda data: data[0],
|
||||||
),
|
),
|
||||||
NetgearSensorEntityDescription(
|
NetgearSensorEntityDescription(
|
||||||
key="NewMonthDownload",
|
key="NewMonthDownload",
|
||||||
|
@ -177,7 +180,7 @@ SENSOR_TRAFFIC_TYPES = [
|
||||||
native_unit_of_measurement=DATA_MEGABYTES,
|
native_unit_of_measurement=DATA_MEGABYTES,
|
||||||
icon="mdi:download",
|
icon="mdi:download",
|
||||||
index=1,
|
index=1,
|
||||||
value=lambda data: data[1] if data is not None else None,
|
value=lambda data: data[1],
|
||||||
),
|
),
|
||||||
NetgearSensorEntityDescription(
|
NetgearSensorEntityDescription(
|
||||||
key="NewLastMonthUpload",
|
key="NewLastMonthUpload",
|
||||||
|
@ -186,7 +189,7 @@ SENSOR_TRAFFIC_TYPES = [
|
||||||
native_unit_of_measurement=DATA_MEGABYTES,
|
native_unit_of_measurement=DATA_MEGABYTES,
|
||||||
icon="mdi:upload",
|
icon="mdi:upload",
|
||||||
index=0,
|
index=0,
|
||||||
value=lambda data: data[0] if data is not None else None,
|
value=lambda data: data[0],
|
||||||
),
|
),
|
||||||
NetgearSensorEntityDescription(
|
NetgearSensorEntityDescription(
|
||||||
key="NewLastMonthUpload",
|
key="NewLastMonthUpload",
|
||||||
|
@ -195,7 +198,7 @@ SENSOR_TRAFFIC_TYPES = [
|
||||||
native_unit_of_measurement=DATA_MEGABYTES,
|
native_unit_of_measurement=DATA_MEGABYTES,
|
||||||
icon="mdi:upload",
|
icon="mdi:upload",
|
||||||
index=1,
|
index=1,
|
||||||
value=lambda data: data[1] if data is not None else None,
|
value=lambda data: data[1],
|
||||||
),
|
),
|
||||||
NetgearSensorEntityDescription(
|
NetgearSensorEntityDescription(
|
||||||
key="NewLastMonthDownload",
|
key="NewLastMonthDownload",
|
||||||
|
@ -204,7 +207,7 @@ SENSOR_TRAFFIC_TYPES = [
|
||||||
native_unit_of_measurement=DATA_MEGABYTES,
|
native_unit_of_measurement=DATA_MEGABYTES,
|
||||||
icon="mdi:download",
|
icon="mdi:download",
|
||||||
index=0,
|
index=0,
|
||||||
value=lambda data: data[0] if data is not None else None,
|
value=lambda data: data[0],
|
||||||
),
|
),
|
||||||
NetgearSensorEntityDescription(
|
NetgearSensorEntityDescription(
|
||||||
key="NewLastMonthDownload",
|
key="NewLastMonthDownload",
|
||||||
|
@ -213,7 +216,7 @@ SENSOR_TRAFFIC_TYPES = [
|
||||||
native_unit_of_measurement=DATA_MEGABYTES,
|
native_unit_of_measurement=DATA_MEGABYTES,
|
||||||
icon="mdi:download",
|
icon="mdi:download",
|
||||||
index=1,
|
index=1,
|
||||||
value=lambda data: data[1] if data is not None else None,
|
value=lambda data: data[1],
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -372,6 +375,17 @@ class NetgearRouterSensorEntity(NetgearRouterEntity, RestoreSensor):
|
||||||
@callback
|
@callback
|
||||||
def async_update_device(self) -> None:
|
def async_update_device(self) -> None:
|
||||||
"""Update the Netgear device."""
|
"""Update the Netgear device."""
|
||||||
if self.coordinator.data is not None:
|
if self.coordinator.data is None:
|
||||||
data = self.coordinator.data.get(self.entity_description.key)
|
return
|
||||||
self._value = self.entity_description.value(data)
|
|
||||||
|
data = self.coordinator.data.get(self.entity_description.key)
|
||||||
|
if data is None:
|
||||||
|
self._value = None
|
||||||
|
_LOGGER.debug(
|
||||||
|
"key '%s' not in Netgear router response '%s'",
|
||||||
|
self.entity_description.key,
|
||||||
|
data,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
self._value = self.entity_description.value(data)
|
||||||
|
|
Loading…
Add table
Reference in a new issue