Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mercedesme] Fix initial update of Thing properties #18003

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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