Skip to content

Commit

Permalink
fix message upgrade when gateway.family field present (#905)
Browse files Browse the repository at this point in the history
  • Loading branch information
noursaidi authored Jun 11, 2024
1 parent aa1b1e4 commit 86cf4af
Show file tree
Hide file tree
Showing 8 changed files with 528 additions and 3 deletions.
16 changes: 13 additions & 3 deletions common/src/main/java/com/google/udmi/util/MessageUpgrader.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,20 @@ private void upgradeTo_1_4_1_metadata() {
ObjectNode gatewayTarget = new ObjectNode(NODE_FACTORY);
gateway.put("target", gatewayTarget);

if (localnetFamilies.has("bacnet")) {
gatewayTarget.put("family", "bacnet");
final String targetFamily;
if (gateway.has("family")) {
targetFamily = gateway.remove("family").asText();
} else if (localnetFamilies.has("bacnet")) {
// Prioritise "bacnet" over any other value
targetFamily = "bacnet";
} else if (localnetFamilies.has("vendor")) {
gatewayTarget.put("family", "vendor");
targetFamily = "vendor";
} else {
targetFamily = null;
}

if (targetFamily != null) {
gatewayTarget.put("family", targetFamily);
}
}

Expand Down
114 changes: 114 additions & 0 deletions tests/sites/downgrade/devices/AHU-102/expected/generated_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
"timestamp": "2024-06-11T08:31:26Z",
"version": "1.4.0",
"system": {
"min_loglevel": 300,
"metrics_rate_sec": 10,
"operation": { }
},
"gateway": { },
"localnet": {
"families": {
"bacnet": {
"addr": "11052"
}
}
},
"pointset": {
"points": {
"cooling_water_valve_percentage_command": {
"ref": "AO10.Present_Value",
"units": "percent"
},
"cooling_water_valve_percentage_sensor": {
"ref": "AI9.Present_Value",
"units": "percent"
},
"exhaust_air_damper_command": {
"ref": "BO2.Present_Value",
"units": "No-units"
},
"exhaust_air_static_pressure_sensor": {
"ref": "AI6.Present_Value",
"units": "pascals"
},
"exhaust_fan_run_command": {
"ref": "BO5.Present_Value",
"units": "No-units"
},
"exhaust_fan_speed_percentage_command": {
"ref": "AO6.Present_Value",
"units": "percent"
},
"exhaust_fan_speed_percentage_sensor": {
"ref": "AI5.Present_Value",
"units": "percent"
},
"exhaust_fan_speed_percentage_setpoint": {
"ref": "AV3.Present_Value",
"units": "percent"
},
"exhaust_filter_differential_pressure_sensor": {
"ref": "AI4.Present_Value",
"units": "pascals"
},
"fire_alarm": {
"ref": "BI3.Present_Value",
"units": "No-units"
},
"heating_water_valve_percentage_command": {
"ref": "AO9.Present_Value",
"units": "percent"
},
"heating_water_valve_percentage_sensor": {
"ref": "AI10.Present_Value",
"units": "percent"
},
"outside_air_temperature_sensor": {
"ref": "AI17.Present_Value",
"units": "degrees-celcius"
},
"return_air_temperature_sensor": {
"ref": "AI3.Present_Value",
"units": "degrees-celcius"
},
"supply_air_damper_command": {
"ref": "BO1.Present_Value",
"units": "No-units"
},
"supply_air_static_pressure_sensor": {
"ref": "AI3.Present_Value",
"units": "pascals"
},
"supply_air_temperature_sensor": {
"ref": "AI12.Present_Value",
"units": "degrees-celcius"
},
"supply_air_temperature_setpoint": {
"ref": "AI20.Present_Value",
"units": "degrees-celcius"
},
"supply_fan_run_command": {
"ref": "BO3.Present_Value",
"units": "No-units"
},
"supply_fan_speed_percentage_command": {
"ref": "AO4.Present_Value",
"units": "percent"
},
"supply_fan_speed_percentage_sensor": {
"ref": "AI2.Present_Value",
"units": "percent"
},
"supply_fan_speed_percentage_setpoint": {
"ref": "AV2.Present_Value",
"units": "percent"
},
"supply_filter_differential_pressure_sensor": {
"ref": "AI1.Present_Value",
"units": "pascals"
}
}
},
"downgraded_from": "1.5.0"
}
158 changes: 158 additions & 0 deletions tests/sites/downgrade/devices/AHU-102/expected/metadata_norm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"timestamp": "2024-06-11T08:31:26Z",
"version": "1.4.1",
"upgraded_from": "1.4.0",
"hash": "fd811951",
"tags": [ ],
"system": {
"location": {
"site": "US-SFO-XYY",
"section": "L01-NW",
"position": {
"x": 10.0,
"y": 10.0,
"z": 10.0
}
},
"physical_tag": {
"asset": {
"guid": "guid://bbfe8b4b-e9e5-424b-9a4e-2234b61c41bf",
"site": "US-SFO-XYY",
"name": "AHU-102"
}
},
"min_loglevel": 300
},
"gateway": {
"gateway_id": "CGW-1",
"target": {
"family": "bacnet"
}
},
"localnet": {
"families": {
"bacnet": {
"addr": "11052"
}
}
},
"pointset": {
"points": {
"cooling_water_valve_percentage_command": {
"units": "percent",
"ref": "AO10.Present_Value",
"tags": [ ]
},
"cooling_water_valve_percentage_sensor": {
"units": "percent",
"ref": "AI9.Present_Value",
"tags": [ ]
},
"exhaust_air_damper_command": {
"units": "No-units",
"ref": "BO2.Present_Value",
"tags": [ ]
},
"exhaust_air_static_pressure_sensor": {
"units": "pascals",
"ref": "AI6.Present_Value",
"tags": [ ]
},
"exhaust_fan_run_command": {
"units": "No-units",
"ref": "BO5.Present_Value",
"tags": [ ]
},
"exhaust_fan_speed_percentage_command": {
"units": "percent",
"ref": "AO6.Present_Value",
"tags": [ ]
},
"exhaust_fan_speed_percentage_sensor": {
"units": "percent",
"ref": "AI5.Present_Value",
"tags": [ ]
},
"exhaust_fan_speed_percentage_setpoint": {
"units": "percent",
"ref": "AV3.Present_Value",
"tags": [ ]
},
"exhaust_filter_differential_pressure_sensor": {
"units": "pascals",
"ref": "AI4.Present_Value",
"tags": [ ]
},
"fire_alarm": {
"units": "No-units",
"ref": "BI3.Present_Value",
"tags": [ ]
},
"heating_water_valve_percentage_command": {
"units": "percent",
"ref": "AO9.Present_Value",
"tags": [ ]
},
"heating_water_valve_percentage_sensor": {
"units": "percent",
"ref": "AI10.Present_Value",
"tags": [ ]
},
"outside_air_temperature_sensor": {
"units": "degrees-celcius",
"ref": "AI17.Present_Value",
"tags": [ ]
},
"return_air_temperature_sensor": {
"units": "degrees-celcius",
"ref": "AI3.Present_Value",
"tags": [ ]
},
"supply_air_damper_command": {
"units": "No-units",
"ref": "BO1.Present_Value",
"tags": [ ]
},
"supply_air_static_pressure_sensor": {
"units": "pascals",
"ref": "AI3.Present_Value",
"tags": [ ]
},
"supply_air_temperature_sensor": {
"units": "degrees-celcius",
"ref": "AI12.Present_Value",
"tags": [ ]
},
"supply_air_temperature_setpoint": {
"units": "degrees-celcius",
"ref": "AI20.Present_Value",
"tags": [ ]
},
"supply_fan_run_command": {
"units": "No-units",
"ref": "BO3.Present_Value",
"tags": [ ]
},
"supply_fan_speed_percentage_command": {
"units": "percent",
"ref": "AO4.Present_Value",
"tags": [ ]
},
"supply_fan_speed_percentage_sensor": {
"units": "percent",
"ref": "AI2.Present_Value",
"tags": [ ]
},
"supply_fan_speed_percentage_setpoint": {
"units": "percent",
"ref": "AV2.Present_Value",
"tags": [ ]
},
"supply_filter_differential_pressure_sensor": {
"units": "pascals",
"ref": "AI1.Present_Value",
"tags": [ ]
}
}
}
}
Loading

0 comments on commit 86cf4af

Please sign in to comment.