Browse Source

draft command-line tool "intertechno-cc1101"

Fabian Peter Hammerle 3 years ago
parent
commit
f9bd9e52b9
2 changed files with 54 additions and 1 deletions
  1. 51 0
      intertechno_cc1101/_cli.py
  2. 3 1
      setup.py

+ 51 - 0
intertechno_cc1101/_cli.py

@@ -0,0 +1,51 @@
+import argparse
+import logging
+
+import intertechno_cc1101
+
+_LOGGER = logging.getLogger(__name__)
+
+
+def _main():
+    argparser = argparse.ArgumentParser(
+        description="Control Intertechno Outlets via CC1101 Transceivers"
+    )
+    argparser.add_argument(
+        "-a",
+        "--address",
+        type=int,
+        help="address of emulated remote control ({}-bit unsigned integer)".format(
+            # pylint: disable=protected-access; internal
+            intertechno_cc1101._ADDRESS_LENGTH_BITS
+        ),
+        required=True,
+    )
+    argparser.add_argument(
+        "-b",
+        "--button-index",
+        type=int,
+        help="index of button on emulated remote control"
+        " ({}-bit unsigned integer, default: %(default)d)".format(
+            # pylint: disable=protected-access; internal
+            intertechno_cc1101._BUTTON_INDEX_LENGTH_BITS
+        ),
+        default=0,
+    )
+    action_arg_group = argparser.add_mutually_exclusive_group(required=True)
+    action_arg_group.add_argument("-1", "--turn-on", action="store_true")
+    action_arg_group.add_argument("-0", "--turn-off", action="store_true")
+    argparser.add_argument("-d", "--debug", action="store_true")
+    args = argparser.parse_args()
+    logging.basicConfig(
+        level=logging.DEBUG if args.debug else logging.INFO,
+        format="%(asctime)s:%(levelname)s:%(name)s:%(funcName)s:%(message)s"
+        if args.debug
+        else "%(message)s",
+        datefmt="%Y-%m-%dT%H:%M:%S%z",
+    )
+    _LOGGER.debug("args=%r", args)
+    remote_control = intertechno_cc1101.RemoteControl(address=args.address)
+    if args.turn_on:
+        remote_control.turn_on(button_index=args.button_index)
+    else:
+        remote_control.turn_on(button_index=args.button_index)

+ 3 - 1
setup.py

@@ -34,7 +34,9 @@ setuptools.setup(
         "Operating System :: POSIX :: Linux",
         "Topic :: Home Automation",
     ],
-    # entry_points={"console_scripts": ["switchbot-mqtt = switchbot_mqtt:_main"]},
+    entry_points={
+        "console_scripts": ["intertechno-cc1101 = intertechno_cc1101._cli:_main"]
+    },
     install_requires=[
         # >=2.7.0 for CC1101.set_output_power()
         "cc1101>=2.7.0"