Update bt_smarthub component making it compatible with smarthub 2 (#31292)
* 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. * Update homeassistant/components/bt_smarthub/device_tracker.py Co-Authored-By: Franck Nijhof <frenck@frenck.nl> * Update homeassistant/components/bt_smarthub/device_tracker.py Co-Authored-By: Franck Nijhof <frenck@frenck.nl> * Remove dep on config in BTSmartHubScanner This should make BTSmartHubScanner easier to test as you can pass in a mock smarthub_client * Black format bt_smarthub Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
214aa3de08
commit
6fc517fdbe
3 changed files with 19 additions and 12 deletions
|
@ -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,15 +15,24 @@ import homeassistant.helpers.config_validation as cv
|
|||
_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
|
||||
|
||||
|
@ -31,10 +40,9 @@ 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 = smarthub_client
|
||||
self.last_results = {}
|
||||
self.success_init = False
|
||||
|
||||
|
@ -43,7 +51,7 @@ class BTSmartHubScanner(DeviceScanner):
|
|||
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."""
|
||||
|
@ -77,9 +85,8 @@ class BTSmartHubScanner(DeviceScanner):
|
|||
"""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:
|
||||
|
|
|
@ -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"]
|
||||
}
|
||||
|
|
|
@ -376,7 +376,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
|
||||
|
|
Loading…
Add table
Reference in a new issue