mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Use Voluptuous for BT Home Hub (#3121)
This commit is contained in:
parent
78f0e681ed
commit
586e47d08d
@ -13,9 +13,10 @@ import json
|
|||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.helpers import validate_config
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.components.device_tracker import DOMAIN
|
from homeassistant.components.device_tracker import DOMAIN, PLATFORM_SCHEMA
|
||||||
from homeassistant.const import CONF_HOST
|
from homeassistant.const import CONF_HOST
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
|
||||||
@ -26,14 +27,14 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
_MAC_REGEX = re.compile(r'(([0-9A-Fa-f]{1,2}\:){5}[0-9A-Fa-f]{1,2})')
|
_MAC_REGEX = re.compile(r'(([0-9A-Fa-f]{1,2}\:){5}[0-9A-Fa-f]{1,2})')
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Required(CONF_HOST): cv.string
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def get_scanner(hass, config):
|
def get_scanner(hass, config):
|
||||||
"""Return a BT Home Hub 5 scanner if successful."""
|
"""Return a BT Home Hub 5 scanner if successful."""
|
||||||
if not validate_config(config,
|
|
||||||
{DOMAIN: [CONF_HOST]},
|
|
||||||
_LOGGER):
|
|
||||||
return None
|
|
||||||
scanner = BTHomeHub5DeviceScanner(config[DOMAIN])
|
scanner = BTHomeHub5DeviceScanner(config[DOMAIN])
|
||||||
|
|
||||||
return scanner if scanner.success_init else None
|
return scanner if scanner.success_init else None
|
||||||
@ -44,7 +45,7 @@ class BTHomeHub5DeviceScanner(object):
|
|||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
"""Initialise the scanner."""
|
"""Initialise the scanner."""
|
||||||
_LOGGER.info("Initialising BT Home Hub 5")
|
_LOGGER.info('Initialising BT Home Hub 5')
|
||||||
self.host = config.get(CONF_HOST, '192.168.1.254')
|
self.host = config.get(CONF_HOST, '192.168.1.254')
|
||||||
|
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
@ -85,7 +86,7 @@ class BTHomeHub5DeviceScanner(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
with self.lock:
|
with self.lock:
|
||||||
_LOGGER.info("Scanning")
|
_LOGGER.info('Scanning')
|
||||||
|
|
||||||
data = _get_homehub_data(self.url)
|
data = _get_homehub_data(self.url)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user