1 """Device tracker for Synology SRM routers."""
3 from __future__
import annotations
8 import voluptuous
as vol
11 DOMAIN
as DEVICE_TRACKER_DOMAIN,
12 PLATFORM_SCHEMA
as DEVICE_TRACKER_PLATFORM_SCHEMA,
27 _LOGGER = logging.getLogger(__name__)
29 DEFAULT_USERNAME =
"admin"
32 DEFAULT_VERIFY_SSL =
False
34 PLATFORM_SCHEMA = DEVICE_TRACKER_PLATFORM_SCHEMA.extend(
36 vol.Required(CONF_HOST): cv.string,
37 vol.Required(CONF_USERNAME, default=DEFAULT_USERNAME): cv.string,
38 vol.Required(CONF_PASSWORD): cv.string,
39 vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
40 vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean,
41 vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL): cv.boolean,
53 "is_baned":
"is_banned",
54 "is_beamforming_on":
None,
58 "is_manual_dev_type":
None,
59 "is_manual_hostname":
None,
61 "is_parental_controled":
"is_parental_controlled",
68 "signalstrength":
"signal_strength",
69 "transferRXRate":
"transfer_rx_rate",
70 "transferTXRate":
"transfer_tx_rate",
75 hass: HomeAssistant, config: ConfigType
76 ) -> SynologySrmDeviceScanner |
None:
77 """Validate the configuration and return Synology SRM scanner."""
80 return scanner
if scanner.success_init
else None
84 """Scanner for devices connected to a Synology SRM router."""
87 """Initialize the scanner."""
89 self.
clientclient = synology_srm.Client(
90 host=config[CONF_HOST],
91 port=config[CONF_PORT],
92 username=config[CONF_USERNAME],
93 password=config[CONF_PASSWORD],
94 https=config[CONF_SSL],
97 if not config[CONF_VERIFY_SSL]:
98 self.
clientclient.http.disable_https_verify()
104 """Scan for new devices and return a list with found device IDs."""
107 return [device[
"mac"]
for device
in self.
devicesdevices]
110 """Get the extra attributes of a device."""
112 (result
for result
in self.
devicesdevices
if result[
"mac"] == device),
None
114 filtered_attributes: dict[str, str] = {}
116 return filtered_attributes
117 for attribute, alias
in ATTRIBUTE_ALIAS.items():
118 if (value := device.get(attribute))
is None:
120 attr = alias
or attribute
121 filtered_attributes[attr] = value
122 return filtered_attributes
125 """Return the name of the given device or None if we don't know."""
127 result[
"hostname"]
for result
in self.
devicesdevices
if result[
"mac"] == device
131 return filter_named[0]
136 """Check the router for connected devices."""
137 _LOGGER.debug(
"Scanning for connected devices")
140 self.
devicesdevices = self.
clientclient.core.get_network_nsm_device({
"is_online":
True})
141 except synology_srm.http.SynologyException
as ex:
142 _LOGGER.error(
"Error with the Synology SRM: %s", ex)
145 _LOGGER.debug(
"Found %d device(s) connected to the router", len(self.
devicesdevices))
def __init__(self, config)
def get_device_name(self, device)
dict get_extra_attributes(self, device)
SynologySrmDeviceScanner|None get_scanner(HomeAssistant hass, ConfigType config)