mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Add additional information to SynologySRM device tracker (#32669)
* Updating SynologySRM device trakcers to show additional information * Fixes * Aliasing attributes to snake case * Sugguested changes as per MartinHjelmare
This commit is contained in:
parent
4e3b079a29
commit
af021b1c81
@ -37,6 +37,34 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
}
|
||||
)
|
||||
|
||||
ATTRIBUTE_ALIAS = {
|
||||
"band": None,
|
||||
"connection": None,
|
||||
"current_rate": None,
|
||||
"dev_type": None,
|
||||
"hostname": None,
|
||||
"ip6_addr": None,
|
||||
"ip_addr": None,
|
||||
"is_baned": "is_banned",
|
||||
"is_beamforming_on": None,
|
||||
"is_guest": None,
|
||||
"is_high_qos": None,
|
||||
"is_low_qos": None,
|
||||
"is_manual_dev_type": None,
|
||||
"is_manual_hostname": None,
|
||||
"is_online": None,
|
||||
"is_parental_controled": "is_parental_controlled",
|
||||
"is_qos": None,
|
||||
"is_wireless": None,
|
||||
"mac": None,
|
||||
"max_rate": None,
|
||||
"mesh_node_id": None,
|
||||
"rate_quality": None,
|
||||
"signalstrength": "signal_strength",
|
||||
"transferRXRate": "transfer_rx_rate",
|
||||
"transferTXRate": "transfer_tx_rate",
|
||||
}
|
||||
|
||||
|
||||
def get_scanner(hass, config):
|
||||
"""Validate the configuration and return Synology SRM scanner."""
|
||||
@ -62,7 +90,7 @@ class SynologySrmDeviceScanner(DeviceScanner):
|
||||
if not config[CONF_VERIFY_SSL]:
|
||||
self.client.http.disable_https_verify()
|
||||
|
||||
self.last_results = []
|
||||
self.devices = []
|
||||
self.success_init = self._update_info()
|
||||
|
||||
_LOGGER.info("Synology SRM scanner initialized")
|
||||
@ -71,14 +99,28 @@ class SynologySrmDeviceScanner(DeviceScanner):
|
||||
"""Scan for new devices and return a list with found device IDs."""
|
||||
self._update_info()
|
||||
|
||||
return [device["mac"] for device in self.last_results]
|
||||
return [device["mac"] for device in self.devices]
|
||||
|
||||
def get_extra_attributes(self, device) -> dict:
|
||||
"""Get the extra attributes of a device."""
|
||||
device = next(
|
||||
(result for result in self.devices if result["mac"] == device), None
|
||||
)
|
||||
filtered_attributes = {}
|
||||
if not device:
|
||||
return filtered_attributes
|
||||
for attribute, alias in ATTRIBUTE_ALIAS.items():
|
||||
value = device.get(attribute)
|
||||
if value is None:
|
||||
continue
|
||||
attr = alias or attribute
|
||||
filtered_attributes[attr] = value
|
||||
return filtered_attributes
|
||||
|
||||
def get_device_name(self, device):
|
||||
"""Return the name of the given device or None if we don't know."""
|
||||
filter_named = [
|
||||
result["hostname"]
|
||||
for result in self.last_results
|
||||
if result["mac"] == device
|
||||
result["hostname"] for result in self.devices if result["mac"] == device
|
||||
]
|
||||
|
||||
if filter_named:
|
||||
@ -90,13 +132,8 @@ class SynologySrmDeviceScanner(DeviceScanner):
|
||||
"""Check the router for connected devices."""
|
||||
_LOGGER.debug("Scanning for connected devices")
|
||||
|
||||
devices = self.client.core.network_nsm_device({"is_online": True})
|
||||
last_results = []
|
||||
self.devices = self.client.core.network_nsm_device({"is_online": True})
|
||||
|
||||
for device in devices:
|
||||
last_results.append({"mac": device["mac"], "hostname": device["hostname"]})
|
||||
_LOGGER.debug("Found %d device(s) connected to the router", len(self.devices))
|
||||
|
||||
_LOGGER.debug("Found %d device(s) connected to the router", len(devices))
|
||||
|
||||
self.last_results = last_results
|
||||
return True
|
||||
|
Loading…
x
Reference in New Issue
Block a user