Browse Source

command: added option -p/--power-setting

Fabian Peter Hammerle 3 years ago
parent
commit
5c72edc627
3 changed files with 26 additions and 11 deletions
  1. 1 0
      CHANGELOG.md
  2. 14 2
      intertechno_cc1101/_cli.py
  3. 11 9
      tests/test_cli.py

+ 1 - 0
CHANGELOG.md

@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Added
 - constant `DEFAULT_OUTPUT_POWER_SETTING`
 - methods `RemoteControl.turn_on/off`: optional keyword argument `output_power_setting`
+- command `intertechno-cc1101`: added option `-p` / `--power-setting`
 
 ### Changed
 - command `intertechno-cc1101`: no longer allow abbreviation of options / flags

+ 14 - 2
intertechno_cc1101/_cli.py

@@ -35,6 +35,14 @@ def _main():
     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_OUTPUT_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(
@@ -47,6 +55,10 @@ def _main():
     _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)
+        remote_control.turn_on(
+            button_index=args.button_index, output_power_setting=args.power_setting
+        )
     elif args.turn_off:
-        remote_control.turn_off(button_index=args.button_index)
+        remote_control.turn_off(
+            button_index=args.button_index, output_power_setting=args.power_setting
+        )

+ 11 - 9
tests/test_cli.py

@@ -8,16 +8,18 @@ import intertechno_cc1101._cli
 
 
 @pytest.mark.parametrize(
-    ("argv", "address", "button_index", "turn_on"),
+    ("argv", "address", "button_index", "turn_on", "power_setting"),
     (
-        (["-a", "12345678", "-1"], 12345678, 0, True),
-        (["-a", "12345678", "-0"], 12345678, 0, False),
-        (["--address", "12345678", "--turn-on"], 12345678, 0, True),
-        (["-a", "12345678", "--turn-off"], 12345678, 0, False),
-        (["-a", "12345678", "-b", "7", "-1"], 12345678, 7, True),
+        (["-a", "12345678", "-1"], 12345678, 0, True, 0xC6),
+        (["-a", "12345678", "-0"], 12345678, 0, False, 0xC6),
+        (["--address", "12345678", "--turn-on"], 12345678, 0, True, 0xC6),
+        (["-a", "12345678", "--turn-off"], 12345678, 0, False, 0xC6),
+        (["-a", "12345678", "-b", "7", "-1"], 12345678, 7, True, 0xC6),
+        (["-a", "12345678", "-1", "-p", str(0xC0)], 12345678, 0, True, 0xC0),
+        (["-a", "12345678", "-0", "--power-setting", "14"], 12345678, 0, False, 14),
     ),
 )
-def test__main(argv, address, button_index, turn_on):
+def test__main(argv, address, button_index, turn_on, power_setting):
     with unittest.mock.patch(
         "intertechno_cc1101.RemoteControl"
     ) as remote_control_class_mock, unittest.mock.patch("sys.argv", [""] + argv):
@@ -25,11 +27,11 @@ def test__main(argv, address, button_index, turn_on):
     remote_control_class_mock.assert_called_once_with(address=address)
     if turn_on:
         remote_control_class_mock().turn_on.assert_called_once_with(
-            button_index=button_index
+            button_index=button_index, output_power_setting=power_setting
         )
         remote_control_class_mock().turn_off.assert_not_called()
     else:
         remote_control_class_mock().turn_off.assert_called_once_with(
-            button_index=button_index
+            button_index=button_index, output_power_setting=power_setting
         )
         remote_control_class_mock().turn_on.assert_not_called()