mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Bump pyubee version to support more models and detect model automatically (#22450)
* Bump pyubee to 0.4, support more models and detect model automatically * Update requirements_all.txt * Check for supported models * Add model aliases * Code clean-up * Updated code to meet reviewer's requests. * Updated code to meet reviewer's requests. * Minor update * Minor update * Populate mac2name dict * Return list of MAC addresses, not dict Co-Authored-By: mzdrale <mzdrale@gmail.com> * Minor update
This commit is contained in:
parent
f5c677146a
commit
8a81286abb
@ -9,79 +9,60 @@ from homeassistant.const import (
|
|||||||
CONF_HOST, CONF_PASSWORD, CONF_USERNAME)
|
CONF_HOST, CONF_PASSWORD, CONF_USERNAME)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ['pyubee==0.2']
|
REQUIREMENTS = ['pyubee==0.5']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
CONF_MODEL = 'model'
|
||||||
|
DEFAULT_MODEL = 'detect'
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_HOST): cv.string,
|
vol.Required(CONF_HOST): cv.string,
|
||||||
vol.Required(CONF_PASSWORD): cv.string,
|
vol.Required(CONF_PASSWORD): cv.string,
|
||||||
vol.Required(CONF_USERNAME): cv.string,
|
vol.Required(CONF_USERNAME): cv.string,
|
||||||
|
vol.Optional(CONF_MODEL, default=DEFAULT_MODEL): cv.string
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
def get_scanner(hass, config):
|
def get_scanner(hass, config):
|
||||||
"""Validate the configuration and return a Ubee scanner."""
|
"""Validate the configuration and return a Ubee scanner."""
|
||||||
try:
|
info = config[DOMAIN]
|
||||||
return UbeeDeviceScanner(config[DOMAIN])
|
host = info[CONF_HOST]
|
||||||
except ConnectionError:
|
username = info[CONF_USERNAME]
|
||||||
|
password = info[CONF_PASSWORD]
|
||||||
|
model = info[CONF_MODEL]
|
||||||
|
|
||||||
|
from pyubee import Ubee
|
||||||
|
ubee = Ubee(host, username, password, model)
|
||||||
|
if not ubee.login():
|
||||||
|
_LOGGER.error("Login failed")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
scanner = UbeeDeviceScanner(ubee)
|
||||||
|
return scanner
|
||||||
|
|
||||||
|
|
||||||
class UbeeDeviceScanner(DeviceScanner):
|
class UbeeDeviceScanner(DeviceScanner):
|
||||||
"""This class queries a wireless Ubee router."""
|
"""This class queries a wireless Ubee router."""
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, ubee):
|
||||||
"""Initialize the Ubee scanner."""
|
"""Initialize the Ubee scanner."""
|
||||||
from pyubee import Ubee
|
self._ubee = ubee
|
||||||
|
self._mac2name = {}
|
||||||
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):
|
def scan_devices(self):
|
||||||
"""Scan for new devices and return a list with found device IDs."""
|
"""Scan for new devices and return a list with found device IDs."""
|
||||||
self._update_info()
|
devices = self._get_connected_devices()
|
||||||
|
self._mac2name = devices
|
||||||
return self.last_results
|
return list(devices)
|
||||||
|
|
||||||
def get_device_name(self, device):
|
def get_device_name(self, device):
|
||||||
"""Return the name of the given device or None if we don't know."""
|
"""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 self.mac2name.get(device)
|
|
||||||
|
|
||||||
return None
|
def _get_connected_devices(self):
|
||||||
|
|
||||||
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."""
|
"""List connected devices with pyubee."""
|
||||||
if not self.ubee.session_active():
|
if not self._ubee.session_active():
|
||||||
self.ubee.login()
|
self._ubee.login()
|
||||||
|
|
||||||
return self.ubee.get_connected_devices()
|
return self._ubee.get_connected_devices()
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "Ubee",
|
"name": "Ubee",
|
||||||
"documentation": "https://www.home-assistant.io/components/ubee",
|
"documentation": "https://www.home-assistant.io/components/ubee",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"pyubee==0.2"
|
"pyubee==0.5"
|
||||||
],
|
],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": []
|
"codeowners": []
|
||||||
|
@ -1423,7 +1423,7 @@ pytradfri[async]==6.0.1
|
|||||||
pytrafikverket==0.1.5.9
|
pytrafikverket==0.1.5.9
|
||||||
|
|
||||||
# homeassistant.components.ubee
|
# homeassistant.components.ubee
|
||||||
pyubee==0.2
|
pyubee==0.5
|
||||||
|
|
||||||
# homeassistant.components.unifi
|
# homeassistant.components.unifi
|
||||||
pyunifi==2.16
|
pyunifi==2.16
|
||||||
|
Loading…
x
Reference in New Issue
Block a user