|
按照教程一步步的安装完以后,状态里面一直提示这条 (在报错信息里面找不到这个信息),而在known device中也找不到任何信息,于是添加了手动日志,查到了以下信息:
Apr 08 10:40:45 ubuntu hass[31125]: INFO:homeassistant.components.device_tracker.ubus:Checking hostapd
Apr 08 10:40:55 ubuntu hass[31125]: INFO:homeassistant.components.device_tracker.ubus:Checking hostapd
Apr 08 10:41:05 ubuntu hass[31125]: INFO:homeassistant.components.device_tracker.ubus:Checking hostapd
Apr 08 10:41:15 ubuntu hass[31125]: INFO:homeassistant.components.device_tracker.ubus:Checking hostapd
查下源代码,感觉是这段有问题
因为LEDE X64 是没有无线的,会不会时段的原因,但是直接删掉,就报错了
class UbusDeviceScanner(DeviceScanner):
"""
This class queries a wireless router running OpenWrt firmware.
Adapted from Tomato scanner.
"""
def __init__(self, config):
"""Initialize the scanner."""
host = config[CONF_HOST]
self.username = config[CONF_USERNAME]
self.password = config[CONF_PASSWORD]
self.parse_api_pattern = re.compile(r"(?P<param>\w*) = (?P<value>.*);")
self.last_results = {}
self.url = 'http://{}/ubus'.format(host)
self.session_id = _get_session_id(self.url, self.username,
self.password)
self.hostapd = []
self.mac2name = None
self.success_init = self.session_id is not None
def scan_devices(self):
"""Scan for new devices and return a list with found device IDs."""
self._update_info()
return self.last_results
def _generate_mac2name(self):
"""Must be implemented depending on the software."""
raise NotImplementedError
@_refresh_on_acccess_denied
def get_device_name(self, mac):
"""Return the name of the given device or None if we don't know."""
if self.mac2name is None:
self._generate_mac2name()
name = self.mac2name.get(mac.upper(), None)
self.mac2name = None
return name
@_refresh_on_acccess_denied
def _update_info(self):
"""Ensure the information from the router is up to date.
Returns boolean if scanning successful.
"""
if not self.success_init:
return False
_LOGGER.info("Checking hostapd")
if not self.hostapd:
hostapd = _req_json_rpc(
self.url, self.session_id, 'list', 'hostapd.*', '')
self.hostapd.extend(hostapd.keys())
self.last_results = []
results = 0
for hostapd in self.hostapd:
result = _req_json_rpc(
self.url, self.session_id, 'call', hostapd, 'get_clients')
if result:
results = results + 1
self.last_results.extend(result['clients'].keys())
return bool(results)
class DnsmasqUbusDeviceScanner(UbusDeviceScanner):
"""Implement the Ubus device scanning for the dnsmasq DHCP server."""
def __init__(self, config):
"""Initialize the scanner."""
super(DnsmasqUbusDeviceScanner, self).__init__(config)
self.leasefile = None
def _generate_mac2name(self):
if self.leasefile is None:
result = _req_json_rpc(
self.url, self.session_id, 'call', 'uci', 'get',
config="dhcp", type="dnsmasq")
if result:
values = result["values"].values()
self.leasefile = next(iter(values))["leasefile"]
else:
return
result = _req_json_rpc(
self.url, self.session_id, 'call', 'file', 'read',
path=self.leasefile)
if result:
self.mac2name = dict()
for line in result["data"].splitlines():
hosts = line.split(" ")
self.mac2name[hosts[1].upper()] = hosts[3]
else:
# Error, handled in the _req_json_rpc
return
|
|