Compare commits
No commits in common. "eed4d6f63b50d81d245336918c2e1aed3a870937" and "9e49c728ed175c06b90611cc0372ff15b27fe5b8" have entirely different histories.
eed4d6f63b
...
9e49c728ed
25
main.py
25
main.py
|
@ -2,8 +2,6 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import asyncio
|
import asyncio
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import RPi.GPIO as GPIO
|
|
||||||
import time
|
|
||||||
from aiohttp import ClientSession, CookieJar
|
from aiohttp import ClientSession, CookieJar
|
||||||
|
|
||||||
import settings
|
import settings
|
||||||
|
@ -13,25 +11,12 @@ from pyunifiprotect.unifi_protect_server import UpvServer
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
RELAY_ON = False
|
|
||||||
RELAY_OFF = True
|
|
||||||
|
|
||||||
def ring_bell(mac):
|
|
||||||
try:
|
|
||||||
doorbell = settings.DOORBELLS[mac]
|
|
||||||
GPIO.output(doorbell['gpio'], RELAY_ON)
|
|
||||||
time.sleep(0.5)
|
|
||||||
GPIO.output(doorbell['gpio'], RELAY_OFF)
|
|
||||||
except KeyError:
|
|
||||||
logger.error('Doorbell %s not found!', mac)
|
|
||||||
|
|
||||||
def subscriber(updated):
|
def subscriber(updated):
|
||||||
logger.debug('Subscription: updated=%s', updated)
|
logger.debug('Subscription: updated=%s', updated)
|
||||||
|
|
||||||
for _, data in updated.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']:
|
||||||
logger.info('%s: %s is ringing!', data['mac'], data['name'])
|
logger.info('%s is ringing!', data['name'])
|
||||||
ring_bell(data['mac'])
|
|
||||||
|
|
||||||
async def ws_listener():
|
async def ws_listener():
|
||||||
session = ClientSession(cookie_jar=CookieJar(unsafe=True))
|
session = ClientSession(cookie_jar=CookieJar(unsafe=True))
|
||||||
|
@ -55,14 +40,6 @@ async def ws_listener():
|
||||||
await session.close()
|
await session.close()
|
||||||
unsub()
|
unsub()
|
||||||
|
|
||||||
def init_relays():
|
|
||||||
GPIO.setmode(GPIO.BCM)
|
|
||||||
GPIO.setwarnings(False)
|
|
||||||
|
|
||||||
for _, doorbell in settings.DOORBELLS.items():
|
|
||||||
GPIO.setup(doorbell['gpio'], GPIO.OUT)
|
|
||||||
GPIO.output(doorbell['gpio'], RELAY_OFF)
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
aiohttp==3.7.4.post0
|
|
||||||
async-timeout==3.0.1
|
|
||||||
asyncio==3.4.3
|
|
||||||
attrs==21.2.0
|
|
||||||
chardet==4.0.0
|
|
||||||
click==8.0.3
|
|
||||||
idna==3.3
|
|
||||||
multidict==5.2.0
|
|
||||||
Pillow==8.4.0
|
|
||||||
PyJWT==2.2.0
|
|
||||||
python-dotenv==0.19.1
|
|
||||||
pyunifiprotect==0.33.0
|
|
||||||
typer==0.4.0
|
|
||||||
typing-extensions==3.10.0.2
|
|
||||||
yarl==1.7.0
|
|
|
@ -1,15 +0,0 @@
|
||||||
UFP_USERNAME = 'admin'
|
|
||||||
UFP_PASSWORD = 'password'
|
|
||||||
UFP_ADDRESS = '192.168.whatever'
|
|
||||||
UFP_PORT = 443
|
|
||||||
|
|
||||||
DOORBELLS = {
|
|
||||||
'123456780ABC': {
|
|
||||||
name: 'Front Door',
|
|
||||||
gpio: 26,
|
|
||||||
},
|
|
||||||
'123456780ABC': {
|
|
||||||
name: 'Side Door',
|
|
||||||
gpio: 19,
|
|
||||||
},
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user