Compare commits
3 Commits
9e49c728ed
...
eed4d6f63b
Author | SHA1 | Date | |
---|---|---|---|
eed4d6f63b | |||
8b6838ac3b | |||
d9499faaba |
25
main.py
25
main.py
|
@ -2,6 +2,8 @@ import os
|
|||
import sys
|
||||
import asyncio
|
||||
import aiohttp
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
from aiohttp import ClientSession, CookieJar
|
||||
|
||||
import settings
|
||||
|
@ -11,12 +13,25 @@ from pyunifiprotect.unifi_protect_server import UpvServer
|
|||
import logging
|
||||
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):
|
||||
logger.debug('Subscription: updated=%s', updated)
|
||||
|
||||
for _, data in updated.items():
|
||||
if data['event_type'] == 'ring' and data['event_ring_on']:
|
||||
logger.info('%s is ringing!', data['name'])
|
||||
logger.info('%s: %s is ringing!', data['mac'], data['name'])
|
||||
ring_bell(data['mac'])
|
||||
|
||||
async def ws_listener():
|
||||
session = ClientSession(cookie_jar=CookieJar(unsafe=True))
|
||||
|
@ -40,6 +55,14 @@ async def ws_listener():
|
|||
await session.close()
|
||||
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__':
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
loop = asyncio.get_event_loop()
|
||||
|
|
15
requirements.txt
Normal file
15
requirements.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
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
|
15
settings.py.example
Normal file
15
settings.py.example
Normal file
|
@ -0,0 +1,15 @@
|
|||
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