mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 22:07:10 +00:00
corrected flake8 warnings
This commit is contained in:
parent
29c9c5a7ec
commit
50fbd83b3d
@ -49,7 +49,8 @@ class UbusDeviceScanner(object):
|
|||||||
|
|
||||||
Read only access will be fine.
|
Read only access will be fine.
|
||||||
|
|
||||||
To use this class you have to install rpcd-mod-file package in your OpenWrt router:
|
To use this class you have to install rpcd-mod-file package
|
||||||
|
in your OpenWrt router:
|
||||||
|
|
||||||
opkg install rpcd-mod-file
|
opkg install rpcd-mod-file
|
||||||
|
|
||||||
@ -64,7 +65,7 @@ class UbusDeviceScanner(object):
|
|||||||
self.last_results = {}
|
self.last_results = {}
|
||||||
self.url = 'http://{}/ubus'.format(host)
|
self.url = 'http://{}/ubus'.format(host)
|
||||||
|
|
||||||
self.session_id= _get_session_id(self.url, username, password)
|
self.session_id = _get_session_id(self.url, username, password)
|
||||||
self.hostapd = []
|
self.hostapd = []
|
||||||
self.leasefile = None
|
self.leasefile = None
|
||||||
self.mac2name = None
|
self.mac2name = None
|
||||||
@ -84,15 +85,19 @@ class UbusDeviceScanner(object):
|
|||||||
|
|
||||||
with self.lock:
|
with self.lock:
|
||||||
if self.leasefile is None:
|
if self.leasefile is None:
|
||||||
result = _req_json_rpc(self.url, self.session_id, 'call', 'uci', 'get', config="dhcp", type="dnsmasq")
|
result = _req_json_rpc(self.url, self.session_id,
|
||||||
|
'call', 'uci', 'get',
|
||||||
|
config="dhcp", type="dnsmasq")
|
||||||
if result:
|
if result:
|
||||||
self.leasefile=next (iter (result["values"].values()))["leasefile"]
|
self.leasefile = next(iter(result["values"].
|
||||||
|
values()))["leasefile"]
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
if self.mac2name is None:
|
if self.mac2name is None:
|
||||||
result = _req_json_rpc(self.url, self.session_id, 'call', 'file', 'read', path=self.leasefile)
|
result = _req_json_rpc(self.url, self.session_id,
|
||||||
|
'call', 'file', 'read',
|
||||||
|
path=self.leasefile)
|
||||||
if result:
|
if result:
|
||||||
self.mac2name = dict()
|
self.mac2name = dict()
|
||||||
for line in result["data"].splitlines():
|
for line in result["data"].splitlines():
|
||||||
@ -117,14 +122,16 @@ class UbusDeviceScanner(object):
|
|||||||
_LOGGER.info("Checking ARP")
|
_LOGGER.info("Checking ARP")
|
||||||
|
|
||||||
if not self.hostapd:
|
if not self.hostapd:
|
||||||
hostapd = _req_json_rpc(self.url, self.session_id, 'list', 'hostapd.*', '')
|
hostapd = _req_json_rpc(self.url, self.session_id,
|
||||||
|
'list', 'hostapd.*', '')
|
||||||
for key in hostapd.keys():
|
for key in hostapd.keys():
|
||||||
self.hostapd.append(key)
|
self.hostapd.append(key)
|
||||||
|
|
||||||
self.last_results = []
|
self.last_results = []
|
||||||
results = 0
|
results = 0
|
||||||
for hostapd in self.hostapd:
|
for hostapd in self.hostapd:
|
||||||
result = _req_json_rpc(self.url, self.session_id, 'call', hostapd, 'get_clients')
|
result = _req_json_rpc(self.url, self.session_id,
|
||||||
|
'call', hostapd, 'get_clients')
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
results = results + 1
|
results = results + 1
|
||||||
@ -136,13 +143,14 @@ class UbusDeviceScanner(object):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _req_json_rpc(url, session_id, rpcmethod, subsystem, method, **params):
|
def _req_json_rpc(url, session_id, rpcmethod, subsystem, method, **params):
|
||||||
""" Perform one JSON RPC operation. """
|
""" Perform one JSON RPC operation. """
|
||||||
|
|
||||||
data = json.dumps({ "jsonrpc": "2.0",
|
data = json.dumps({"jsonrpc": "2.0",
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"method": rpcmethod,
|
"method": rpcmethod,
|
||||||
"params": [ session_id,
|
"params": [session_id,
|
||||||
subsystem,
|
subsystem,
|
||||||
method,
|
method,
|
||||||
params]
|
params]
|
||||||
@ -162,10 +170,10 @@ def _req_json_rpc(url, session_id, rpcmethod, subsystem, method, **params):
|
|||||||
else:
|
else:
|
||||||
return response["result"]
|
return response["result"]
|
||||||
|
|
||||||
|
|
||||||
def _get_session_id(url, username, password):
|
def _get_session_id(url, username, password):
|
||||||
""" Get authentication token for the given host+username+password. """
|
""" Get authentication token for the given host+username+password. """
|
||||||
res = _req_json_rpc(url, "00000000000000000000000000000000", 'call', 'session', 'login', username=username, password=password)
|
res = _req_json_rpc(url, "00000000000000000000000000000000", 'call',
|
||||||
|
'session', 'login', username=username,
|
||||||
|
password=password)
|
||||||
return res["ubus_rpc_session"]
|
return res["ubus_rpc_session"]
|
||||||
|
|
||||||
|
|
||||||
# root@dom:~# ubus call uci get '{ "config": "dhcp", "type": "dnsmasq" }'
|
|
Loading…
x
Reference in New Issue
Block a user