From 5a259499aafb511c0bb777bc732a602917abf72f Mon Sep 17 00:00:00 2001 From: Leroy Shirto Date: Wed, 29 Jan 2020 22:39:09 +0000 Subject: [PATCH 1/5] 0.2.0 of the btsmarthub_devicelist package makes it compatable with BT's home hub 2. The API has changed in the new version so this change also makes the component code compatible with the changes to the library. --- .../components/bt_smarthub/device_tracker.py | 17 ++++++++++++----- .../components/bt_smarthub/manifest.json | 2 +- requirements_all.txt | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/bt_smarthub/device_tracker.py b/homeassistant/components/bt_smarthub/device_tracker.py index 45b18b963c5427..0af857f8d1a373 100644 --- a/homeassistant/components/bt_smarthub/device_tracker.py +++ b/homeassistant/components/bt_smarthub/device_tracker.py @@ -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 ( @@ -15,9 +15,13 @@ _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, default=None): vol.In([None, 1, 2]), + } ) @@ -35,8 +39,12 @@ def __init__(self, config): """Initialise the scanner.""" _LOGGER.debug("Initialising BT Smart Hub") self.host = config[CONF_HOST] + self.smarthub_model = config[CONF_SMARTHUB_MODEL] self.last_results = {} self.success_init = False + self.smarthub = BTSmartHub( + router_ip=self.host, smarthub_model=self.smarthub_model + ) # Test the router is accessible data = self.get_bt_smarthub_data() @@ -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: diff --git a/homeassistant/components/bt_smarthub/manifest.json b/homeassistant/components/bt_smarthub/manifest.json index 5f677a433c8ef5..81f7098e65348b 100644 --- a/homeassistant/components/bt_smarthub/manifest.json +++ b/homeassistant/components/bt_smarthub/manifest.json @@ -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"] } diff --git a/requirements_all.txt b/requirements_all.txt index 38133b1a4760e6..2d290d70938e07 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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 From 3b099ffbc04501ed73dff472eb0d9a9f54678259 Mon Sep 17 00:00:00 2001 From: Leroy Shirto Date: Mon, 30 Mar 2020 13:50:03 +0100 Subject: [PATCH 2/5] Update homeassistant/components/bt_smarthub/device_tracker.py Co-Authored-By: Franck Nijhof --- homeassistant/components/bt_smarthub/device_tracker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/bt_smarthub/device_tracker.py b/homeassistant/components/bt_smarthub/device_tracker.py index 0af857f8d1a373..6ee0af5a4cfd25 100644 --- a/homeassistant/components/bt_smarthub/device_tracker.py +++ b/homeassistant/components/bt_smarthub/device_tracker.py @@ -39,7 +39,7 @@ def __init__(self, config): """Initialise the scanner.""" _LOGGER.debug("Initialising BT Smart Hub") self.host = config[CONF_HOST] - self.smarthub_model = config[CONF_SMARTHUB_MODEL] + self.smarthub_model = config.get(CONF_SMARTHUB_MODEL) self.last_results = {} self.success_init = False self.smarthub = BTSmartHub( From 16939b8f66d2922eef9d827751809d82464977c0 Mon Sep 17 00:00:00 2001 From: Leroy Shirto Date: Mon, 30 Mar 2020 13:50:49 +0100 Subject: [PATCH 3/5] Update homeassistant/components/bt_smarthub/device_tracker.py Co-Authored-By: Franck Nijhof --- homeassistant/components/bt_smarthub/device_tracker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/bt_smarthub/device_tracker.py b/homeassistant/components/bt_smarthub/device_tracker.py index 6ee0af5a4cfd25..3121ba9f66f706 100644 --- a/homeassistant/components/bt_smarthub/device_tracker.py +++ b/homeassistant/components/bt_smarthub/device_tracker.py @@ -20,7 +20,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { vol.Optional(CONF_HOST, default=CONF_DEFAULT_IP): cv.string, - vol.Optional(CONF_SMARTHUB_MODEL, default=None): vol.In([None, 1, 2]), + vol.Optional(CONF_SMARTHUB_MODEL): vol.In([1, 2]), } ) From b3fe9d880f005335ae4bc8168a068d5fcad07b9d Mon Sep 17 00:00:00 2001 From: Leroy Shirto Date: Wed, 15 Apr 2020 11:50:16 +0100 Subject: [PATCH 4/5] Remove dep on config in BTSmartHubScanner This should make BTSmartHubScanner easier to test as you can pass in a mock smarthub_client --- .../components/bt_smarthub/device_tracker.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/bt_smarthub/device_tracker.py b/homeassistant/components/bt_smarthub/device_tracker.py index 3121ba9f66f706..d623e72a4cecb6 100644 --- a/homeassistant/components/bt_smarthub/device_tracker.py +++ b/homeassistant/components/bt_smarthub/device_tracker.py @@ -27,7 +27,13 @@ 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 @@ -35,23 +41,18 @@ def get_scanner(hass, config): 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_model = config.get(CONF_SMARTHUB_MODEL) + self.smarthub = smarthub_client self.last_results = {} self.success_init = False - self.smarthub = BTSmartHub( - router_ip=self.host, smarthub_model=self.smarthub_model - ) # Test the router is accessible data = self.get_bt_smarthub_data() 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.""" From 2e4a325ccaa51de95df72d19a7102adc7f1b97d5 Mon Sep 17 00:00:00 2001 From: Leroy Shirto Date: Wed, 15 Apr 2020 16:37:54 +0100 Subject: [PATCH 5/5] Black format bt_smarthub --- homeassistant/components/bt_smarthub/device_tracker.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homeassistant/components/bt_smarthub/device_tracker.py b/homeassistant/components/bt_smarthub/device_tracker.py index d623e72a4cecb6..383f724decd632 100644 --- a/homeassistant/components/bt_smarthub/device_tracker.py +++ b/homeassistant/components/bt_smarthub/device_tracker.py @@ -29,8 +29,7 @@ def get_scanner(hass, config): """Return a BT Smart Hub scanner if successful.""" info = config[DOMAIN] smarthub_client = BTSmartHub( - router_ip=info[CONF_HOST], - smarthub_model=info.get(CONF_SMARTHUB_MODEL) + router_ip=info[CONF_HOST], smarthub_model=info.get(CONF_SMARTHUB_MODEL) ) scanner = BTSmartHubScanner(smarthub_client)