mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
* Moved climate components with tests into platform dirs. * Updated tests from climate component. * Moved binary_sensor components with tests into platform dirs. * Updated tests from binary_sensor component. * Moved calendar components with tests into platform dirs. * Updated tests from calendar component. * Moved camera components with tests into platform dirs. * Updated tests from camera component. * Moved cover components with tests into platform dirs. * Updated tests from cover component. * Moved device_tracker components with tests into platform dirs. * Updated tests from device_tracker component. * Moved fan components with tests into platform dirs. * Updated tests from fan component. * Moved geo_location components with tests into platform dirs. * Updated tests from geo_location component. * Moved image_processing components with tests into platform dirs. * Updated tests from image_processing component. * Moved light components with tests into platform dirs. * Updated tests from light component. * Moved lock components with tests into platform dirs. * Moved media_player components with tests into platform dirs. * Updated tests from media_player component. * Moved scene components with tests into platform dirs. * Moved sensor components with tests into platform dirs. * Updated tests from sensor component. * Moved switch components with tests into platform dirs. * Updated tests from sensor component. * Moved vacuum components with tests into platform dirs. * Updated tests from vacuum component. * Moved weather components with tests into platform dirs. * Fixed __init__.py files * Fixes for stuff moved as part of this branch. * Fix stuff needed to merge with balloob's branch. * Formatting issues. * Missing __init__.py files. * Fix-ups * Fixup * Regenerated requirements. * Linting errors fixed. * Fixed more broken tests. * Missing init files. * Fix broken tests. * More broken tests * There seems to be a thread race condition. I suspect the logger stuff is running in another thread, which means waiting until the aio loop is done is missing the log messages. Used sleep instead because that allows the logger thread to run. I think the api_streams sensor might not be thread safe. * Disabled tests, will remove sensor in #22147 * Updated coverage and codeowners.
108 lines
3.1 KiB
Python
108 lines
3.1 KiB
Python
"""
|
|
Support for EE Brightbox router.
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
https://home-assistant.io/components/device_tracker.ee_brightbox/
|
|
"""
|
|
import logging
|
|
|
|
import voluptuous as vol
|
|
|
|
from homeassistant.components.device_tracker import (
|
|
DOMAIN, PLATFORM_SCHEMA, DeviceScanner)
|
|
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
|
|
import homeassistant.helpers.config_validation as cv
|
|
|
|
REQUIREMENTS = ['eebrightbox==0.0.4']
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
CONF_VERSION = 'version'
|
|
|
|
CONF_DEFAULT_IP = '192.168.1.1'
|
|
CONF_DEFAULT_USERNAME = 'admin'
|
|
CONF_DEFAULT_VERSION = 2
|
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|
vol.Required(CONF_VERSION, default=CONF_DEFAULT_VERSION): cv.positive_int,
|
|
vol.Required(CONF_HOST, default=CONF_DEFAULT_IP): cv.string,
|
|
vol.Required(CONF_USERNAME, default=CONF_DEFAULT_USERNAME): cv.string,
|
|
vol.Required(CONF_PASSWORD): cv.string,
|
|
})
|
|
|
|
|
|
def get_scanner(hass, config):
|
|
"""Return a router scanner instance."""
|
|
scanner = EEBrightBoxScanner(config[DOMAIN])
|
|
|
|
return scanner if scanner.check_config() else None
|
|
|
|
|
|
class EEBrightBoxScanner(DeviceScanner):
|
|
"""Scan EE Brightbox router."""
|
|
|
|
def __init__(self, config):
|
|
"""Initialise the scanner."""
|
|
self.config = config
|
|
self.devices = {}
|
|
|
|
def check_config(self):
|
|
"""Check if provided configuration and credentials are correct."""
|
|
from eebrightbox import EEBrightBox, EEBrightBoxException
|
|
|
|
try:
|
|
with EEBrightBox(self.config) as ee_brightbox:
|
|
return bool(ee_brightbox.get_devices())
|
|
except EEBrightBoxException:
|
|
_LOGGER.exception("Failed to connect to the router")
|
|
return False
|
|
|
|
def scan_devices(self):
|
|
"""Scan for devices."""
|
|
from eebrightbox import EEBrightBox
|
|
|
|
with EEBrightBox(self.config) as ee_brightbox:
|
|
self.devices = {d['mac']: d for d in ee_brightbox.get_devices()}
|
|
|
|
macs = [d['mac'] for d in self.devices.values() if d['activity_ip']]
|
|
|
|
_LOGGER.debug('Scan devices %s', macs)
|
|
|
|
return macs
|
|
|
|
def get_device_name(self, device):
|
|
"""Get the name of a device from hostname."""
|
|
if device in self.devices:
|
|
return self.devices[device]['hostname'] or None
|
|
|
|
return None
|
|
|
|
def get_extra_attributes(self, device):
|
|
"""
|
|
Get the extra attributes of a device.
|
|
|
|
Extra attributes include:
|
|
- ip
|
|
- mac
|
|
- port - ethX or wifiX
|
|
- last_active
|
|
"""
|
|
port_map = {
|
|
'wl1': 'wifi5Ghz',
|
|
'wl0': 'wifi2.4Ghz',
|
|
'eth0': 'eth0',
|
|
'eth1': 'eth1',
|
|
'eth2': 'eth2',
|
|
'eth3': 'eth3',
|
|
}
|
|
|
|
if device in self.devices:
|
|
return {
|
|
'ip': self.devices[device]['ip'],
|
|
'mac': self.devices[device]['mac'],
|
|
'port': port_map[self.devices[device]['port']],
|
|
'last_active': self.devices[device]['time_last_active'],
|
|
}
|
|
|
|
return {}
|