Update config generator and converter to track deviceType change for UART

This commit is contained in:
brentru 2025-08-05 16:52:36 -04:00
parent fcf757c9b9
commit 7bde129844
2 changed files with 41 additions and 21 deletions

View file

@ -159,12 +159,12 @@ def convert_components_to_json():
# Special handling for GPS over I2C
if component_data.get("isGps", False):
print("**** GPS over I2C detected for component: " + component_dir)
component_info["isGps"] = True
if "commands_ubxes" in component_data:
component_info["commands_ubxes"] = component_data["commands_ubxes"]
if "commands_pmtks" in component_data:
component_info["commands_pmtks"] = component_data["commands_pmtks"]
gps_data = component_data.get("gps", {})
if "commands_ubxes" in gps_data:
component_info["gps"]["commands_ubxes"] = gps_data["commands_ubxes"]
if "commands_pmtks" in gps_data:
component_info["gps"]["commands_pmtks"] = gps_data["commands_pmtks"]
# Handle UART-specific properties
if category == "uart":
@ -173,8 +173,9 @@ def convert_components_to_json():
component_info["deviceId"] = component_data.get("deviceId")
# Specific device_type properties
if component_info["device_type"] == "generic_input":
# Parse generic input properties
component_info["period"] = component_data["generic_input"].get("period", 30000) # Default to 30s if not specified
component_info["generic_input"] = {}
generic_input_data = component_data.get("generic_input", {})
component_info["generic_input"]["period"] = generic_input_data.get("period", 30000)
# Extract data types
if "generic_input" in component_data and "sensor_types" in component_data["generic_input"]:
for meas_type in component_data["generic_input"]["sensor_types"]:
@ -186,17 +187,20 @@ def convert_components_to_json():
else:
component_info["dataTypes"].append(map_datatypes_to_offline_types(meas_type))
elif component_info["device_type"] == "gps":
component_info["period"] = component_data.get("period", 30000) # Default to 30s if not specified
if "commands_ubxes" in component_data:
component_info["commands_ubxes"] = component_data["commands_ubxes"]
if "commands_pmtks" in component_data:
component_info["commands_pmtks"] = component_data["commands_pmtks"]
component_info["gps"] = {}
gps_data = component_data.get("gps", {})
component_info["gps"]["period"] = gps_data.get("period", 30000)
if "commands_ubxes" in gps_data:
component_info["gps"]["commands_ubxes"] = gps_data["commands_ubxes"]
if "commands_pmtks" in gps_data:
component_info["gps"]["commands_pmtks"] = gps_data["commands_pmtks"]
elif component_info["device_type"] == "pm25aqi":
component_info["pm25aqi"] = {}
# Parse PM2.5 AQI properties
if "pm25aqi" in component_data:
component_info["period"] = component_data["pm25aqi"].get("period", 30000) # Default to 30s if not specified
component_info["pm25aqi"]["period"] = component_data["pm25aqi"].get("period", 30000) # Default to 30s if not specified
if component_data["pm25aqi"].get("is_pm1006", False):
component_info["is_pm1006"] = True
component_info["pm25aqi"]["is_pm1006"] = True
# Extract data types
pm25aqi_data = component_data
if "pm25aqi" in pm25aqi_data and "sensor_types" in pm25aqi_data["pm25aqi"]:
@ -208,12 +212,11 @@ def convert_components_to_json():
})
else:
component_info["dataTypes"].append(map_datatypes_to_offline_types(meas_type))
elif device_type == "tm22xx":
elif component_info["device_type"] == "tmc22xx":
# TODO
pass
else:
raise ValueError(f"Unknown deviceType {device_type} for {category}/{component_dir}")
raise ValueError(f"Unknown deviceType {component_info['device_type']} for {category}/{component_dir}")
# Look for an image file
image_extensions = ['.jpg', '.jpeg', '.png', '.gif', '.svg']

View file

@ -1676,15 +1676,32 @@ function saveModalData() {
componentConfig.deviceId = componentTemplate.deviceId;
}
// Add period if it exists in the component template
if (componentTemplate.gps && componentTemplate.gps.period) {
componentConfig.gps.period = componentTemplate.gps.period;
}
// Add UBX commands if they exist in the component template
if (componentTemplate.commands_ubxes) {
componentConfig.commands_ubxes = componentTemplate.commands_ubxes;
if (componentTemplate.gps && componentTemplate.gps.commands_ubxes) {
componentConfig.gps.commands_ubxes = componentTemplate.gps.commands_ubxes;
}
// Add PMTK commands if they exist in the component template
if (componentTemplate.commands_pmtks) {
componentConfig.commands_pmtks = componentTemplate.commands_pmtks;
if (componentTemplate.gps && componentTemplate.gps.commands_pmtks) {
componentConfig.gps.commands_pmtks = componentTemplate.gps.commands_pmtks;
}
// Add AQI period if it exists in the component template
if (componentTemplate.pm25aqi && componentTemplate.pm25aqi.period) {
componentConfig.pm25aqi.period = componentTemplate.pm25aqi.period;
}
// Add generic_input field if it exists in the component template
if (componentTemplate.generic_input && componentTemplate.generic_input.period) {
componentConfig.generic_input.period = componentTemplate.generic_input.period;
}
}
// Add component to the selected components list