Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 17 additions & 10 deletions homeassistant/components/bt_smarthub/device_tracker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Support for BT Smart Hub (Sometimes referred to as BT Home Hub 6)."""
import logging

import btsmarthub_devicelist
from btsmarthub_devicelist import BTSmartHub
import voluptuous as vol

from homeassistant.components.device_tracker import (
Expand All @@ -15,26 +15,34 @@
_LOGGER = logging.getLogger(__name__)

CONF_DEFAULT_IP = "192.168.1.254"
CONF_SMARTHUB_MODEL = "smarthub_model"

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{vol.Optional(CONF_HOST, default=CONF_DEFAULT_IP): cv.string}
{
vol.Optional(CONF_HOST, default=CONF_DEFAULT_IP): cv.string,
vol.Optional(CONF_SMARTHUB_MODEL): vol.In([1, 2]),
}
)


def get_scanner(hass, config):
"""Return a BT Smart Hub scanner if successful."""
scanner = BTSmartHubScanner(config[DOMAIN])
info = config[DOMAIN]
smarthub_client = BTSmartHub(
router_ip=info[CONF_HOST], smarthub_model=info.get(CONF_SMARTHUB_MODEL)
)

scanner = BTSmartHubScanner(smarthub_client)

return scanner if scanner.success_init else None


class BTSmartHubScanner(DeviceScanner):
"""This class queries a BT Smart Hub."""

def __init__(self, config):
def __init__(self, smarthub_client):
"""Initialise the scanner."""
_LOGGER.debug("Initialising BT Smart Hub")
self.host = config[CONF_HOST]
self.smarthub = smarthub_client
self.last_results = {}
self.success_init = False

Expand All @@ -43,7 +51,7 @@ def __init__(self, config):
if data:
self.success_init = True
else:
_LOGGER.info("Failed to connect to %s", self.host)
_LOGGER.info("Failed to connect to %s", self.smarthub.router_ip)

def scan_devices(self):
"""Scan for new devices and return a list with found device IDs."""
Expand Down Expand Up @@ -77,9 +85,8 @@ def get_bt_smarthub_data(self):
"""Retrieve data from BT Smart Hub and return parsed result."""

# Request data from bt smarthub into a list of dicts.
data = btsmarthub_devicelist.get_devicelist(
router_ip=self.host, only_active_devices=True
)
data = self.smarthub.get_devicelist(only_active_devices=True)

# Renaming keys from parsed result.
devices = {}
for device in data:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/bt_smarthub/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"domain": "bt_smarthub",
"name": "BT Smart Hub",
"documentation": "https://www.home-assistant.io/integrations/bt_smarthub",
"requirements": ["btsmarthub_devicelist==0.1.3"],
"requirements": ["btsmarthub_devicelist==0.2.0"],
"codeowners": ["@jxwolstenholme"]
}
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ bt_proximity==0.2
bthomehub5-devicelist==0.1.1

# homeassistant.components.bt_smarthub
btsmarthub_devicelist==0.1.3
btsmarthub_devicelist==0.2.0

# homeassistant.components.buienradar
buienradar==1.0.4
Expand Down