mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Added device tracker support for Ubee Router (#19586)
* Added Ubee Router Device Tracker. * Updated code to meet requirements. * Code clean-up. * Code clean-up. * Code clean-up. * Minor error message update * Ubee device tracker: Minor code clean-up * Bump pyubee version * Code clean-up
This commit is contained in:
parent
4c4317fb37
commit
565f513b77
@ -136,6 +136,7 @@ omit =
|
||||
homeassistant/components/device_tracker/tplink.py
|
||||
homeassistant/components/device_tracker/traccar.py
|
||||
homeassistant/components/device_tracker/trackr.py
|
||||
homeassistant/components/device_tracker/ubee.py
|
||||
homeassistant/components/device_tracker/ubus.py
|
||||
homeassistant/components/digital_ocean/*
|
||||
homeassistant/components/dominos/*
|
||||
|
92
homeassistant/components/device_tracker/ubee.py
Normal file
92
homeassistant/components/device_tracker/ubee.py
Normal file
@ -0,0 +1,92 @@
|
||||
"""
|
||||
Support for Ubee router.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/device_tracker.ubee/
|
||||
"""
|
||||
|
||||
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 = ['pyubee==0.2']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_HOST): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
})
|
||||
|
||||
|
||||
def get_scanner(hass, config):
|
||||
"""Validate the configuration and return a Ubee scanner."""
|
||||
try:
|
||||
return UbeeDeviceScanner(config[DOMAIN])
|
||||
except ConnectionError:
|
||||
return None
|
||||
|
||||
|
||||
class UbeeDeviceScanner(DeviceScanner):
|
||||
"""This class queries a wireless Ubee router."""
|
||||
|
||||
def __init__(self, config):
|
||||
"""Initialize the Ubee scanner."""
|
||||
from pyubee import Ubee
|
||||
|
||||
self.host = config[CONF_HOST]
|
||||
self.username = config[CONF_USERNAME]
|
||||
self.password = config[CONF_PASSWORD]
|
||||
|
||||
self.last_results = {}
|
||||
self.mac2name = {}
|
||||
|
||||
self.ubee = Ubee(self.host, self.username, self.password)
|
||||
_LOGGER.info("Logging in")
|
||||
results = self.get_connected_devices()
|
||||
self.success_init = results is not None
|
||||
|
||||
if self.success_init:
|
||||
self.last_results = results
|
||||
else:
|
||||
_LOGGER.error("Login failed")
|
||||
|
||||
def scan_devices(self):
|
||||
"""Scan for new devices and return a list with found device IDs."""
|
||||
self._update_info()
|
||||
|
||||
return self.last_results
|
||||
|
||||
def get_device_name(self, device):
|
||||
"""Return the name of the given device or None if we don't know."""
|
||||
if device in self.mac2name:
|
||||
return self.mac2name.get(device)
|
||||
|
||||
return None
|
||||
|
||||
def _update_info(self):
|
||||
"""Retrieve latest information from the Ubee router."""
|
||||
if not self.success_init:
|
||||
return
|
||||
|
||||
_LOGGER.debug("Scanning")
|
||||
results = self.get_connected_devices()
|
||||
|
||||
if results is None:
|
||||
_LOGGER.warning("Error scanning devices")
|
||||
return
|
||||
|
||||
self.last_results = results or []
|
||||
|
||||
def get_connected_devices(self):
|
||||
"""List connected devices with pyubee."""
|
||||
if not self.ubee.session_active():
|
||||
self.ubee.login()
|
||||
|
||||
return self.ubee.get_connected_devices()
|
@ -1417,6 +1417,9 @@ pytradfri[async]==6.0.1
|
||||
# homeassistant.components.sensor.trafikverket_weatherstation
|
||||
pytrafikverket==0.1.5.8
|
||||
|
||||
# homeassistant.components.device_tracker.ubee
|
||||
pyubee==0.2
|
||||
|
||||
# homeassistant.components.device_tracker.unifi
|
||||
pyunifi==2.16
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user