1 """Support for Linksys Smart Wifi routers."""
3 from __future__
import annotations
5 from http
import HTTPStatus
9 import voluptuous
as vol
12 DOMAIN
as DEVICE_TRACKER_DOMAIN,
13 PLATFORM_SCHEMA
as DEVICE_TRACKER_PLATFORM_SCHEMA,
23 _LOGGER = logging.getLogger(__name__)
25 PLATFORM_SCHEMA = DEVICE_TRACKER_PLATFORM_SCHEMA.extend(
26 {vol.Required(CONF_HOST): cv.string}
31 hass: HomeAssistant, config: ConfigType
32 ) -> LinksysSmartWifiDeviceScanner |
None:
33 """Validate the configuration and return a Linksys AP scanner."""
36 except ConnectionError:
41 """Class which queries a Linksys Access Point."""
44 """Initialize the scanner."""
45 self.
hosthost = config[CONF_HOST]
50 if response.status_code != HTTPStatus.OK:
51 raise ConnectionError(
"Cannot connect to Linksys Access Point")
54 """Scan for new devices and return a list with device IDs (MACs)."""
60 """Return the name (if known) of the device."""
64 """Check for connected devices."""
65 _LOGGER.debug(
"Checking Linksys Smart Wifi")
69 if response.status_code != HTTPStatus.OK:
71 "Got HTTP status code %d when getting device list", response.status_code
75 data = response.json()
76 result = data[
"responses"][0]
77 devices = result[
"output"][
"devices"]
78 for device
in devices:
79 if not (macs := device[
"knownMACAddresses"]):
80 _LOGGER.warning(
"Skipping device without known MAC address")
83 if not device[
"connections"]:
84 _LOGGER.debug(
"Device %s is not connected", mac)
88 for prop
in device[
"properties"]:
89 if prop[
"name"] ==
"userDeviceName":
92 name = device.get(
"friendlyName", device[
"deviceID"])
94 _LOGGER.debug(
"Device %s is connected", mac)
96 except (KeyError, IndexError):
97 _LOGGER.exception(
"Router returned unexpected response")
105 "request": {
"sinceRevision": 0},
106 "action":
"http://linksys.com/jnap/devicelist/GetDevices",
109 headers = {
"X-JNAP-Action":
"http://linksys.com/jnap/core/Transaction"}
110 return requests.post(
111 f
"http://{self.host}/JNAP/",
112 timeout=DEFAULT_TIMEOUT,
def __init__(self, config)
def get_device_name(self, device)
web.Response get(self, web.Request request, str config_key)
LinksysSmartWifiDeviceScanner|None get_scanner(HomeAssistant hass, ConfigType config)