Compare commits
1 Commits
master
...
auto-reboo
Author | SHA1 | Date | |
---|---|---|---|
874d67782c |
@ -6,6 +6,7 @@ import sys
|
|||||||
from io import StringIO
|
from io import StringIO
|
||||||
import requests
|
import requests
|
||||||
from hid.DoorController import DoorController
|
from hid.DoorController import DoorController
|
||||||
|
from pyunifi.controller import Controller as UnifiController
|
||||||
|
|
||||||
from passwords import *
|
from passwords import *
|
||||||
|
|
||||||
@ -20,9 +21,14 @@ except NameError:
|
|||||||
|
|
||||||
doors = {doorName: DoorController(doorData['ip'],
|
doors = {doorName: DoorController(doorData['ip'],
|
||||||
DOOR_USERNAME, DOOR_PASSWORD,
|
DOOR_USERNAME, DOOR_PASSWORD,
|
||||||
name=doorName, access=doorData['access'])
|
name=doorName, access=doorData['access'],
|
||||||
|
mac=doorData['mac'])
|
||||||
for doorName, doorData in config["doors"].items()}
|
for doorName, doorData in config["doors"].items()}
|
||||||
|
|
||||||
|
unifiController = UnifiController(config['unifi-controller']['host'],
|
||||||
|
UNIFI_USERNAME, UNIFI_PASSWORD,
|
||||||
|
ssl_verify = False)
|
||||||
|
|
||||||
# mapping of member levels to schedules
|
# mapping of member levels to schedules
|
||||||
memberLevels = {"CMS Staff": "7x24",
|
memberLevels = {"CMS Staff": "7x24",
|
||||||
"CMS Weekends Only": "Weekends Only",
|
"CMS Weekends Only": "Weekends Only",
|
||||||
|
39
config.json
39
config.json
@ -1,10 +1,37 @@
|
|||||||
{
|
{
|
||||||
"doors": {
|
"doors": {
|
||||||
"Studio Space": {"ip": "172.18.51.11", "access": "Studio Space"},
|
"Studio Space": {
|
||||||
"Front Door": {"ip": "172.18.51.12", "access": "Front Door"},
|
"access": "Studio Space",
|
||||||
"Metal Shop": {"ip": "172.18.51.13", "access": "Metal Shop"},
|
"ip": "172.18.51.11",
|
||||||
"Wood Shop": {"ip": "172.18.51.14", "access": "Wood Shop"},
|
"mac": "00:06:8e:41:8d:16"
|
||||||
"Wood Shop Rear": {"ip": "172.18.51.15", "access": "Wood Shop"},
|
},
|
||||||
"Storage Closet": {"ip": "172.18.51.16", "access": "Storage Closet"}
|
"Front Door": {
|
||||||
|
"access": "Front Door",
|
||||||
|
"ip": "172.18.51.12",
|
||||||
|
"mac": "00:06:8e:41:4a:8e"
|
||||||
|
},
|
||||||
|
"Metal Shop": {
|
||||||
|
"access": "Metal Shop",
|
||||||
|
"ip": "172.18.51.13",
|
||||||
|
"mac": "00:06:8e:41:4a:89"
|
||||||
|
},
|
||||||
|
"Wood Shop": {
|
||||||
|
"access": "Wood Shop",
|
||||||
|
"ip": "172.18.51.14",
|
||||||
|
"mac": "00:06:8e:41:50:2e"
|
||||||
|
},
|
||||||
|
"Wood Shop Rear Door": {
|
||||||
|
"access": "Wood Shop",
|
||||||
|
"ip": "172.18.51.15",
|
||||||
|
"mac": "00:06:8e:41:4a:5e"
|
||||||
|
},
|
||||||
|
"Storage Closet": {
|
||||||
|
"access": "Storage Closet",
|
||||||
|
"ip": "172.18.51.16",
|
||||||
|
"mac": "00:06:8e:41:4a:6c"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"unifi-controller": {
|
||||||
|
"host": "172.18.1.7"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,11 +59,29 @@ def makeDoor(door, members, hashes):
|
|||||||
else:
|
else:
|
||||||
print("Door", door.name, "changed, trying to update")
|
print("Door", door.name, "changed, trying to update")
|
||||||
hashes[door.name] = doorHash
|
hashes[door.name] = doorHash
|
||||||
|
try:
|
||||||
door.doCSVImport(outString)
|
door.doCSVImport(outString)
|
||||||
|
except (requests.ReadTimeout, requests.ConnectionError):
|
||||||
|
print(f"Import failed on door {door.name}, trying to power cycle it")
|
||||||
|
cycleDoor(door)
|
||||||
# write out hash if we sucessfully updated this door
|
# write out hash if we sucessfully updated this door
|
||||||
with open('/tmp/doorUpdaterLastHash', 'w') as f:
|
with open('/tmp/doorUpdaterLastHash', 'w') as f:
|
||||||
json.dump(hashes, f)
|
json.dump(hashes, f)
|
||||||
|
|
||||||
|
def cycleDoor(door):
|
||||||
|
if door.mac is None:
|
||||||
|
print(f"Cannot power cycle to door {door.name}, no mac address defined")
|
||||||
|
return
|
||||||
|
|
||||||
|
doorControllerClient = unifiController.get_client(door.mac)
|
||||||
|
print(doorControllerClient)
|
||||||
|
|
||||||
|
unifiController._api_write(
|
||||||
|
'cmd/devmgr',
|
||||||
|
{"cmd": "power-cycle",
|
||||||
|
"mac": doorControllerClient["sw_mac"],
|
||||||
|
"port_idx": doorControllerClient["sw_port"]})
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
members = getMembershipworksData(
|
members = getMembershipworksData(
|
||||||
['members', 'staff', 'misc'],
|
['members', 'staff', 'misc'],
|
||||||
|
@ -20,12 +20,13 @@ class RemoteError(Exception):
|
|||||||
.format(r.status_code, r.reason, r.text))
|
.format(r.status_code, r.reason, r.text))
|
||||||
|
|
||||||
class DoorController():
|
class DoorController():
|
||||||
def __init__(self, ip, username, password, name="", access=""):
|
def __init__(self, ip, username, password, name="", access="", mac=""):
|
||||||
self.ip = ip
|
self.ip = ip
|
||||||
self.username = username
|
self.username = username
|
||||||
self.password = password
|
self.password = password
|
||||||
self.name = name
|
self.name = name
|
||||||
self.access = access
|
self.access = access
|
||||||
|
self.mac = mac
|
||||||
|
|
||||||
def doImportRequest(self, params=None, files=None):
|
def doImportRequest(self, params=None, files=None):
|
||||||
"""Send a request to the door control import script"""
|
"""Send a request to the door control import script"""
|
||||||
|
Reference in New Issue
Block a user