Home Assistant Unofficial Reference 2024.12.1
device_tracker.py
Go to the documentation of this file.
1 """Support for Verizon FiOS Quantum Gateways."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from quantum_gateway import QuantumGatewayScanner
8 from requests.exceptions import RequestException
9 import voluptuous as vol
10 
12  DOMAIN as DEVICE_TRACKER_DOMAIN,
13  PLATFORM_SCHEMA as DEVICE_TRACKER_PLATFORM_SCHEMA,
14  DeviceScanner,
15 )
16 from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_SSL
17 from homeassistant.core import HomeAssistant
19 from homeassistant.helpers.typing import ConfigType
20 
21 _LOGGER = logging.getLogger(__name__)
22 
23 DEFAULT_HOST = "myfiosgateway.com"
24 
25 PLATFORM_SCHEMA = DEVICE_TRACKER_PLATFORM_SCHEMA.extend(
26  {
27  vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string,
28  vol.Optional(CONF_SSL, default=True): cv.boolean,
29  vol.Required(CONF_PASSWORD): cv.string,
30  }
31 )
32 
33 
35  hass: HomeAssistant, config: ConfigType
36 ) -> QuantumGatewayDeviceScanner | None:
37  """Validate the configuration and return a Quantum Gateway scanner."""
38  scanner = QuantumGatewayDeviceScanner(config[DEVICE_TRACKER_DOMAIN])
39 
40  return scanner if scanner.success_init else None
41 
42 
43 class QuantumGatewayDeviceScanner(DeviceScanner):
44  """Class which queries a Quantum Gateway."""
45 
46  def __init__(self, config):
47  """Initialize the scanner."""
48 
49  self.hosthost = config[CONF_HOST]
50  self.passwordpassword = config[CONF_PASSWORD]
51  self.use_httpsuse_https = config[CONF_SSL]
52  _LOGGER.debug("Initializing")
53 
54  try:
55  self.quantumquantum = QuantumGatewayScanner(
56  self.hosthost, self.passwordpassword, self.use_httpsuse_https
57  )
58  self.success_initsuccess_init = self.quantumquantum.success_init
59  except RequestException:
60  self.success_initsuccess_init = False
61  _LOGGER.error("Unable to connect to gateway. Check host")
62 
63  if not self.success_initsuccess_init:
64  _LOGGER.error("Unable to login to gateway. Check password and host")
65 
66  def scan_devices(self):
67  """Scan for new devices and return a list of found MACs."""
68  connected_devices = []
69  try:
70  connected_devices = self.quantumquantum.scan_devices()
71  except RequestException:
72  _LOGGER.error("Unable to scan devices. Check connection to router")
73  return connected_devices
74 
75  def get_device_name(self, device):
76  """Return the name of the given device or None if we don't know."""
77  return self.quantumquantum.get_device_name(device)
QuantumGatewayDeviceScanner|None get_scanner(HomeAssistant hass, ConfigType config)