This commit is contained in:
Paulus Schoutsen committed 2019-07-31 12:25:30 -07:00
1 parent da05dfe708
commit 4de97abc3a
2676 files changed
+163166 -140084

No files matched your search

+26 -19
View File
@@ -4,21 +4,25 @@ 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_SSL, CONF_USERNAME)
DOMAIN,
PLATFORM_SCHEMA,
DeviceScanner,
)
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_SSL, CONF_USERNAME
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
DEFAULT_SSL = False
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean,
})
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_SSL, default=DEFAULT_SSL): cv.boolean,
}
)
def get_scanner(hass, config):
@@ -36,8 +40,11 @@ class LuciDeviceScanner(DeviceScanner):
from openwrt_luci_rpc import OpenWrtRpc
self.router = OpenWrtRpc(
config[CONF_HOST], config[CONF_USERNAME], config[CONF_PASSWORD],
config[CONF_SSL])
config[CONF_HOST],
config[CONF_USERNAME],
config[CONF_PASSWORD],
config[CONF_SSL],
)
self.last_results = {}
self.success_init = self.router.is_logged_in()
@@ -50,9 +57,10 @@ class LuciDeviceScanner(DeviceScanner):
def get_device_name(self, device):
"""Return the name of the given device or None if we don't know."""
name = next((
result.hostname for result in self.last_results
if result.mac == device), None)
name = next(
(result.hostname for result in self.last_results if result.mac == device),
None,
)
return name
def get_extra_attributes(self, device):
@@ -64,15 +72,14 @@ class LuciDeviceScanner(DeviceScanner):
(ip), reachable status (reachable), associated router
(host), hostname if known (hostname) among others.
"""
device = next((
result for result in self.last_results
if result.mac == device), None)
device = next(
(result for result in self.last_results if result.mac == device), None
)
return device._asdict()
def _update_info(self):
"""Check the Luci router for devices."""
result = self.router.get_all_connected_devices(
only_reachable=True)
result = self.router.get_all_connected_devices(only_reachable=True)
_LOGGER.debug("Luci get_all_connected_devices returned: %s", result)