Skip to content

Commit dd3af99

Browse files
committed
Mods for V 5.11.39 (minor)
1 parent f222215 commit dd3af99

File tree

4 files changed

+75
-32
lines changed

4 files changed

+75
-32
lines changed

get_models.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#extract models info from unifi javascript
55
# N Waterton 4th July 2019 V1.0: initial release
66
# N Waterton 13th July 2019 V1.0.2 minor fixes.
7+
# N Waterton 10th Sep 2019 V1.0.3 minor fixes
78

89
import time, os, sys, json, re
910
from datetime import timedelta
@@ -14,7 +15,7 @@
1415
from logging.handlers import RotatingFileHandler
1516
supported_devices=['UGW','USW','UAP','UDM']
1617

17-
__VERSION__ = __version__ = '1.0.2'
18+
__VERSION__ = __version__ = '1.0.3'
1819

1920
class progress_bar():
2021
'''
@@ -305,14 +306,15 @@ def update_models(file, data):
305306

306307
log.debug('The following new devices have been added: %s' % pprint(new_models))
307308
log.info('New devices: %s' % get_summary(new_models))
308-
if not any([value for value in get_summary(new_models).values()]):
309-
log.info('No New Models Found')
310-
return
311309
all_models = OrderedDict()
312310
all_models.update(models)
313-
if query_yes_no("Do you want to add them to the database?"):
314-
all_models = merge_dicts(models, new_models)
315-
log.info('database updated')
311+
if not any([value for value in get_summary(new_models).values()]):
312+
log.info('No New Models Found')
313+
#return
314+
else:
315+
if query_yes_no("Do you want to add them to the database?"):
316+
all_models = merge_dicts(models, new_models)
317+
log.info('database updated')
316318
if query_yes_no("Do you want to add the full Unifi data to the database (recommended)?"):
317319
for type, devices in all_models.copy().items():
318320
for device in devices:

models.json

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,16 @@
767767
"eth3": "LAN",
768768
"eth4": "WAN"
769769
},
770+
"radios": {
771+
"na": {
772+
"gain": 4,
773+
"maxPower": 25
774+
},
775+
"ng": {
776+
"gain": 3,
777+
"maxPower": 20
778+
}
779+
},
770780
"subtypes": [
771781
"ugw",
772782
"usw",
@@ -831,34 +841,36 @@
831841
"ipsThroughput": "1 Gbps"
832842
},
833843
"diagram": [
834-
"01 03 05 07 __ 10",
835-
"02 04 06 08 09 11"
844+
"01 03 05 07 __ __ 10",
845+
"02 04 06 08 __ 09 11"
836846
],
837847
"name": "UniFi Dream Machine Pro",
838848
"networkGroups": {
839849
"eth0": "LAN",
840850
"eth1": "LAN",
851+
"eth10": "LAN",
841852
"eth2": "LAN",
842853
"eth3": "LAN",
843854
"eth4": "LAN",
844855
"eth5": "LAN",
845856
"eth6": "LAN",
846857
"eth7": "LAN",
847858
"eth8": "WAN",
848-
"eth9": "WAN"
859+
"eth9": "WAN2"
849860
},
850861
"ports": {
851862
"eth0": "LAN",
852863
"eth1": "LAN",
864+
"eth10": "LAN",
853865
"eth2": "LAN",
854866
"eth3": "LAN",
855867
"eth4": "LAN",
856868
"eth5": "LAN",
857869
"eth6": "LAN",
858870
"eth7": "LAN",
859-
"eth8": "WAN",
860-
"eth9": "WAN",
861-
"sfp": [
871+
"eth8": "WAN1",
872+
"eth9": "WAN2",
873+
"plus": [
862874
10,
863875
11
864876
],
@@ -919,6 +931,16 @@
919931
"eth3": "LAN",
920932
"eth4": "WAN"
921933
},
934+
"radios": {
935+
"na": {
936+
"gain": 4,
937+
"maxPower": 25
938+
},
939+
"ng": {
940+
"gain": 3,
941+
"maxPower": 20
942+
}
943+
},
922944
"subtypes": [
923945
"ugw",
924946
"usw",
@@ -955,34 +977,36 @@
955977
"ipsThroughput": "1 Gbps"
956978
},
957979
"diagram": [
958-
"01 03 05 07 __ 10",
959-
"02 04 06 08 09 11"
980+
"01 03 05 07 __ __ 10",
981+
"02 04 06 08 __ 09 11"
960982
],
961983
"name": "UniFi Dream Machine Pro",
962984
"networkGroups": {
963985
"eth0": "LAN",
964986
"eth1": "LAN",
987+
"eth10": "LAN",
965988
"eth2": "LAN",
966989
"eth3": "LAN",
967990
"eth4": "LAN",
968991
"eth5": "LAN",
969992
"eth6": "LAN",
970993
"eth7": "LAN",
971994
"eth8": "WAN",
972-
"eth9": "WAN"
995+
"eth9": "WAN2"
973996
},
974997
"ports": {
975998
"eth0": "LAN",
976999
"eth1": "LAN",
1000+
"eth10": "LAN",
9771001
"eth2": "LAN",
9781002
"eth3": "LAN",
9791003
"eth4": "LAN",
9801004
"eth5": "LAN",
9811005
"eth6": "LAN",
9821006
"eth7": "LAN",
983-
"eth8": "WAN",
984-
"eth9": "WAN",
985-
"sfp": [
1007+
"eth8": "WAN1",
1008+
"eth9": "WAN2",
1009+
"plus": [
9861010
10,
9871011
11
9881012
],
@@ -1528,16 +1552,20 @@
15281552
},
15291553
"unifi": {
15301554
"features": {
1555+
"fan": "simple",
15311556
"poe": 1
15321557
},
1533-
"name": "UniFi Switch 16 POE",
1558+
"name": "UniFi Switch 16 POE-150W",
15341559
"ports": {
15351560
"sfp": [
15361561
17,
15371562
18
15381563
],
15391564
"standard": 16
15401565
},
1566+
"power": {
1567+
"capacity": 150
1568+
},
15411569
"type": "usw"
15421570
}
15431571
},
@@ -1588,16 +1616,20 @@
15881616
},
15891617
"unifi": {
15901618
"features": {
1619+
"fan": "alwayson",
15911620
"poe": 1
15921621
},
1593-
"name": "UniFi Switch 24 POE",
1622+
"name": "UniFi Switch 24 POE-250W",
15941623
"ports": {
15951624
"sfp": [
15961625
25,
15971626
26
15981627
],
15991628
"standard": 24
16001629
},
1630+
"power": {
1631+
"capacity": 250
1632+
},
16011633
"type": "usw"
16021634
}
16031635
},

unifi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ def draw_port(self):
797797
Grx.draw_text(str(self.port_number), self.x+self.port_width//2, self.y-self.text_height, port_number_text_opts)
798798
Grx.draw_filled_rounded_box(self.x, self.y, self.x+self.port_width, self.y+self.port_height, 3, color)
799799
if color == self.black and float(self.power)==0:
800-
log.info("POWER: %s" % self.power)
800+
#log.info("POWER: %s" % self.power)
801801
port_color = self.white
802802
if not self.enabled:
803803
port_color = self.red

unifi_client.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#need to install websockets-client (pip install websocket-client)
2121
#or aiohttp (pip install aiohttp) - python 3 only!
2222

23+
# N Waterton 10th September 2019 V1.1.2: added "sta:sync" message type found in controller 5.11.39
24+
2325
from __future__ import print_function
2426

2527
import json
@@ -35,18 +37,19 @@
3537
import logging
3638
from logging.handlers import RotatingFileHandler
3739

38-
__VERSION__ = '1.1.0'
40+
__VERSION__ = '1.1.2'
3941

4042
log = logging.getLogger('Main')
4143

4244
class UnifiClient(object):
4345

44-
def __init__(self, username, password, host='localhost', port=8443, ssl_verify=False, q=None):
46+
def __init__(self, username, password, host='localhost', port=8443, ssl_verify=False, q=None, timeout=10.0):
4547
self.username = username
4648
self.password = password
4749
self.host = host
4850
self.port = port
4951
self.ssl_verify = ssl_verify
52+
self.timeout = timeout
5053

5154
self.url = 'https://' + self.host + ':' + str(port) + '/'
5255
self.login_url = self.url + 'api/login'
@@ -79,9 +82,9 @@ def connect_websocket(self):
7982
'''
8083
if sys.version_info[0] == 3 and sys.version_info[1] > 3:
8184
from unifi_client_3 import UnifiClient3 #has to be in separate module to prevent python2 syntax errors
82-
UnifiClient3(self.username,self.password,self.host,self.port,self.ssl_verify,self.queues)
85+
UnifiClient3(self.username,self.password,self.host,self.port,self.ssl_verify,self.queues,self.timeout)
8386
else:
84-
UnifiClient2(self.username,self.password,self.host,self.port,self.ssl_verify,self.queues)
87+
UnifiClient2(self.username,self.password,self.host,self.port,self.ssl_verify,self.queues,self.timeout)
8588

