Add Netgear ssid and conn_ap_mac sensors (#57226)

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
starkillerOG 2021-10-11 13:08:56 +02:00 committed by GitHub
parent 9040b6a59e
commit 1fbc94f56d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 10 deletions

View File

@ -120,7 +120,7 @@ class NetgearRouter:
self.device_name = None
self.firmware_version = None
self._method_version = 1
self.method_version = 1
consider_home_int = entry.options.get(
CONF_CONSIDER_HOME, DEFAULT_CONSIDER_HOME.total_seconds()
)
@ -148,7 +148,7 @@ class NetgearRouter:
for model in MODELS_V2:
if self.model.startswith(model):
self._method_version = 2
self.method_version = 2
async def async_setup(self) -> None:
"""Set up a Netgear router."""
@ -186,7 +186,7 @@ class NetgearRouter:
async def async_get_attached_devices(self) -> list:
"""Get the devices connected to the router."""
if self._method_version == 1:
if self.method_version == 1:
return await self.hass.async_add_executor_job(
self._api.get_attached_devices
)

View File

@ -21,14 +21,11 @@ SENSOR_TYPES = {
"type": SensorEntityDescription(
key="type",
name="link type",
native_unit_of_measurement=None,
device_class=None,
),
"link_rate": SensorEntityDescription(
key="link_rate",
name="link rate",
native_unit_of_measurement="Mbps",
device_class=None,
),
"signal": SensorEntityDescription(
key="signal",
@ -36,6 +33,14 @@ SENSOR_TYPES = {
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_SIGNAL_STRENGTH,
),
"ssid": SensorEntityDescription(
key="ssid",
name="ssid",
),
"conn_ap_mac": SensorEntityDescription(
key="conn_ap_mac",
name="access point mac",
),
}
@ -45,10 +50,11 @@ async def async_setup_entry(
"""Set up device tracker for Netgear component."""
def generate_sensor_classes(router: NetgearRouter, device: dict):
return [
NetgearSensorEntity(router, device, attribute)
for attribute in ("type", "link_rate", "signal")
]
sensors = ["type", "link_rate", "signal"]
if router.method_version == 2:
sensors.extend(["ssid", "conn_ap_mac"])
return [NetgearSensorEntity(router, device, attribute) for attribute in sensors]
async_setup_netgear_entry(hass, entry, async_add_entities, generate_sensor_classes)