diff --git a/test/data-parse-test.py b/test/data-parse-test.py index 85266344..c52493ba 100755 --- a/test/data-parse-test.py +++ b/test/data-parse-test.py @@ -275,6 +275,20 @@ def validate_data_file_name(path: str): ) +SINOWEALTH_DEVICE_SECTION_PREFIX = "Driver/sinowealth/devices/" +SINOWEALTH_REQUIRED_KEYS = ( + "DeviceName", + "FwVersion", + "LedType", +) +SINOWEALTH_PERMITTED_KEYS = ( + *SINOWEALTH_REQUIRED_KEYS, + "ButtonCount", + "ProfileCount", + "SensorType", +) + + def parse_data_file(path: str): print(f"Parsing file {path}") data = configparser.ConfigParser(strict=True) @@ -289,9 +303,19 @@ def parse_data_file(path: str): driver_section = f"Driver/{driver}" permitted_sections = ["Device", driver_section] - # FIXME: remove this once `sinowealth` driver has a better way of defining data. + # The sinowealth driver uses non-static section names in device files as it + # uses a single device file for several actual devices. See the example + # device file for details. if driver == "sinowealth": - print("Skipping `Driver` section check for a `sinowealth` device") + for device_section_name in data.sections(): + if not device_section_name.startswith(SINOWEALTH_DEVICE_SECTION_PREFIX): + continue + + device_section = data[device_section_name] + for key in SINOWEALTH_REQUIRED_KEYS: + assert key in device_section + for key in device_section: + assert key in SINOWEALTH_PERMITTED_KEYS else: for s in data.sections(): assert s in permitted_sections