8689
def update_unifi_data(self, data):
8790
'''
@@ -92,7 +95,7 @@ def update_unifi_data(self, data):
9295
unifi_data = OrderedDict()
9396

9497
meta = data['meta']
95-
update_type = meta.get("message", "device:sync") #"events", "device:sync", "device:update", "speed-test:update", "user:sync", possibly others
98+
update_type = meta.get("message", "device:sync") #"events", "device:sync", "device:update", "speed-test:update", "user:sync", "sta:sync", possibly others
9699
data_list = data['data']
97100

98101
if update_type == "device:sync":
@@ -118,6 +121,10 @@ def update_unifi_data(self, data):
118121
elif update_type == "speed-test:update":
119122
log.info('received speedtest: %s' % json.dumps(data, indent=2))
120123
#do something with speed tests here
124+
elif update_type == "sta:sync":
125+
log.info('received sta:sync: message')
126+
log.debug('\n: %s' % json.dumps(data, indent=2))
127+
#do something with station sync here
121128

122129
else:
123130
log.warn('Unknown message type: %s, data: %s' % (update_type, json.dumps(data, indent=2)))
@@ -232,8 +239,8 @@ class UnifiClient2(UnifiClient):
232239
'''
233240
Python 2 websocket class
234241
'''
235-
def __init__(self, username, password, host='localhost', port=8443, ssl_verify=False, q=None):
236-
super(UnifiClient2, self).__init__(username, password, host, port, ssl_verify, q)
242+
def __init__(self, username, password, host='localhost', port=8443, ssl_verify=False, q=None, timeout=10.0):
243+
super(UnifiClient2, self).__init__(username, password, host, port, ssl_verify, q, timeout)
237244

238245
def connect_websocket(self):
239246
t=threading.Thread(target=self.start_websocket)
@@ -269,10 +276,10 @@ def simple_websocket(self):
269276
try:
270277

271278
# We Authenticate with one session to get a session ID and other validation cookies
272-
r = session.post(self.login_url, json=json_request, verify=self.ssl_verify)
279+
r = session.post(self.login_url, json=json_request, verify=self.ssl_verify, timeout=self.timeout)
273280
assert r.status_code == 200
274281

275-
r = session.get(self.initial_info_url, json=self.params, verify=self.ssl_verify)
282+
r = session.get(self.initial_info_url, json=self.params, verify=self.ssl_verify, timeout=self.timeout)
276283
assert r.status_code == 200
277284

278285
data = r.json()
@@ -310,8 +317,10 @@ def simple_websocket(self):
310317
self.update_unifi_data(json.loads(msg))
311318
log.info('WS disconnected')
312319

313-
except AssertionError as e:
320+
except (AssertionError, requests.ConnectionError, requests.Timeout) as e:
314321
log.error("Connection failed error: %s" % e)
322+
except Exception as e:
323+
log.exception("unknown exception: %s" % e)
315324

316325
log.info('Exited')
317326

0 commit comments

Comments
 (0)