1 """Support for BT Smart Hub (Sometimes referred to as BT Home Hub 6)."""
3 from __future__
import annotations
5 from collections
import namedtuple
8 from btsmarthub_devicelist
import BTSmartHub
9 import voluptuous
as vol
12 DOMAIN
as DEVICE_TRACKER_DOMAIN,
13 PLATFORM_SCHEMA
as DEVICE_TRACKER_PLATFORM_SCHEMA,
21 _LOGGER = logging.getLogger(__name__)
23 CONF_DEFAULT_IP =
"192.168.1.254"
24 CONF_SMARTHUB_MODEL =
"smarthub_model"
26 PLATFORM_SCHEMA = DEVICE_TRACKER_PLATFORM_SCHEMA.extend(
28 vol.Optional(CONF_HOST, default=CONF_DEFAULT_IP): cv.string,
29 vol.Optional(CONF_SMARTHUB_MODEL): vol.In([1, 2]),
34 def get_scanner(hass: HomeAssistant, config: ConfigType) -> BTSmartHubScanner |
None:
35 """Return a BT Smart Hub scanner if successful."""
36 info = config[DEVICE_TRACKER_DOMAIN]
37 smarthub_client = BTSmartHub(
38 router_ip=info[CONF_HOST], smarthub_model=info.get(CONF_SMARTHUB_MODEL)
41 return scanner
if scanner.success_init
else None
45 """Create new device from the dict."""
46 ip_address = data.get(
"IPAddress")
47 mac = data.get(
"PhysAddress")
48 host = data.get(
"UserHostName")
49 status = data.get(
"Active")
50 name = data.get(
"name")
51 return _Device(ip_address, mac, host, status, name)
54 _Device = namedtuple(
"_Device", [
"ip_address",
"mac",
"host",
"status",
"name"])
58 """Class which queries a BT Smart Hub."""
61 """Initialise the scanner."""
70 _LOGGER.warning(
"Failed to connect to %s", self.
smarthubsmarthub.router_ip)
73 """Scan for new devices and return a list with found device IDs."""
75 return [device.mac
for device
in self.
last_resultslast_results]
78 """Return the name of the given device or None if we don't know."""
82 if result_device.mac == device:
83 return result_device.name
or result_device.host
87 """Ensure the information from the BT Smart Hub is up to date."""
91 _LOGGER.debug(
"Scanning")
93 _LOGGER.warning(
"Error scanning devices")
98 """Retrieve data from BT Smart Hub and return parsed result."""
100 data = self.
smarthubsmarthub.get_devicelist(only_active_devices=
True)
def __init__(self, smarthub_client)
def get_device_name(self, device)
def get_bt_smarthub_data(self)
BTSmartHubScanner|None get_scanner(HomeAssistant hass, ConfigType config)