Compare commits
No commits in common. "0053b78e41563a47ece4c74e3f1059d75e000418" and "760ce18290480e15b98cd69f2a602cbc8af32938" have entirely different histories.
0053b78e41
...
760ce18290
67
main.py
67
main.py
|
@ -17,7 +17,6 @@ from aiohttp import ClientSession, CookieJar
|
||||||
import settings
|
import settings
|
||||||
|
|
||||||
from pyunifiprotect.unifi_protect_server import UpvServer
|
from pyunifiprotect.unifi_protect_server import UpvServer
|
||||||
from pyunifiprotect.exceptions import NvrError
|
|
||||||
|
|
||||||
RELAY_ON = False
|
RELAY_ON = False
|
||||||
RELAY_OFF = True
|
RELAY_OFF = True
|
||||||
|
@ -45,10 +44,10 @@ def ring_bell(mac):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logging.error('Doorbell %s not found!', mac)
|
logging.error('Doorbell %s not found!', mac)
|
||||||
|
|
||||||
def subscriber(updates):
|
def subscriber(updated):
|
||||||
logging.debug('Subscription: updates=%s', updates)
|
logging.debug('Subscription: updated=%s', updated)
|
||||||
|
|
||||||
for _, data in updates.items():
|
for _, data in updated.items():
|
||||||
if data['event_type'] == 'ring' and data['event_ring_on']:
|
if data['event_type'] == 'ring' and data['event_ring_on']:
|
||||||
logging.info('%s: %s is ringing!', data['mac'], data['name'])
|
logging.info('%s: %s is ringing!', data['mac'], data['name'])
|
||||||
ring_bell(data['mac'])
|
ring_bell(data['mac'])
|
||||||
|
@ -58,46 +57,28 @@ def feed_watchdog():
|
||||||
wdt.write('1')
|
wdt.write('1')
|
||||||
|
|
||||||
async def ws_listener():
|
async def ws_listener():
|
||||||
|
session = ClientSession(cookie_jar=CookieJar(unsafe=True))
|
||||||
|
|
||||||
|
unifiprotect = UpvServer(
|
||||||
|
session,
|
||||||
|
settings.UFP_ADDRESS,
|
||||||
|
settings.UFP_PORT,
|
||||||
|
settings.UFP_USERNAME,
|
||||||
|
settings.UFP_PASSWORD,
|
||||||
|
)
|
||||||
|
|
||||||
|
await unifiprotect.check_unifi_os()
|
||||||
|
await unifiprotect.update()
|
||||||
|
|
||||||
|
unsub = unifiprotect.subscribe_websocket(subscriber)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
session = ClientSession(cookie_jar=CookieJar(unsafe=True))
|
if allow_watchdog and not DEBUG:
|
||||||
|
feed_watchdog()
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
|
||||||
unifiprotect = UpvServer(
|
await session.close()
|
||||||
session,
|
unsub()
|
||||||
settings.UFP_ADDRESS,
|
|
||||||
settings.UFP_PORT,
|
|
||||||
settings.UFP_USERNAME,
|
|
||||||
settings.UFP_PASSWORD,
|
|
||||||
)
|
|
||||||
|
|
||||||
await unifiprotect.check_unifi_os()
|
|
||||||
await unifiprotect.update()
|
|
||||||
|
|
||||||
unsub = unifiprotect.subscribe_websocket(subscriber)
|
|
||||||
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
updates = await unifiprotect.update()
|
|
||||||
logging.debug('Updates: %s', str(updates))
|
|
||||||
except NvrError:
|
|
||||||
logging.error('Problem connecting to Unifi Protect. Reconnecting...')
|
|
||||||
break
|
|
||||||
|
|
||||||
logging.debug('unifiprotect: %s', unifiprotect.__dict__)
|
|
||||||
logging.debug('ws_session %s', unifiprotect.ws_session.__dict__)
|
|
||||||
|
|
||||||
breakpoint()
|
|
||||||
|
|
||||||
#active_ws = await unifiprotect.check_ws()
|
|
||||||
#if not active_ws:
|
|
||||||
# logging.error('Websocket unactive. Reconnecting...')
|
|
||||||
|
|
||||||
if allow_watchdog and not DEBUG:
|
|
||||||
feed_watchdog()
|
|
||||||
|
|
||||||
await asyncio.sleep(1)
|
|
||||||
|
|
||||||
await session.close()
|
|
||||||
unsub()
|
|
||||||
|
|
||||||
def disable_relays_on_exit(*args):
|
def disable_relays_on_exit(*args):
|
||||||
logging.info('Exiting, disabling relays...')
|
logging.info('Exiting, disabling relays...')
|
||||||
|
@ -112,7 +93,7 @@ def init():
|
||||||
|
|
||||||
for _, doorbell in settings.DOORBELLS.items():
|
for _, doorbell in settings.DOORBELLS.items():
|
||||||
GPIO.setup(doorbell['gpio'], GPIO.OUT)
|
GPIO.setup(doorbell['gpio'], GPIO.OUT)
|
||||||
#pulse_relay(doorbell['gpio'])
|
pulse_relay(doorbell['gpio'])
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
logging.info('GPIO initialized')
|
logging.info('GPIO initialized')
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
aiohttp==3.7.4.post0
|
aiohttp==3.7.4.post0
|
||||||
aioshutil==1.1
|
|
||||||
async-timeout==3.0.1
|
async-timeout==3.0.1
|
||||||
asyncio==3.4.3
|
asyncio==3.4.3
|
||||||
attrs==21.2.0
|
attrs==21.2.0
|
||||||
|
@ -8,14 +7,10 @@ click==8.0.3
|
||||||
idna==3.3
|
idna==3.3
|
||||||
importlib-metadata==4.8.1
|
importlib-metadata==4.8.1
|
||||||
multidict==5.2.0
|
multidict==5.2.0
|
||||||
packaging==21.3
|
|
||||||
Pillow==8.4.0
|
Pillow==8.4.0
|
||||||
pydantic==1.8.2
|
|
||||||
PyJWT==2.2.0
|
PyJWT==2.2.0
|
||||||
pyparsing==3.0.6
|
|
||||||
python-dotenv==0.19.1
|
python-dotenv==0.19.1
|
||||||
pytz==2021.3
|
pyunifiprotect==0.33.0
|
||||||
pyunifiprotect==1.1.0
|
|
||||||
RPi.GPIO==0.7.0
|
RPi.GPIO==0.7.0
|
||||||
typer==0.4.0
|
typer==0.4.0
|
||||||
typing-extensions==3.10.0.2
|
typing-extensions==3.10.0.2
|
||||||
|
|
Loading…
Reference in New Issue
Block a user