Change script to dog barking

This commit is contained in:
Tanner Collin 2022-06-27 17:13:24 -06:00
parent c2d0c8e27b
commit bbf04d6397

36
main.py
View File

@ -15,16 +15,14 @@ import secrets
COOLDOWN = time.time()
CHIME = 'chime.ogg'
DOORBELLS = {
'647166': {
CAMERAS = {
'NE-W-ZoneB': {
'name': 'Front Door',
'sound': 'frontdoor.ogg',
'sound': 'barkLR.ogg',
},
'549660': {
'name': 'Back Door',
'sound': 'backdoor.ogg',
'SE-N-ZoneB': {
'name': 'Side Door',
'sound': 'barkRL.ogg',
}
}
@ -39,7 +37,7 @@ async def play_sound(filename):
await asyncio.sleep(0.1)
async def ring_bell(sound):
async def bark(sound):
global COOLDOWN
if time.time() - COOLDOWN < 5.0:
logging.info('Cooldown skipping.')
@ -48,22 +46,16 @@ async def ring_bell(sound):
await asyncio.sleep(0.1)
await play_sound(CHIME)
await play_sound(sound)
await asyncio.sleep(0.75)
await play_sound(CHIME)
await play_sound(sound)
logging.info('Done ringing.')
logging.info('Done barking.')
async def process_mqtt(message):
text = message.payload.decode()
topic = message.topic
logging.info('MQTT topic: %s, message: %s', topic, text)
if not topic.startswith('rtl_433'):
if not topic.startswith('iot/cameras'):
logging.info('Invalid topic, returning')
return
@ -75,21 +67,21 @@ async def process_mqtt(message):
id_ = str(data.get('id', ''))
if id_ not in DOORBELLS:
if id_ not in CAMERAS:
logging.info('Invalid id, returning')
return
doorbell = DOORBELLS[id_]
camera = CAMERAS[id_]
logging.info('Ringing %s...', doorbell['name'])
logging.info('Ringing %s...', camera['name'])
await ring_bell(doorbell['sound'])
async def fetch_mqtt():
await asyncio.sleep(3)
async with Client('localhost') as client:
async with client.filtered_messages('#') as messages:
async with Client('192.168.0.100') as client:
async with client.filtered_messages('iot/cameras') as messages:
await client.subscribe('#')
async for message in messages:
loop = asyncio.get_event_loop()