1 """Support for the Hitron CODA-4582U, provided by Rogers."""
3 from __future__
import annotations
5 from collections
import namedtuple
6 from http
import HTTPStatus
10 import voluptuous
as vol
13 DOMAIN
as DEVICE_TRACKER_DOMAIN,
14 PLATFORM_SCHEMA
as DEVICE_TRACKER_PLATFORM_SCHEMA,
22 _LOGGER = logging.getLogger(__name__)
24 DEFAULT_TYPE =
"rogers"
26 PLATFORM_SCHEMA = DEVICE_TRACKER_PLATFORM_SCHEMA.extend(
28 vol.Required(CONF_HOST): cv.string,
29 vol.Required(CONF_USERNAME): cv.string,
30 vol.Required(CONF_PASSWORD): cv.string,
31 vol.Optional(CONF_TYPE, default=DEFAULT_TYPE): cv.string,
37 _hass: HomeAssistant, config: ConfigType
38 ) -> HitronCODADeviceScanner |
None:
39 """Validate the configuration and return a Hitron CODA-4582U scanner."""
42 return scanner
if scanner.success_init
else None
45 Device = namedtuple(
"Device", [
"mac",
"name"])
49 """Scanner for devices using the CODA's web interface."""
52 """Initialize the scanner."""
54 host = config[CONF_HOST]
55 self.
_url_url = f
"http://{host}/data/getConnectInfo.asp"
56 self.
_loginurl_loginurl = f
"http://{host}/goform/login"
61 if config.get(CONF_TYPE) ==
"shaw":
64 self.
_type_type =
"pws"
71 """Scan for new devices and return a list with found device IDs."""
74 return [device.mac
for device
in self.
last_resultslast_results]
77 """Return the name of the device with the given MAC address."""
79 (result.name
for result
in self.
last_resultslast_results
if result.mac == device),
None
83 """Log in to the router. This is required for subsequent api calls."""
84 _LOGGER.debug(
"Logging in to CODA")
88 res = requests.post(self.
_loginurl_loginurl, data=data, timeout=10)
89 except requests.exceptions.Timeout:
90 _LOGGER.error(
"Connection to the router timed out at URL %s", self.
_url_url)
92 if res.status_code != HTTPStatus.OK:
93 _LOGGER.error(
"Connection failed with http code %s", res.status_code)
96 self.
_userid_userid = res.cookies[
"userid"]
98 _LOGGER.error(
"Failed to log in to router")
103 """Get ARP from router."""
104 _LOGGER.debug(
"Fetching")
107 _LOGGER.error(
"Could not obtain a user ID from the router")
113 res = requests.get(self.
_url_url, timeout=10, cookies={
"userid": self.
_userid_userid})
114 except requests.exceptions.Timeout:
115 _LOGGER.error(
"Connection to the router timed out at URL %s", self.
_url_url)
117 if res.status_code != HTTPStatus.OK:
118 _LOGGER.error(
"Connection failed with http code %s", res.status_code)
124 _LOGGER.error(
"Failed to parse response from router")
129 mac = info[
"macAddr"]
130 name = info[
"hostName"]
135 last_results.append(
Device(mac.upper(), name))
139 _LOGGER.debug(
"Request successful")
def __init__(self, config)
def get_device_name(self, device)
HitronCODADeviceScanner|None get_scanner(HomeAssistant _hass, ConfigType config)