diff --git a/bundles/org.openhab.binding.mercedesme/src/main/java/org/openhab/binding/mercedesme/internal/handler/AccountHandler.java b/bundles/org.openhab.binding.mercedesme/src/main/java/org/openhab/binding/mercedesme/internal/handler/AccountHandler.java index ab2d583ad0cb1..b5d6e8646d8b9 100644 --- a/bundles/org.openhab.binding.mercedesme/src/main/java/org/openhab/binding/mercedesme/internal/handler/AccountHandler.java +++ b/bundles/org.openhab.binding.mercedesme/src/main/java/org/openhab/binding/mercedesme/internal/handler/AccountHandler.java @@ -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); @@ -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(); @@ -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(); @@ -394,6 +394,7 @@ public boolean distributeVepUpdates(Map map) { } }); notFoundList.forEach(vin -> { + discovery(vin); // add vehicle to discovery logger.trace("No VehicleHandler available for VIN {}", vin); }); return notFoundList.isEmpty(); @@ -410,13 +411,18 @@ public void commandStatusUpdate(Map 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 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