Change script to dog barking

main
Tanner Collin 2 years ago
parent c2d0c8e27b
commit bbf04d6397
  1. 36
      main.py

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

Loading…
Cancel
Save