12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import argparse
- import logging
- import intertechno_cc1101
- _LOGGER = logging.getLogger(__name__)
- def _main():
- argparser = argparse.ArgumentParser(
- description="Control Intertechno Outlets via CC1101 Transceivers",
- allow_abbrev=False,
- )
- 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(
- "-p",
- "--power-setting",
- type=int,
- default=intertechno_cc1101.DEFAULT_POWER_SETTING,
- help='see "Table 39: Optimum PATABLE Settings for Various Output Power Levels […]"'
- " in CC1101's docs (default: %(default)d / 0x%(default)X)",
- )
- 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, power_setting=args.power_setting
- )
- elif args.turn_off:
- remote_control.turn_off(
- button_index=args.button_index, power_setting=args.power_setting
- )
|