Initial version - ring

This commit is contained in:
Dirk Alders 2022-09-21 14:38:35 +01:00
parent c8a86afbd1
commit f8284b51ef
12 changed files with 95 additions and 0 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
config.py
# ---> Linux
*~

9
.gitmodules vendored Normal file
View File

@ -0,0 +1,9 @@
[submodule "mqtt"]
path = mqtt
url = https://git.mount-mockery.de/pylib/mqtt.git
[submodule "report"]
path = report
url = https://git.mount-mockery.de/pylib/report.git
[submodule "task"]
path = task
url = https://git.mount-mockery.de/pylib/task.git

26
example_config/config.py Normal file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import os
import report
__BASEPATH__ = os.path.abspath(os.path.dirname(__file__))
MQTT_USER = "user"
MQTT_PASS = "pass"
MQTT_SERVER = "host"
TOPIC = 'topic'
PAYLOAD = b'payload'
COMMAND = "aplay ring.wav -D plughw:UACDemoV10,0"
#
# Logging
#
APP_NAME = "exec_command"
LOGTARGET = 'stdout' # possible choices are: 'logfile' or 'stdout'
LOGLVL = 'DEBUG'
LOGHOST = 'cutelog'
LOGPORT = 19996
formatter = report.SHORT_FMT

49
exec_command.py Normal file
View File

@ -0,0 +1,49 @@
import config
import logging
import mqtt
import os
import report
import task
import time
try:
from config import APP_NAME as ROOT_LOGGER_NAME
except ImportError:
ROOT_LOGGER_NAME = 'root'
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild('main')
class exec_command(mqtt.mqtt_client, task.threaded_queue):
def __init__(self):
self.__block_execution__ = False
task.threaded_queue.__init__(self)
mqtt.mqtt_client.__init__(self, config.APP_NAME, config.MQTT_SERVER, 1883, config.MQTT_USER, config.MQTT_PASS)
self.add_callback(config.TOPIC, self.mqtt_rx)
def exec_command(self, rt):
os.system(config.COMMAND)
self.__block_execution__ = False
def mqtt_rx(self, client, userdate, message):
if not self.__block_execution__:
if message.payload == config.PAYLOAD:
logger.debug("Starting execution in background...")
self.__block_execution__ = True
self.enqueue(5, self.exec_command)
else:
logger.debug("Execution in progress. Ignoring request...")
if __name__ == '__main__':
report.appLoggingConfigure(config.__BASEPATH__, config.LOGTARGET, ((config.APP_NAME, config.LOGLVL), ), fmt=config.formatter, host=config.LOGHOST, port=config.LOGPORT)
#
ec = exec_command()
ec.run()
#
while True:
time.sleep(30)
try:
ec.join()
finally:
ec.stop()

4
exec_command.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
#
BASEPATH=`dirname $0`
$BASEPATH/venv/bin/python $BASEPATH/exec_command.py

1
mqtt Submodule

@ -0,0 +1 @@
Subproject commit cf97fa066cdff0e2f7eda0ff4d3c8c0f59c3f2ec

1
report Submodule

@ -0,0 +1 @@
Subproject commit 21bac82e0c459ebf6d34783c9249526a657a6bbd

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
paho-mqtt

1
ring.wav Symbolic link
View File

@ -0,0 +1 @@
sounds/phone-incoming-call.wav

Binary file not shown.

BIN
sounds/suspend-error.wav Normal file

Binary file not shown.

1
task Submodule

@ -0,0 +1 @@
Subproject commit 7583bb5f3bd2420c901374ba95b678af6ce88433