From b0bf43e6a272d42a55158e657bd937cb82fc3d8d Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Sat, 10 Jun 2023 23:02:34 +0300 Subject: move files, rename home package to homekit --- bin/gpiorelayd.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 bin/gpiorelayd.py (limited to 'bin/gpiorelayd.py') diff --git a/bin/gpiorelayd.py b/bin/gpiorelayd.py new file mode 100755 index 0000000..1f4d2e2 --- /dev/null +++ b/bin/gpiorelayd.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +import logging +import os +import sys +import __py_include + +from homekit.config import config +from homekit.relay.sunxi_h3_server import RelayServer + +logger = logging.getLogger(__name__) + + +if __name__ == '__main__': + if not os.getegid() == 0: + sys.exit('Must be run as root.') + + config.load_app() + + try: + s = RelayServer(pinname=config.get('relayd.pin'), + addr=config.get_addr('relayd.listen')) + s.run() + except KeyboardInterrupt: + logger.info('Exiting...') -- cgit v1.2.3 From a3d6fadb2e99a87346d5b4f2c97755cc6f17f3b7 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Sun, 11 Jun 2023 02:33:22 +0300 Subject: gpiorelayd: get rid of config, use command line arguments instead --- bin/gpiorelayd.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'bin/gpiorelayd.py') diff --git a/bin/gpiorelayd.py b/bin/gpiorelayd.py index 1f4d2e2..89ba78e 100755 --- a/bin/gpiorelayd.py +++ b/bin/gpiorelayd.py @@ -4,6 +4,8 @@ import os import sys import __py_include +from argparse import ArgumentParser +from homekit.util import Addr from homekit.config import config from homekit.relay.sunxi_h3_server import RelayServer @@ -11,14 +13,19 @@ logger = logging.getLogger(__name__) if __name__ == '__main__': - if not os.getegid() == 0: + if os.getegid() != 0: sys.exit('Must be run as root.') - config.load_app() + parser = ArgumentParser() + parser.add_argument('--pin', type=str, required=True, + help='name of GPIO pin of Allwinner H3 sunxi board') + parser.add_argument('--listen', type=str, required=True, + help='address to listen to, in ip:port format') + + arg = config.load_app(no_config=True, parser=parser) + listen = Addr.fromstring(arg.listen) try: - s = RelayServer(pinname=config.get('relayd.pin'), - addr=config.get_addr('relayd.listen')) - s.run() + RelayServer(pinname=arg.pin, addr=listen).run() except KeyboardInterrupt: logger.info('Exiting...') -- cgit v1.2.3