1 """Support for UPC ConnectBox router."""
3 from __future__
import annotations
7 from connect_box
import ConnectBox
8 from connect_box.exceptions
import ConnectBoxError, ConnectBoxLoginError
9 import voluptuous
as vol
12 DOMAIN
as DEVICE_TRACKER_DOMAIN,
13 PLATFORM_SCHEMA
as DEVICE_TRACKER_PLATFORM_SCHEMA,
22 _LOGGER = logging.getLogger(__name__)
24 DEFAULT_IP =
"192.168.0.1"
26 PLATFORM_SCHEMA = DEVICE_TRACKER_PLATFORM_SCHEMA.extend(
28 vol.Required(CONF_PASSWORD): cv.string,
29 vol.Optional(CONF_HOST, default=DEFAULT_IP): cv.string,
35 hass: HomeAssistant, config: ConfigType
36 ) -> UPCDeviceScanner |
None:
37 """Return the UPC device scanner."""
38 conf = config[DEVICE_TRACKER_DOMAIN]
40 connect_box = ConnectBox(session, conf[CONF_PASSWORD], host=conf[CONF_HOST])
44 await connect_box.async_initialize_token()
45 except ConnectBoxLoginError:
46 _LOGGER.error(
"ConnectBox login data error!")
48 except ConnectBoxError:
51 async
def _shutdown(event):
53 await connect_box.async_close_session()
55 hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _shutdown)
61 """Class which queries a router running UPC ConnectBox firmware."""
63 def __init__(self, connect_box: ConnectBox) ->
None:
64 """Initialize the scanner."""
65 self.connect_box: ConnectBox = connect_box
68 """Scan for new devices and return a list with found device IDs."""
71 except ConnectBoxError:
74 return [device.mac
for device
in self.connect_box.devices]
77 """Get the device name (the name of the wireless device not used)."""
78 for connected_device
in self.connect_box.devices:
80 connected_device.mac == device
81 and connected_device.hostname.lower() !=
"unknown"
83 return connected_device.hostname
str|None async_get_device_name(self, str device)
None __init__(self, ConnectBox connect_box)
list[str] async_scan_devices(self)
Generator[ProtectAdoptableDeviceModel] async_get_devices(Bootstrap bootstrap, Iterable[ModelType] model_type)
UPCDeviceScanner|None async_get_scanner(HomeAssistant hass, ConfigType config)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)