diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2023-06-11 02:33:22 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2023-06-11 02:33:22 +0300 |
commit | a3d6fadb2e99a87346d5b4f2c97755cc6f17f3b7 (patch) | |
tree | ebb73473f3b6808b5d1a44473c4000f5e4f6c404 /bin | |
parent | eaab12b8f4722ceae1039e4745088c555d6cbd1e (diff) |
gpiorelayd: get rid of config, use command line arguments instead
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/gpiorelayd.py | 17 |
1 files changed, 12 insertions, 5 deletions
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...') |