bugfix discovery and thing properties (#18003)

Signed-off-by: Bernd Weymann <bernd.weymann@gmail.com>
This commit is contained in:
Bernd Weymann 2024-12-30 13:05:20 +01:00 committed by GitHub
parent 33d3577230
commit 1b02f98b46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -271,6 +271,7 @@ public class AccountHandler extends BaseBridgeHandler implements AccessTokenRefr
public void registerVin(String vin, VehicleHandler handler) { public void registerVin(String vin, VehicleHandler handler) {
discoveryService.vehicleRemove(this, vin, handler.getThing().getThingTypeUID().getId()); discoveryService.vehicleRemove(this, vin, handler.getThing().getThingTypeUID().getId());
activeVehicleHandlerMap.put(vin, handler); activeVehicleHandlerMap.put(vin, handler);
discovery(vin); // update properties for added vehicle
VEPUpdate updateForVin = vepUpdateMap.get(vin); VEPUpdate updateForVin = vepUpdateMap.get(vin);
if (updateForVin != null) { if (updateForVin != null) {
handler.enqueueUpdate(updateForVin); handler.enqueueUpdate(updateForVin);
@ -340,7 +341,6 @@ public class AccountHandler extends BaseBridgeHandler implements AccessTokenRefr
PushMessage pm = VehicleEvents.PushMessage.parseFrom(array); PushMessage pm = VehicleEvents.PushMessage.parseFrom(array);
if (pm.hasVepUpdates()) { if (pm.hasVepUpdates()) {
boolean distributed = distributeVepUpdates(pm.getVepUpdates().getUpdatesMap()); boolean distributed = distributeVepUpdates(pm.getVepUpdates().getUpdatesMap());
logger.trace("Distributed VEPUpdate {}", distributed);
if (distributed) { if (distributed) {
AcknowledgeVEPUpdatesByVIN ack = AcknowledgeVEPUpdatesByVIN.newBuilder() AcknowledgeVEPUpdatesByVIN ack = AcknowledgeVEPUpdatesByVIN.newBuilder()
.setSequenceNumber(pm.getVepUpdates().getSequenceNumber()).build(); .setSequenceNumber(pm.getVepUpdates().getSequenceNumber()).build();
@ -349,7 +349,7 @@ public class AccountHandler extends BaseBridgeHandler implements AccessTokenRefr
} }
} else if (pm.hasAssignedVehicles()) { } else if (pm.hasAssignedVehicles()) {
for (int i = 0; i < pm.getAssignedVehicles().getVinsCount(); i++) { for (int i = 0; i < pm.getAssignedVehicles().getVinsCount(); i++) {
String vin = pm.getAssignedVehicles().getVins(0); String vin = pm.getAssignedVehicles().getVins(i);
discovery(vin); discovery(vin);
} }
AcknowledgeAssignedVehicles ack = AcknowledgeAssignedVehicles.newBuilder().build(); AcknowledgeAssignedVehicles ack = AcknowledgeAssignedVehicles.newBuilder().build();
@ -394,6 +394,7 @@ public class AccountHandler extends BaseBridgeHandler implements AccessTokenRefr
} }
}); });
notFoundList.forEach(vin -> { notFoundList.forEach(vin -> {
discovery(vin); // add vehicle to discovery
logger.trace("No VehicleHandler available for VIN {}", vin); logger.trace("No VehicleHandler available for VIN {}", vin);
}); });
return notFoundList.isEmpty(); return notFoundList.isEmpty();
@ -410,13 +411,18 @@ public class AccountHandler extends BaseBridgeHandler implements AccessTokenRefr
}); });
} }
/**
* Updates properties for existing handlers or delivers discovery result
*
* @param vin of discovered vehicle
*/
@SuppressWarnings("null") @SuppressWarnings("null")
public void discovery(String vin) { public void discovery(String vin) {
if (activeVehicleHandlerMap.containsKey(vin)) { if (activeVehicleHandlerMap.containsKey(vin)) {
VehicleHandler vh = activeVehicleHandlerMap.get(vin); VehicleHandler vh = activeVehicleHandlerMap.get(vin);
if (vh.getThing().getProperties().isEmpty()) { Map<String, String> properties = getStringCapabilities(vin);
vh.getThing().setProperties(getStringCapabilities(vin)); properties.putAll(vh.getThing().getProperties());
} vh.getThing().setProperties(properties);
} else { } else {
if (!capabilitiesMap.containsKey(vin)) { if (!capabilitiesMap.containsKey(vin)) {
// only report new discovery if capabilities aren't discovered yet // only report new discovery if capabilities aren't discovered yet