2019-04-03 15:40:03 +00:00
|
|
|
"""Support for Verizon FiOS Quantum Gateways."""
|
2022-01-10 22:42:39 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2018-10-10 06:23:31 +00:00
|
|
|
import logging
|
|
|
|
|
2019-12-02 23:56:08 +00:00
|
|
|
from quantum_gateway import QuantumGatewayScanner
|
2018-10-10 06:23:31 +00:00
|
|
|
from requests.exceptions import RequestException
|
|
|
|
import voluptuous as vol
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
from homeassistant.components.device_tracker import (
|
|
|
|
DOMAIN,
|
2021-05-21 11:08:40 +00:00
|
|
|
PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
|
2019-07-31 19:25:30 +00:00
|
|
|
DeviceScanner,
|
|
|
|
)
|
|
|
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_SSL
|
2022-01-10 22:42:39 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2018-10-10 06:23:31 +00:00
|
|
|
import homeassistant.helpers.config_validation as cv
|
2022-01-10 22:42:39 +00:00
|
|
|
from homeassistant.helpers.typing import ConfigType
|
2018-10-10 06:23:31 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
DEFAULT_HOST = "myfiosgateway.com"
|
2018-10-10 06:23:31 +00:00
|
|
|
|
2021-05-21 11:08:40 +00:00
|
|
|
PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
|
2019-07-31 19:25:30 +00:00
|
|
|
{
|
|
|
|
vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string,
|
|
|
|
vol.Optional(CONF_SSL, default=True): cv.boolean,
|
|
|
|
vol.Required(CONF_PASSWORD): cv.string,
|
|
|
|
}
|
|
|
|
)
|
2018-10-10 06:23:31 +00:00
|
|
|
|
|
|
|
|
2022-09-07 08:58:54 +00:00
|
|
|
def get_scanner(
|
|
|
|
hass: HomeAssistant, config: ConfigType
|
|
|
|
) -> QuantumGatewayDeviceScanner | None:
|
2018-10-10 06:23:31 +00:00
|
|
|
"""Validate the configuration and return a Quantum Gateway scanner."""
|
|
|
|
scanner = QuantumGatewayDeviceScanner(config[DOMAIN])
|
|
|
|
|
|
|
|
return scanner if scanner.success_init else None
|
|
|
|
|
|
|
|
|
|
|
|
class QuantumGatewayDeviceScanner(DeviceScanner):
|
2023-03-03 10:26:13 +00:00
|
|
|
"""Class which queries a Quantum Gateway."""
|
2018-10-10 06:23:31 +00:00
|
|
|
|
|
|
|
def __init__(self, config):
|
|
|
|
"""Initialize the scanner."""
|
|
|
|
|
|
|
|
self.host = config[CONF_HOST]
|
|
|
|
self.password = config[CONF_PASSWORD]
|
2019-03-11 04:26:19 +00:00
|
|
|
self.use_https = config[CONF_SSL]
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug("Initializing")
|
2018-10-10 06:23:31 +00:00
|
|
|
|
|
|
|
try:
|
2019-07-31 19:25:30 +00:00
|
|
|
self.quantum = QuantumGatewayScanner(
|
|
|
|
self.host, self.password, self.use_https
|
|
|
|
)
|
2018-10-10 06:23:31 +00:00
|
|
|
self.success_init = self.quantum.success_init
|
|
|
|
except RequestException:
|
|
|
|
self.success_init = False
|
2020-07-05 21:04:19 +00:00
|
|
|
_LOGGER.error("Unable to connect to gateway. Check host")
|
2018-10-10 06:23:31 +00:00
|
|
|
|
|
|
|
if not self.success_init:
|
2020-07-05 21:04:19 +00:00
|
|
|
_LOGGER.error("Unable to login to gateway. Check password and host")
|
2018-10-10 06:23:31 +00:00
|
|
|
|
|
|
|
def scan_devices(self):
|
|
|
|
"""Scan for new devices and return a list of found MACs."""
|
|
|
|
connected_devices = []
|
|
|
|
try:
|
|
|
|
connected_devices = self.quantum.scan_devices()
|
|
|
|
except RequestException:
|
|
|
|
_LOGGER.error("Unable to scan devices. Check connection to router")
|
|
|
|
return connected_devices
|
|
|
|
|
|
|
|
def get_device_name(self, device):
|
|
|
|
"""Return the name of the given device or None if we don't know."""
|
|
|
|
return self.quantum.get_device_name(device)
|