Browse Source

added option `--power-setting`

Fabian Peter Hammerle 3 years ago
parent
commit
d5415225ae
4 changed files with 31 additions and 3 deletions
  1. 2 0
      CHANGELOG.md
  2. 4 2
      docker-compose.yml
  3. 8 1
      intertechno_cc1101_mqtt/__init__.py
  4. 17 0
      tests/test_cli.py

+ 2 - 0
CHANGELOG.md

@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 
 ## [Unreleased]
+### Added
+- option `--power-setting`
 
 ## [0.1.0] - 2021-02-06
 ### Added

+ 4 - 2
docker-compose.yml

@@ -24,11 +24,13 @@ services:
     build: .
     image: fphammerle/intertechno-cc1101-mqtt
     #volumes:
-    #- config:/etc/wireless-sensor-mqtt:ro
+    #- config:/etc/intertechno-cc1101-mqtt:ro
     command: intertechno-cc1101-mqtt
       --mqtt-host broker
     #  --mqtt-username raspberrypi
-    #  --mqtt-password-file /etc/wireless-sensor-mqtt/mqtt-password
+    #  --mqtt-password-file /etc/intertechno-cc1101-mqtt/mqtt-password
+    #  --alias-file /etc/intertechno-cc1101-mqtt/aliases.json
+    #  --power-setting 29
     devices: [/dev/spidev0.0]
     read_only: true
     cap_drop: [all]

+ 8 - 1
intertechno_cc1101_mqtt/__init__.py

@@ -229,6 +229,13 @@ def _main() -> None:
             )
         ),
     )
+    argparser.add_argument(
+        "--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)",
+    )
     args = argparser.parse_args()
     if args.mqtt_password_path:
         # .read_text() replaces \r\n with \n
@@ -245,5 +252,5 @@ def _main() -> None:
         mqtt_username=args.mqtt_username,
         mqtt_password=mqtt_password,
         alias_file_path=args.alias_file_path,
-        power_setting=intertechno_cc1101.DEFAULT_POWER_SETTING,
+        power_setting=args.power_setting,
     )

+ 17 - 0
tests/test_cli.py

@@ -162,3 +162,20 @@ def test__main_alias_file():
         alias_file_path=pathlib.Path("/etc/intertechno-cc1101-mqtt/aliases.json"),
         power_setting=0xC6,
     )
+
+
+def test__main_power_setting():
+    with unittest.mock.patch(
+        "intertechno_cc1101_mqtt._run"
+    ) as run_mock, unittest.mock.patch(
+        "sys.argv", ["", "--mqtt-host", "broker", "--power-setting", "29"]
+    ):
+        intertechno_cc1101_mqtt._main()
+    run_mock.assert_called_once_with(
+        mqtt_host="broker",
+        mqtt_port=1883,
+        mqtt_username=None,
+        mqtt_password=None,
+        alias_file_path=None,
+        power_setting=0x1D,  # -15dBm
+    )