Skip to content

Commit

Permalink
bugfix discovery and thing properties (#18003)
Browse files Browse the repository at this point in the history
Signed-off-by: Bernd Weymann <[email protected]>
  • Loading branch information
weymann authored Dec 30, 2024
1 parent 33d3577 commit 1b02f98
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ public ClientUpgradeRequest getClientUpgradeRequest() {
public void registerVin(String vin, VehicleHandler handler) {
discoveryService.vehicleRemove(this, vin, handler.getThing().getThingTypeUID().getId());
activeVehicleHandlerMap.put(vin, handler);
discovery(vin); // update properties for added vehicle
VEPUpdate updateForVin = vepUpdateMap.get(vin);
if (updateForVin != null) {
handler.enqueueUpdate(updateForVin);
Expand Down Expand Up @@ -340,7 +341,6 @@ private void handleMessage(byte[] array) {
PushMessage pm = VehicleEvents.PushMessage.parseFrom(array);
if (pm.hasVepUpdates()) {
boolean distributed = distributeVepUpdates(pm.getVepUpdates().getUpdatesMap());
logger.trace("Distributed VEPUpdate {}", distributed);
if (distributed) {
AcknowledgeVEPUpdatesByVIN ack = AcknowledgeVEPUpdatesByVIN.newBuilder()
.setSequenceNumber(pm.getVepUpdates().getSequenceNumber()).build();
Expand All @@ -349,7 +349,7 @@ private void handleMessage(byte[] array) {
}
} else if (pm.hasAssignedVehicles()) {
for (int i = 0; i < pm.getAssignedVehicles().getVinsCount(); i++) {
String vin = pm.getAssignedVehicles().getVins(0);
String vin = pm.getAssignedVehicles().getVins(i);
discovery(vin);
}
AcknowledgeAssignedVehicles ack = AcknowledgeAssignedVehicles.newBuilder().build();
Expand Down Expand Up @@ -394,6 +394,7 @@ public boolean distributeVepUpdates(Map<String, VEPUpdate> map) {
}
});
notFoundList.forEach(vin -> {
discovery(vin); // add vehicle to discovery
logger.trace("No VehicleHandler available for VIN {}", vin);
});
return notFoundList.isEmpty();
Expand All @@ -410,13 +411,18 @@ public void commandStatusUpdate(Map<String, AppTwinCommandStatusUpdatesByPID> up
});
}

/**
* Updates properties for existing handlers or delivers discovery result
*
* @param vin of discovered vehicle
*/
@SuppressWarnings("null")
public void discovery(String vin) {
if (activeVehicleHandlerMap.containsKey(vin)) {
VehicleHandler vh = activeVehicleHandlerMap.get(vin);
if (vh.getThing().getProperties().isEmpty()) {
vh.getThing().setProperties(getStringCapabilities(vin));
}
Map<String, String> properties = getStringCapabilities(vin);
properties.putAll(vh.getThing().getProperties());
vh.getThing().setProperties(properties);
} else {
if (!capabilitiesMap.containsKey(vin)) {
// only report new discovery if capabilities aren't discovered yet
Expand Down

0 comments on commit 1b02f98

Please sign in to comment.