Start and Stop sending via IR implemented
This commit is contained in:
parent
afc1509050
commit
1f591b6ca3
@ -17,7 +17,8 @@ logger = logging.getLogger(ROOT_LOGGER_NAME).getChild('main')
|
||||
class remote_control(object):
|
||||
def __init__(self):
|
||||
self.__lirc_client__ = lirc.Client()
|
||||
|
||||
self.__start_data__ = None
|
||||
#
|
||||
self.__client__ = mqtt.Client(config.APP_NAME) # create client object
|
||||
self.__client__.on_message = self.__receive__ # attach function to callback
|
||||
self.__client__.username_pw_set(config.MQTT_USER, config.MQTT_PASS) # login with credentials
|
||||
@ -37,19 +38,47 @@ class remote_control(object):
|
||||
payload = json.loads(message.payload)
|
||||
except json.decoder.JSONDecodeError:
|
||||
payload = None
|
||||
if payload is None:
|
||||
#
|
||||
remote = message.topic.split("/")[-2]
|
||||
command = message.topic.split("/")[-1]
|
||||
if payload is None:
|
||||
if self.__start_data__ is not None:
|
||||
self.__send_stop__(*self.__start_data__)
|
||||
self.__start_data__ = None
|
||||
self.__send_once__(remote, command)
|
||||
elif payload is True:
|
||||
if self.__start_data__ is not None:
|
||||
self.__send_stop__(*self.__start_data__)
|
||||
self.__start_data__ = None
|
||||
self.__start_data__ = remote, command
|
||||
self.__send_start__(remote, command)
|
||||
elif payload is False:
|
||||
if self.__start_data__ is None:
|
||||
self.__send_stop__(remote, command)
|
||||
else:
|
||||
self.__send_stop__(*self.__start_data__)
|
||||
self.__start_data__ = None
|
||||
|
||||
def __send_once__(self, remote, command):
|
||||
try:
|
||||
self.__lirc_client__.send_once(remote, command)
|
||||
except TimeoutError:
|
||||
logger.exception("Timeout-Error while sending IR-Command.")
|
||||
logger.info("Sending once: %s to %s.", command, remote)
|
||||
elif payload is True:
|
||||
logger.warning("Start of remote command NYI!")
|
||||
elif payload is False:
|
||||
logger.warning("Stop of remote command NYI!")
|
||||
|
||||
def __send_start__(self, remote, command):
|
||||
try:
|
||||
self.__lirc_client__.send_start(remote, command)
|
||||
except TimeoutError:
|
||||
logger.exception("Timeout-Error while sending IR-Command.")
|
||||
logger.info("Sending start: %s to %s.", command, remote)
|
||||
|
||||
def __send_stop__(self, remote, command):
|
||||
try:
|
||||
self.__lirc_client__.send_stop(remote, command)
|
||||
except TimeoutError:
|
||||
logger.exception("Timeout-Error while sending IR-Command.")
|
||||
logger.info("Sending stop: %s to %s.", command, remote)
|
||||
|
||||
if __name__ == '__main__':
|
||||
report.appLoggingConfigure(config.__BASEPATH__, config.LOGTARGET, ((config.APP_NAME, config.LOGLVL), ), fmt=config.formatter, host=config.LOGHOST, port=config.LOGPORT)
|
||||
|
Loading…
x
Reference in New Issue
Block a user