1 """Support for French FAI Bouygues Bbox routers."""
3 from __future__
import annotations
5 from collections
import namedtuple
6 from datetime
import timedelta
10 import voluptuous
as vol
13 DOMAIN
as DEVICE_TRACKER_DOMAIN,
14 PLATFORM_SCHEMA
as DEVICE_TRACKER_PLATFORM_SCHEMA,
24 _LOGGER = logging.getLogger(__name__)
26 DEFAULT_HOST =
"192.168.1.254"
30 PLATFORM_SCHEMA = DEVICE_TRACKER_PLATFORM_SCHEMA.extend(
31 {vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string}
35 def get_scanner(hass: HomeAssistant, config: ConfigType) -> BboxDeviceScanner |
None:
36 """Validate the configuration and return a Bbox scanner."""
39 return scanner
if scanner.success_init
else None
42 Device = namedtuple(
"Device", [
"mac",
"name",
"ip",
"last_update"])
46 """Scanner for devices connected to the bbox."""
49 """Get host from config."""
51 self.
hosthost = config[CONF_HOST]
53 """Initialize the scanner."""
59 """Scan for new devices and return a list with found device IDs."""
62 return [device.mac
for device
in self.
last_resultslast_results]
65 """Return the name of the given device or None if we don't know."""
67 result.name
for result
in self.
last_resultslast_results
if result.mac == device
71 return filter_named[0]
74 @Throttle(MIN_TIME_BETWEEN_SCANS)
76 """Check the Bbox for devices.
78 Returns boolean if scanning successful.
80 _LOGGER.debug(
"Scanning")
82 box = pybbox.Bbox(ip=self.
hosthost)
83 result = box.get_all_connected_devices()
88 if device[
"active"] != 1:
92 device[
"macaddress"], device[
"hostname"], device[
"ipaddress"], now
98 _LOGGER.debug(
"Scan successful")
def get_device_name(self, device)
def __init__(self, config)
BboxDeviceScanner|None get_scanner(HomeAssistant hass, ConfigType config)