summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/gpiorelayd.py17
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...')