Add configurable host for bbox routers (#16778)
* Add configurable host for bbox routers Add configurable host for bbox router running on non-default IP addresses. * Fix unused import Fix unused import which also resolves "line too long" * Fix wrong import order * Update validation
This commit is contained in:
parent
539b86e079
commit
eaee55175b
1 changed files with 18 additions and 4 deletions
|
@ -5,19 +5,30 @@ For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/device_tracker.bbox/
|
https://home-assistant.io/components/device_tracker.bbox/
|
||||||
"""
|
"""
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
import logging
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
import logging
|
||||||
|
|
||||||
import homeassistant.util.dt as dt_util
|
import voluptuous as vol
|
||||||
from homeassistant.components.device_tracker import DOMAIN, DeviceScanner
|
|
||||||
|
from homeassistant.components.device_tracker import (
|
||||||
|
DOMAIN, PLATFORM_SCHEMA, DeviceScanner)
|
||||||
|
from homeassistant.const import CONF_HOST
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
REQUIREMENTS = ['pybbox==0.0.5-alpha']
|
REQUIREMENTS = ['pybbox==0.0.5-alpha']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
DEFAULT_HOST = '192.168.1.254'
|
||||||
|
|
||||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=60)
|
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=60)
|
||||||
|
|
||||||
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
|
vol.Optional(CONF_HOST, default=DEFAULT_HOST): cv.string,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def get_scanner(hass, config):
|
def get_scanner(hass, config):
|
||||||
"""Validate the configuration and return a Bbox scanner."""
|
"""Validate the configuration and return a Bbox scanner."""
|
||||||
|
@ -33,6 +44,9 @@ class BboxDeviceScanner(DeviceScanner):
|
||||||
"""This class scans for devices connected to the bbox."""
|
"""This class scans for devices connected to the bbox."""
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
|
"""Get host from config."""
|
||||||
|
self.host = config[CONF_HOST]
|
||||||
|
|
||||||
"""Initialize the scanner."""
|
"""Initialize the scanner."""
|
||||||
self.last_results = [] # type: List[Device]
|
self.last_results = [] # type: List[Device]
|
||||||
|
|
||||||
|
@ -64,7 +78,7 @@ class BboxDeviceScanner(DeviceScanner):
|
||||||
|
|
||||||
import pybbox
|
import pybbox
|
||||||
|
|
||||||
box = pybbox.Bbox()
|
box = pybbox.Bbox(ip=self.host)
|
||||||
result = box.get_all_connected_devices()
|
result = box.get_all_connected_devices()
|
||||||
|
|
||||||
now = dt_util.now()
|
now = dt_util.now()
|
||||||
|
|
Loading…
Add table
Reference in a new issue