1 """Support for OpenWRT (luci) routers."""
3 from __future__
import annotations
7 from openwrt_luci_rpc
import OpenWrtRpc
8 import voluptuous
as vol
11 DOMAIN
as DEVICE_TRACKER_DOMAIN,
12 PLATFORM_SCHEMA
as DEVICE_TRACKER_PLATFORM_SCHEMA,
26 _LOGGER = logging.getLogger(__name__)
29 DEFAULT_VERIFY_SSL =
True
31 PLATFORM_SCHEMA = DEVICE_TRACKER_PLATFORM_SCHEMA.extend(
33 vol.Required(CONF_HOST): cv.string,
34 vol.Required(CONF_USERNAME): cv.string,
35 vol.Required(CONF_PASSWORD): cv.string,
36 vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean,
37 vol.Optional(CONF_VERIFY_SSL, default=DEFAULT_VERIFY_SSL): cv.boolean,
42 def get_scanner(hass: HomeAssistant, config: ConfigType) -> LuciDeviceScanner |
None:
43 """Validate the configuration and return a Luci scanner."""
46 return scanner
if scanner.success_init
else None
50 """Scanner for devices connected to an OpenWrt router."""
53 """Initialize the scanner."""
57 config[CONF_USERNAME],
58 config[CONF_PASSWORD],
60 config[CONF_VERIFY_SSL],
67 """Scan for new devices and return a list with found device IDs."""
70 return [device.mac
for device
in self.
last_resultslast_results]
73 """Return the name of the given device or None if we don't know."""
75 (result.hostname
for result
in self.
last_resultslast_results
if result.mac == device),
80 """Get extra attributes of a device.
82 Some known extra attributes that may be returned in the device tuple
83 include MAC address (mac), network device (dev), IP address
84 (ip), reachable status (reachable), associated router
85 (host), hostname if known (hostname) among others.
88 (result
for result
in self.
last_resultslast_results
if result.mac == device),
None
90 return device._asdict()
93 """Check the Luci router for devices."""
94 result = self.
routerrouter.get_all_connected_devices(only_reachable=
True)
96 _LOGGER.debug(
"Luci get_all_connected_devices returned: %s", result)
101 if not hasattr(self.
routerrouter.router.owrt_version,
"release")
102 or not self.
routerrouter.router.owrt_version.release
103 or self.
routerrouter.router.owrt_version.release[0] < 19
def get_device_name(self, device)
def __init__(self, config)
def get_extra_attributes(self, device)
LuciDeviceScanner|None get_scanner(HomeAssistant hass, ConfigType config)