Fix devicetype, sensorType, period

This commit is contained in:
brentru 2025-08-06 15:10:41 -04:00
parent 07daf2ba6b
commit ca2412d5a7
2 changed files with 18 additions and 18 deletions

View file

@ -169,10 +169,10 @@ def convert_components_to_json():
# Handle UART-specific properties
if category == "uart":
# Required properties
component_info["device_type"] = component_data.get("deviceType")
component_info["deviceType"] = component_data.get("deviceType")
component_info["deviceId"] = component_data.get("deviceId")
# Specific device_type properties
if component_info["device_type"] == "generic_input":
# Specific deviceType properties
if component_info["deviceType"] == "generic_input":
component_info["generic_input"] = {}
generic_input_data = component_data.get("generic_input", {})
component_info["generic_input"]["period"] = generic_input_data.get("period", 30000)
@ -186,7 +186,7 @@ def convert_components_to_json():
})
else:
component_info["dataTypes"].append(map_datatypes_to_offline_types(meas_type))
elif component_info["device_type"] == "gps":
elif component_info["deviceType"] == "gps":
component_info["gps"] = {}
gps_data = component_data.get("gps", {})
component_info["gps"]["period"] = gps_data.get("period", 30000)
@ -194,7 +194,7 @@ def convert_components_to_json():
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":
elif component_info["deviceType"] == "pm25aqi":
component_info["pm25aqi"] = {}
# Parse PM2.5 AQI properties
if "pm25aqi" in component_data:
@ -212,11 +212,11 @@ def convert_components_to_json():
})
else:
component_info["dataTypes"].append(map_datatypes_to_offline_types(meas_type))
elif component_info["device_type"] == "tmc22xx":
elif component_info["deviceType"] == "tmc22xx":
# TODO
pass
else:
raise ValueError(f"Unknown deviceType {component_info['device_type']} for {category}/{component_dir}")
raise ValueError(f"Unknown deviceType {component_info['deviceType']} for {category}/{component_dir}")
# Look for an image file
image_extensions = ['.jpg', '.jpeg', '.png', '.gif', '.svg']

View file

@ -1528,9 +1528,9 @@ function saveModalData() {
// Only add period for components that don't have their own period objects
if (!componentTemplate.isGps &&
componentTemplate.device_type !== 'gps' &&
componentTemplate.device_type !== 'pm25aqi' &&
componentTemplate.device_type !== 'generic_input') {
componentTemplate.deviceType !== 'gps' &&
componentTemplate.deviceType !== 'pm25aqi' &&
componentTemplate.deviceType !== 'generic_input') {
componentConfig.period = period;
}
let validationError = false; // future use
@ -1688,17 +1688,17 @@ function saveModalData() {
if (dataTypeCheckboxes.length > 0) {
componentConfig.sensorTypes = Array.from(dataTypeCheckboxes).map(checkbox => {
try {
return JSON.parse(checkbox.value);
return { type: JSON.parse(checkbox.value) };
} catch (e) {
return checkbox.value;
return { type: checkbox.value };
}
});
}
// UART-Specific //
// Add device_type field if it exists in the component template
if (componentTemplate.device_type) {
componentConfig.device_type = componentTemplate.device_type;
// Add deviceType field if it exists in the component template
if (componentTemplate.deviceType) {
componentConfig.deviceType = componentTemplate.deviceType;
}
// Add deviceId field if it exists in the component template
@ -1707,7 +1707,7 @@ function saveModalData() {
}
// Add GPS fields if this is a GPS component
if (componentTemplate.device_type === 'gps') {
if (componentTemplate.deviceType === 'gps') {
if (!componentConfig.gps) {
componentConfig.gps = {};
}
@ -1715,7 +1715,7 @@ function saveModalData() {
}
// Add PM25AQI fields if this is a PM25AQI component
if (componentTemplate.device_type === 'pm25aqi') {
if (componentTemplate.deviceType === 'pm25aqi') {
if (!componentConfig.pm25aqi) {
componentConfig.pm25aqi = {};
}
@ -1723,7 +1723,7 @@ function saveModalData() {
}
// Add generic_input fields if this is a generic_input component
if (componentTemplate.device_type === 'generic_input') {
if (componentTemplate.deviceType === 'generic_input') {
if (!componentConfig.generic_input) {
componentConfig.generic_input = {};
}