2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.hue.internal.handler;
15 import static org.openhab.binding.hue.internal.HueBindingConstants.*;
17 import java.math.BigDecimal;
18 import java.time.Duration;
19 import java.time.Instant;
20 import java.util.Collection;
21 import java.util.HashMap;
22 import java.util.HashSet;
23 import java.util.List;
25 import java.util.Objects;
27 import java.util.concurrent.ConcurrentHashMap;
28 import java.util.concurrent.CopyOnWriteArrayList;
29 import java.util.concurrent.Future;
30 import java.util.concurrent.TimeUnit;
31 import java.util.stream.Collectors;
33 import org.eclipse.jdt.annotation.NonNullByDefault;
34 import org.eclipse.jdt.annotation.Nullable;
35 import org.openhab.binding.hue.internal.action.DynamicsActions;
36 import org.openhab.binding.hue.internal.config.Clip2ThingConfig;
37 import org.openhab.binding.hue.internal.dto.clip2.Alerts;
38 import org.openhab.binding.hue.internal.dto.clip2.ColorXy;
39 import org.openhab.binding.hue.internal.dto.clip2.Dimming;
40 import org.openhab.binding.hue.internal.dto.clip2.Effects;
41 import org.openhab.binding.hue.internal.dto.clip2.Gamut2;
42 import org.openhab.binding.hue.internal.dto.clip2.MetaData;
43 import org.openhab.binding.hue.internal.dto.clip2.MirekSchema;
44 import org.openhab.binding.hue.internal.dto.clip2.ProductData;
45 import org.openhab.binding.hue.internal.dto.clip2.Resource;
46 import org.openhab.binding.hue.internal.dto.clip2.ResourceReference;
47 import org.openhab.binding.hue.internal.dto.clip2.Resources;
48 import org.openhab.binding.hue.internal.dto.clip2.enums.ActionType;
49 import org.openhab.binding.hue.internal.dto.clip2.enums.EffectType;
50 import org.openhab.binding.hue.internal.dto.clip2.enums.RecallAction;
51 import org.openhab.binding.hue.internal.dto.clip2.enums.ResourceType;
52 import org.openhab.binding.hue.internal.dto.clip2.enums.ZigbeeStatus;
53 import org.openhab.binding.hue.internal.dto.clip2.helper.Setters;
54 import org.openhab.binding.hue.internal.exceptions.ApiException;
55 import org.openhab.binding.hue.internal.exceptions.AssetNotLoadedException;
56 import org.openhab.core.library.types.DateTimeType;
57 import org.openhab.core.library.types.DecimalType;
58 import org.openhab.core.library.types.HSBType;
59 import org.openhab.core.library.types.IncreaseDecreaseType;
60 import org.openhab.core.library.types.OnOffType;
61 import org.openhab.core.library.types.PercentType;
62 import org.openhab.core.library.types.QuantityType;
63 import org.openhab.core.library.types.StringType;
64 import org.openhab.core.library.unit.MetricPrefix;
65 import org.openhab.core.library.unit.Units;
66 import org.openhab.core.thing.Bridge;
67 import org.openhab.core.thing.Channel;
68 import org.openhab.core.thing.ChannelUID;
69 import org.openhab.core.thing.Thing;
70 import org.openhab.core.thing.ThingRegistry;
71 import org.openhab.core.thing.ThingStatus;
72 import org.openhab.core.thing.ThingStatusDetail;
73 import org.openhab.core.thing.ThingTypeUID;
74 import org.openhab.core.thing.ThingUID;
75 import org.openhab.core.thing.binding.BaseThingHandler;
76 import org.openhab.core.thing.binding.BridgeHandler;
77 import org.openhab.core.thing.binding.ThingHandlerService;
78 import org.openhab.core.thing.binding.builder.ThingBuilder;
79 import org.openhab.core.thing.link.ItemChannelLink;
80 import org.openhab.core.thing.link.ItemChannelLinkRegistry;
81 import org.openhab.core.types.Command;
82 import org.openhab.core.types.RefreshType;
83 import org.openhab.core.types.State;
84 import org.openhab.core.types.StateOption;
85 import org.openhab.core.types.UnDefType;
86 import org.slf4j.Logger;
87 import org.slf4j.LoggerFactory;
90 * Handler for things based on CLIP 2 'device', 'room', or 'zone resources.
92 * @author Andrew Fiddian-Green - Initial contribution.
95 public class Clip2ThingHandler extends BaseThingHandler {
97 public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Set.of(THING_TYPE_DEVICE, THING_TYPE_ROOM,
100 private static final Duration DYNAMICS_ACTIVE_WINDOW = Duration.ofSeconds(10);
102 private static final String LK_WISER_DIMMER_MODEL_ID = "LK Dimmer";
104 private final Logger logger = LoggerFactory.getLogger(Clip2ThingHandler.class);
107 * A map of service Resources whose state contributes to the overall state of this thing. It is a map between the
108 * resource ID (string) and a Resource object containing the last known state. e.g. a DEVICE thing may support a
109 * LIGHT service whose Resource contributes to its overall state, or a ROOM or ZONE thing may support a
110 * GROUPED_LIGHT service whose Resource contributes to the its overall state.
112 private final Map<String, Resource> serviceContributorsCache = new ConcurrentHashMap<>();
115 * A map of Resource IDs which are targets for commands to be sent. It is a map between the type of command
116 * (ResourcesType) and the resource ID to which the command shall be sent. e.g. a LIGHT 'on' command shall be sent
117 * to the respective LIGHT resource ID.
119 private final Map<ResourceType, String> commandResourceIds = new ConcurrentHashMap<>();
122 * Button devices contain one or more physical buttons, each of which is represented by a BUTTON Resource with its
123 * own unique resource ID, and a respective controlId that indicates which button it is in the device. e.g. a dimmer
124 * pad has four buttons (controlId's 1..4) each represented by a BUTTON Resource with a unique resource ID. This is
125 * a map between the resource ID and its respective controlId.
127 private final Map<String, Integer> controlIds = new ConcurrentHashMap<>();
130 * The set of channel IDs that are supported by this thing. e.g. an on/off light may support 'switch' and
131 * 'zigbeeStatus' channels, whereas a complex light may support 'switch', 'brightness', 'color', 'color temperature'
132 * and 'zigbeeStatus' channels.
134 private final Set<String> supportedChannelIdSet = new HashSet<>();
137 * A map of scene IDs and respective scene Resources for the scenes that contribute to and command this thing. It is
138 * a map between the resource ID (string) and a Resource object containing the scene's last known state.
140 private final Map<String, Resource> sceneContributorsCache = new ConcurrentHashMap<>();
143 * A map of scene names versus Resource IDs for the scenes that contribute to and command this thing. e.g. a command
144 * for a scene named 'Energize' shall be sent to the respective SCENE resource ID.
146 private final Map<String, String> sceneResourceIds = new ConcurrentHashMap<>();
149 * A list of API v1 thing channel UIDs that are linked to items. It is used in the process of replicating the
150 * Item/Channel links from a legacy v1 thing to this API v2 thing.
152 private final List<ChannelUID> legacyLinkedChannelUIDs = new CopyOnWriteArrayList<>();
154 private final ThingRegistry thingRegistry;
155 private final ItemChannelLinkRegistry itemChannelLinkRegistry;
156 private final Clip2StateDescriptionProvider stateDescriptionProvider;
158 private String resourceId = "?";
159 private Resource thisResource;
160 private Duration dynamicsDuration = Duration.ZERO;
161 private Instant dynamicsExpireTime = Instant.MIN;
163 private boolean disposing;
164 private boolean hasConnectivityIssue;
165 private boolean updateSceneContributorsDone;
166 private boolean updateLightPropertiesDone;
167 private boolean updatePropertiesDone;
168 private boolean updateDependenciesDone;
169 private boolean applyOffTransitionWorkaround;
171 private @Nullable Future<?> alertResetTask;
172 private @Nullable Future<?> dynamicsResetTask;
173 private @Nullable Future<?> updateDependenciesTask;
174 private @Nullable Future<?> updateServiceContributorsTask;
176 public Clip2ThingHandler(Thing thing, Clip2StateDescriptionProvider stateDescriptionProvider,
177 ThingRegistry thingRegistry, ItemChannelLinkRegistry itemChannelLinkRegistry) {
180 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
181 if (THING_TYPE_DEVICE.equals(thingTypeUID)) {
182 thisResource = new Resource(ResourceType.DEVICE);
183 } else if (THING_TYPE_ROOM.equals(thingTypeUID)) {
184 thisResource = new Resource(ResourceType.ROOM);
185 } else if (THING_TYPE_ZONE.equals(thingTypeUID)) {
186 thisResource = new Resource(ResourceType.ZONE);
188 throw new IllegalArgumentException("Wrong thing type " + thingTypeUID.getAsString());
191 this.thingRegistry = thingRegistry;
192 this.itemChannelLinkRegistry = itemChannelLinkRegistry;
193 this.stateDescriptionProvider = stateDescriptionProvider;
197 * Add a channel ID to the supportedChannelIdSet set. If the channel supports dynamics (timed transitions) then add
198 * the respective channel as well.
200 * @param channelId the channel ID to add.
202 private void addSupportedChannel(String channelId) {
203 if (!disposing && !updateDependenciesDone) {
204 synchronized (supportedChannelIdSet) {
205 logger.debug("{} -> addSupportedChannel() '{}' added to supported channel set", resourceId, channelId);
206 supportedChannelIdSet.add(channelId);
207 if (DYNAMIC_CHANNELS.contains(channelId)) {
208 clearDynamicsChannel();
215 * Cancel the given task.
217 * @param cancelTask the task to be cancelled (may be null)
218 * @param mayInterrupt allows cancel() to interrupt the thread.
220 private void cancelTask(@Nullable Future<?> cancelTask, boolean mayInterrupt) {
221 if (Objects.nonNull(cancelTask)) {
222 cancelTask.cancel(mayInterrupt);
227 * Clear the dynamics channel parameters.
229 private void clearDynamicsChannel() {
230 dynamicsExpireTime = Instant.MIN;
231 dynamicsDuration = Duration.ZERO;
232 updateState(CHANNEL_2_DYNAMICS, new QuantityType<>(0, MetricPrefix.MILLI(Units.SECOND)), true);
236 public void dispose() {
237 logger.debug("{} -> dispose()", resourceId);
239 cancelTask(alertResetTask, true);
240 cancelTask(dynamicsResetTask, true);
241 cancelTask(updateDependenciesTask, true);
242 cancelTask(updateServiceContributorsTask, true);
243 alertResetTask = null;
244 dynamicsResetTask = null;
245 updateDependenciesTask = null;
246 updateServiceContributorsTask = null;
247 legacyLinkedChannelUIDs.clear();
248 sceneContributorsCache.clear();
249 sceneResourceIds.clear();
250 supportedChannelIdSet.clear();
251 commandResourceIds.clear();
252 serviceContributorsCache.clear();
257 * Get the bridge handler.
259 * @throws AssetNotLoadedException if the handler does not exist.
261 private Clip2BridgeHandler getBridgeHandler() throws AssetNotLoadedException {
262 Bridge bridge = getBridge();
263 if (Objects.nonNull(bridge)) {
264 BridgeHandler handler = bridge.getHandler();
265 if (handler instanceof Clip2BridgeHandler) {
266 return (Clip2BridgeHandler) handler;
269 throw new AssetNotLoadedException("Bridge handler missing");
273 * Do a double lookup to get the cached resource that matches the given ResourceType.
275 * @param resourceType the type to search for.
276 * @return the Resource, or null if not found.
278 private @Nullable Resource getCachedResource(ResourceType resourceType) {
279 String commandResourceId = commandResourceIds.get(resourceType);
280 return Objects.nonNull(commandResourceId) ? serviceContributorsCache.get(commandResourceId) : null;
284 * Return a ResourceReference to this handler's resource.
286 * @return a ResourceReference instance.
288 public ResourceReference getResourceReference() {
289 return new ResourceReference().setId(resourceId).setType(thisResource.getType());
293 * Register the 'DynamicsAction' service.
296 public Collection<Class<? extends ThingHandlerService>> getServices() {
297 return Set.of(DynamicsActions.class);
301 public void handleCommand(ChannelUID channelUID, Command commandParam) {
302 if (RefreshType.REFRESH.equals(commandParam)) {
303 if (thing.getStatus() == ThingStatus.ONLINE) {
304 refreshAllChannels();
309 Channel channel = thing.getChannel(channelUID);
310 if (channel == null) {
311 if (logger.isDebugEnabled()) {
312 logger.debug("{} -> handleCommand() channelUID:{} does not exist", resourceId, channelUID);
315 logger.warn("Command received for channel '{}' which is not in thing '{}'.", channelUID,
321 ResourceType lightResourceType = thisResource.getType() == ResourceType.DEVICE ? ResourceType.LIGHT
322 : ResourceType.GROUPED_LIGHT;
324 Resource putResource = null;
325 String putResourceId = null;
326 Command command = commandParam;
327 String channelId = channelUID.getId();
328 Resource cache = getCachedResource(lightResourceType);
331 case CHANNEL_2_ALERT:
332 putResource = Setters.setAlert(new Resource(lightResourceType), command, cache);
333 cancelTask(alertResetTask, false);
334 alertResetTask = scheduler.schedule(
335 () -> updateState(channelUID, new StringType(ActionType.NO_ACTION.name())), 10,
339 case CHANNEL_2_EFFECT:
340 putResource = Setters.setEffect(new Resource(lightResourceType), command, cache);
341 putResource.setOnOff(OnOffType.ON);
344 case CHANNEL_2_COLOR_TEMP_PERCENT:
345 if (command instanceof IncreaseDecreaseType) {
346 if (Objects.nonNull(cache)) {
347 State current = cache.getColorTemperaturePercentState();
348 if (current instanceof PercentType) {
349 int sign = IncreaseDecreaseType.INCREASE == command ? 1 : -1;
350 int percent = ((PercentType) current).intValue() + (sign * (int) Resource.PERCENT_DELTA);
351 command = new PercentType(Math.min(100, Math.max(0, percent)));
354 } else if (command instanceof OnOffType) {
355 command = OnOffType.OFF == command ? PercentType.ZERO : PercentType.HUNDRED;
357 putResource = Setters.setColorTemperaturePercent(new Resource(lightResourceType), command, cache);
360 case CHANNEL_2_COLOR_TEMP_ABSOLUTE:
361 putResource = Setters.setColorTemperatureAbsolute(new Resource(lightResourceType), command, cache);
364 case CHANNEL_2_COLOR:
365 putResource = new Resource(lightResourceType);
366 if (command instanceof HSBType) {
367 HSBType color = ((HSBType) command);
368 putResource = Setters.setColorXy(putResource, color, cache);
369 command = color.getBrightness();
371 // NB fall through for handling of brightness and switch related commands !!
373 case CHANNEL_2_BRIGHTNESS:
374 putResource = Objects.nonNull(putResource) ? putResource : new Resource(lightResourceType);
375 if (command instanceof IncreaseDecreaseType) {
376 if (Objects.nonNull(cache)) {
377 State current = cache.getBrightnessState();
378 if (current instanceof PercentType) {
379 int sign = IncreaseDecreaseType.INCREASE == command ? 1 : -1;
380 double percent = ((PercentType) current).doubleValue() + (sign * Resource.PERCENT_DELTA);
381 command = new PercentType(new BigDecimal(Math.min(100f, Math.max(0f, percent)),
382 Resource.PERCENT_MATH_CONTEXT));
386 if (command instanceof PercentType) {
387 PercentType brightness = (PercentType) command;
388 putResource = Setters.setDimming(putResource, brightness, cache);
389 Double minDimLevel = Objects.nonNull(cache) ? cache.getMinimumDimmingLevel() : null;
390 minDimLevel = Objects.nonNull(minDimLevel) ? minDimLevel : Dimming.DEFAULT_MINIMUM_DIMMIMG_LEVEL;
391 command = OnOffType.from(brightness.doubleValue() >= minDimLevel);
393 // NB fall through for handling of switch related commands !!
395 case CHANNEL_2_SWITCH:
396 putResource = Objects.nonNull(putResource) ? putResource : new Resource(lightResourceType);
397 putResource.setOnOff(command);
398 applyDeviceSpecificWorkArounds(command, putResource);
401 case CHANNEL_2_COLOR_XY_ONLY:
402 putResource = Setters.setColorXy(new Resource(lightResourceType), command, cache);
405 case CHANNEL_2_DIMMING_ONLY:
406 putResource = Setters.setDimming(new Resource(lightResourceType), command, cache);
409 case CHANNEL_2_ON_OFF_ONLY:
410 putResource = new Resource(lightResourceType).setOnOff(command);
411 applyDeviceSpecificWorkArounds(command, putResource);
414 case CHANNEL_2_TEMPERATURE_ENABLED:
415 putResource = new Resource(ResourceType.TEMPERATURE).setEnabled(command);
418 case CHANNEL_2_MOTION_ENABLED:
419 putResource = new Resource(ResourceType.MOTION).setEnabled(command);
422 case CHANNEL_2_LIGHT_LEVEL_ENABLED:
423 putResource = new Resource(ResourceType.LIGHT_LEVEL).setEnabled(command);
426 case CHANNEL_2_SCENE:
427 if (command instanceof StringType) {
428 putResourceId = sceneResourceIds.get(((StringType) command).toString());
429 if (Objects.nonNull(putResourceId)) {
430 putResource = new Resource(ResourceType.SCENE).setRecallAction(RecallAction.ACTIVE);
435 case CHANNEL_2_DYNAMICS:
436 Duration clearAfter = Duration.ZERO;
437 if (command instanceof QuantityType<?>) {
438 QuantityType<?> durationMs = ((QuantityType<?>) command).toUnit(MetricPrefix.MILLI(Units.SECOND));
439 if (Objects.nonNull(durationMs) && durationMs.longValue() > 0) {
440 Duration duration = Duration.ofMillis(durationMs.longValue());
441 dynamicsDuration = duration;
442 dynamicsExpireTime = Instant.now().plus(DYNAMICS_ACTIVE_WINDOW);
443 clearAfter = DYNAMICS_ACTIVE_WINDOW;
444 logger.debug("{} -> handleCommand() dynamics setting {} valid for {}", resourceId, duration,
448 cancelTask(dynamicsResetTask, false);
449 dynamicsResetTask = scheduler.schedule(() -> clearDynamicsChannel(), clearAfter.toMillis(),
450 TimeUnit.MILLISECONDS);
454 if (logger.isDebugEnabled()) {
455 logger.debug("{} -> handleCommand() channelUID:{} unknown", resourceId, channelUID);
457 logger.warn("Command received for unknown channel '{}'.", channelUID);
462 if (putResource == null) {
463 if (logger.isDebugEnabled()) {
464 logger.debug("{} -> handleCommand() command:{} not supported on channelUID:{}", resourceId, command,
467 logger.warn("Command '{}' is not supported on channel '{}'.", command, channelUID);
472 putResourceId = Objects.nonNull(putResourceId) ? putResourceId : commandResourceIds.get(putResource.getType());
473 if (putResourceId == null) {
474 if (logger.isDebugEnabled()) {
476 "{} -> handleCommand() channelUID:{}, command:{}, putResourceType:{} => missing resource ID",
477 resourceId, channelUID, command, putResource.getType());
479 logger.warn("Command '{}' for channel '{}' cannot be processed by thing '{}'.", command, channelUID,
485 if (DYNAMIC_CHANNELS.contains(channelId)) {
486 if (Instant.now().isBefore(dynamicsExpireTime) && !dynamicsDuration.isZero()
487 && !dynamicsDuration.isNegative()) {
488 if (ResourceType.SCENE == putResource.getType()) {
489 putResource.setRecallDuration(dynamicsDuration);
491 putResource.setDynamicsDuration(dynamicsDuration);
496 putResource.setId(putResourceId);
497 logger.debug("{} -> handleCommand() put resource {}", resourceId, putResource);
500 Resources resources = getBridgeHandler().putResource(putResource);
501 if (resources.hasErrors()) {
502 logger.info("Command '{}' for thing '{}', channel '{}' succeeded with errors: {}", command,
503 thing.getUID(), channelUID, String.join("; ", resources.getErrors()));
505 } catch (ApiException | AssetNotLoadedException e) {
506 if (logger.isDebugEnabled()) {
507 logger.debug("{} -> handleCommand() error {}", resourceId, e.getMessage(), e);
509 logger.warn("Command '{}' for thing '{}', channel '{}' failed with error '{}'.", command,
510 thing.getUID(), channelUID, e.getMessage());
512 } catch (InterruptedException e) {
516 private void refreshAllChannels() {
517 if (!updateDependenciesDone) {
520 cancelTask(updateServiceContributorsTask, false);
521 updateServiceContributorsTask = scheduler.schedule(() -> {
523 updateServiceContributors();
524 } catch (ApiException | AssetNotLoadedException e) {
525 logger.debug("{} -> handleCommand() error {}", resourceId, e.getMessage(), e);
526 } catch (InterruptedException e) {
528 }, 3, TimeUnit.SECONDS);
532 * Apply device specific work-arounds needed for given command.
534 * @param command the handled command.
535 * @param putResource the resource that will be adjusted if needed.
537 private void applyDeviceSpecificWorkArounds(Command command, Resource putResource) {
538 if (command == OnOffType.OFF && applyOffTransitionWorkaround) {
539 putResource.setDynamicsDuration(dynamicsDuration);
544 * Handle a 'dynamics' command for the given channel ID for the given dynamics duration.
546 * @param channelId the ID of the target channel.
547 * @param command the new target state.
548 * @param duration the transition duration.
550 public synchronized void handleDynamicsCommand(String channelId, Command command, QuantityType<?> duration) {
551 if (DYNAMIC_CHANNELS.contains(channelId)) {
552 Channel dynamicsChannel = thing.getChannel(CHANNEL_2_DYNAMICS);
553 Channel targetChannel = thing.getChannel(channelId);
554 if (Objects.nonNull(dynamicsChannel) && Objects.nonNull(targetChannel)) {
555 logger.debug("{} - handleDynamicsCommand() channelId:{}, command:{}, duration:{}", resourceId,
556 channelId, command, duration);
557 handleCommand(dynamicsChannel.getUID(), duration);
558 handleCommand(targetChannel.getUID(), command);
562 logger.warn("Dynamics command '{}' for thing '{}', channel '{}' and duration'{}' failed.", command,
563 thing.getUID(), channelId, duration);
567 public void initialize() {
568 Clip2ThingConfig config = getConfigAs(Clip2ThingConfig.class);
570 String resourceId = config.resourceId;
571 if (resourceId.isBlank()) {
572 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
573 "@text/offline.api2.conf-error.resource-id-bad");
576 thisResource.setId(resourceId);
577 this.resourceId = resourceId;
578 logger.debug("{} -> initialize()", resourceId);
580 updateThingFromLegacy();
581 updateStatus(ThingStatus.UNKNOWN);
583 dynamicsDuration = Duration.ZERO;
584 dynamicsExpireTime = Instant.MIN;
587 hasConnectivityIssue = false;
588 updatePropertiesDone = false;
589 updateDependenciesDone = false;
590 updateLightPropertiesDone = false;
591 updateSceneContributorsDone = false;
593 Bridge bridge = getBridge();
594 if (Objects.nonNull(bridge)) {
595 BridgeHandler bridgeHandler = bridge.getHandler();
596 if (bridgeHandler instanceof Clip2BridgeHandler) {
597 ((Clip2BridgeHandler) bridgeHandler).childInitialized();
603 * Update the channel state depending on a new resource sent from the bridge.
605 * @param resource a Resource object containing the new state.
607 public void onResource(Resource resource) {
609 boolean resourceConsumed = false;
610 String incomingResourceId = resource.getId();
611 if (resourceId.equals(incomingResourceId)) {
612 if (resource.hasFullState()) {
613 thisResource = resource;
614 if (!updatePropertiesDone) {
615 updateProperties(resource);
616 resourceConsumed = updatePropertiesDone;
619 if (!updateDependenciesDone) {
620 resourceConsumed = true;
621 cancelTask(updateDependenciesTask, false);
622 updateDependenciesTask = scheduler.submit(() -> updateDependencies());
624 } else if (ResourceType.SCENE == resource.getType()) {
625 Resource cachedScene = sceneContributorsCache.get(incomingResourceId);
626 if (Objects.nonNull(cachedScene)) {
627 Setters.setResource(resource, cachedScene);
628 resourceConsumed = updateChannels(resource);
629 sceneContributorsCache.put(incomingResourceId, resource);
632 Resource cachedService = serviceContributorsCache.get(incomingResourceId);
633 if (Objects.nonNull(cachedService)) {
634 Setters.setResource(resource, cachedService);
635 resourceConsumed = updateChannels(resource);
636 serviceContributorsCache.put(incomingResourceId, resource);
637 if (ResourceType.LIGHT == resource.getType() && !updateLightPropertiesDone) {
638 updateLightProperties(resource);
642 if (resourceConsumed) {
643 logger.debug("{} -> onResource() consumed resource {}", resourceId, resource);
649 * Update the thing internal state depending on a full list of resources sent from the bridge. If the resourceType
650 * is SCENE then call updateScenes(), otherwise if the resource refers to this thing, consume it via onResource() as
651 * any other resource, or else if the resourceType nevertheless matches the thing type, set the thing state offline.
653 * @param resourceType the type of the resources in the list.
654 * @param fullResources the full list of resources of the given type.
656 public void onResourcesList(ResourceType resourceType, List<Resource> fullResources) {
657 if (resourceType == ResourceType.SCENE) {
658 updateSceneContributors(fullResources);
660 fullResources.stream().filter(r -> resourceId.equals(r.getId())).findAny()
661 .ifPresentOrElse(r -> onResource(r), () -> {
662 if (resourceType == thisResource.getType()) {
663 logger.debug("{} -> onResourcesList() configuration error: unknown resourceId", resourceId);
664 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
665 "@text/offline.api2.conf-error.resource-id-bad");
672 * Process the incoming Resource to initialize the alert channel.
674 * @param resource a Resource possibly with an Alerts element.
676 private void updateAlertChannel(Resource resource) {
677 Alerts alerts = resource.getAlerts();
678 if (Objects.nonNull(alerts)) {
679 List<StateOption> stateOptions = alerts.getActionValues().stream().map(action -> action.name())
680 .map(actionId -> new StateOption(actionId, actionId)).collect(Collectors.toList());
681 if (!stateOptions.isEmpty()) {
682 stateDescriptionProvider.setStateOptions(new ChannelUID(thing.getUID(), CHANNEL_2_ALERT), stateOptions);
683 logger.debug("{} -> updateAlerts() found {} associated alerts", resourceId, stateOptions.size());
689 * If this v2 thing has a matching v1 legacy thing in the system, then for each channel in the v1 thing that
690 * corresponds to an equivalent channel in this v2 thing, and for all items that are linked to the v1 channel,
691 * create a new channel/item link between that item and the respective v2 channel in this thing.
693 private void updateChannelItemLinksFromLegacy() {
695 legacyLinkedChannelUIDs.forEach(legacyLinkedChannelUID -> {
696 String targetChannelId = REPLICATE_CHANNEL_ID_MAP.get(legacyLinkedChannelUID.getId());
697 if (Objects.nonNull(targetChannelId)) {
698 Channel targetChannel = thing.getChannel(targetChannelId);
699 if (Objects.nonNull(targetChannel)) {
700 ChannelUID uid = targetChannel.getUID();
701 itemChannelLinkRegistry.getLinkedItems(legacyLinkedChannelUID).forEach(linkedItem -> {
702 String item = linkedItem.getName();
703 if (!itemChannelLinkRegistry.isLinked(item, uid)) {
704 if (logger.isDebugEnabled()) {
706 "{} -> updateChannelItemLinksFromLegacy() item:{} linked to channel:{}",
707 resourceId, item, uid);
709 logger.info("Item '{}' linked to thing '{}' channel '{}'", item, thing.getUID(),
712 itemChannelLinkRegistry.add(new ItemChannelLink(item, uid));
718 legacyLinkedChannelUIDs.clear();
723 * Set the active list of channels by removing any that had initially been created by the thing XML declaration, but
724 * which in fact did not have data returned from the bridge i.e. channels which are not in the supportedChannelIdSet
726 * Also warn if there are channels in the supportedChannelIdSet set which are not in the thing.
728 * Adjusts the channel list so that only the highest level channel is available in the normal channel list. If a
729 * light supports the color channel, then it's brightness and switch can be commanded via the 'B' part of the HSB
730 * channel value. And if it supports the brightness channel the switch can be controlled via the brightness. So we
731 * can remove these lower level channels from the normal channel list.
733 * For more advanced applications, it is necessary to orthogonally command the color xy parameter, dimming
734 * parameter, and/or on/off parameter independently. So we add corresponding advanced level 'CHANNEL_2_BLAH_ONLY'
735 * channels for that purpose. Since they are advanced level, normal users should normally not be confused by them,
736 * yet advanced users can use them nevertheless.
738 private void updateChannelList() {
740 synchronized (supportedChannelIdSet) {
741 logger.debug("{} -> updateChannelList()", resourceId);
743 if (supportedChannelIdSet.contains(CHANNEL_2_COLOR)) {
744 supportedChannelIdSet.add(CHANNEL_2_COLOR_XY_ONLY);
746 supportedChannelIdSet.remove(CHANNEL_2_BRIGHTNESS);
747 supportedChannelIdSet.add(CHANNEL_2_DIMMING_ONLY);
749 supportedChannelIdSet.remove(CHANNEL_2_SWITCH);
750 supportedChannelIdSet.add(CHANNEL_2_ON_OFF_ONLY);
752 if (supportedChannelIdSet.contains(CHANNEL_2_BRIGHTNESS)) {
753 supportedChannelIdSet.add(CHANNEL_2_DIMMING_ONLY);
755 supportedChannelIdSet.remove(CHANNEL_2_SWITCH);
756 supportedChannelIdSet.add(CHANNEL_2_ON_OFF_ONLY);
758 if (supportedChannelIdSet.contains(CHANNEL_2_SWITCH)) {
759 supportedChannelIdSet.add(CHANNEL_2_ON_OFF_ONLY);
763 * This binding creates its dynamic list of channels by a 'subtractive' method i.e. the full set of
764 * channels is initially created from the thing type xml, and then for any channels where UndfType.NULL
765 * data is returned, the respective channel is removed from the full list. However in seldom cases
766 * UndfType.NULL may wrongly be returned, so we should log a warning here just in case.
768 if (logger.isDebugEnabled()) {
769 supportedChannelIdSet.stream().filter(channelId -> Objects.isNull(thing.getChannel(channelId)))
770 .forEach(channelId -> logger.debug(
771 "{} -> updateChannelList() required channel '{}' missing", resourceId, channelId));
773 supportedChannelIdSet.stream().filter(channelId -> Objects.isNull(thing.getChannel(channelId)))
774 .forEach(channelId -> logger.warn(
775 "Thing '{}' is missing required channel '{}'. Please recreate the thing!",
776 thing.getUID(), channelId));
779 // get list of unused channels
780 List<Channel> unusedChannels = thing.getChannels().stream()
781 .filter(channel -> !supportedChannelIdSet.contains(channel.getUID().getId()))
782 .collect(Collectors.toList());
784 // remove any unused channels
785 if (!unusedChannels.isEmpty()) {
786 if (logger.isDebugEnabled()) {
787 unusedChannels.stream().map(channel -> channel.getUID().getId())
788 .forEach(channelId -> logger.debug(
789 "{} -> updateChannelList() removing unused channel '{}'", resourceId,
792 updateThing(editThing().withoutChannels(unusedChannels).build());
799 * Update the state of the existing channels.
801 * @param resource the Resource containing the new channel state.
802 * @return true if the channel was found and updated.
804 private boolean updateChannels(Resource resource) {
805 logger.debug("{} -> updateChannels() from resource {}", resourceId, resource);
806 boolean fullUpdate = resource.hasFullState();
807 switch (resource.getType()) {
810 addSupportedChannel(CHANNEL_2_BUTTON_LAST_EVENT);
811 controlIds.put(resource.getId(), resource.getControlId());
813 State buttonState = resource.getButtonEventState(controlIds);
814 updateState(CHANNEL_2_BUTTON_LAST_EVENT, buttonState, fullUpdate);
819 updateState(CHANNEL_2_BATTERY_LEVEL, resource.getBatteryLevelState(), fullUpdate);
820 updateState(CHANNEL_2_BATTERY_LOW, resource.getBatteryLowState(), fullUpdate);
825 updateEffectChannel(resource);
827 updateState(CHANNEL_2_COLOR_TEMP_PERCENT, resource.getColorTemperaturePercentState(), fullUpdate);
828 updateState(CHANNEL_2_COLOR_TEMP_ABSOLUTE, resource.getColorTemperatureAbsoluteState(), fullUpdate);
829 updateState(CHANNEL_2_COLOR, resource.getColorState(), fullUpdate);
830 updateState(CHANNEL_2_COLOR_XY_ONLY, resource.getColorXyState(), fullUpdate);
831 updateState(CHANNEL_2_EFFECT, resource.getEffectState(), fullUpdate);
832 // fall through for dimming and on/off related channels
836 updateAlertChannel(resource);
838 updateState(CHANNEL_2_BRIGHTNESS, resource.getBrightnessState(), fullUpdate);
839 updateState(CHANNEL_2_DIMMING_ONLY, resource.getDimmingState(), fullUpdate);
840 updateState(CHANNEL_2_SWITCH, resource.getOnOffState(), fullUpdate);
841 updateState(CHANNEL_2_ON_OFF_ONLY, resource.getOnOffState(), fullUpdate);
842 updateState(CHANNEL_2_ALERT, resource.getAlertState(), fullUpdate);
846 updateState(CHANNEL_2_LIGHT_LEVEL, resource.getLightLevelState(), fullUpdate);
847 updateState(CHANNEL_2_LIGHT_LEVEL_ENABLED, resource.getEnabledState(), fullUpdate);
851 updateState(CHANNEL_2_MOTION, resource.getMotionState(), fullUpdate);
852 updateState(CHANNEL_2_MOTION_ENABLED, resource.getEnabledState(), fullUpdate);
855 case RELATIVE_ROTARY:
857 addSupportedChannel(CHANNEL_2_ROTARY_STEPS);
859 updateState(CHANNEL_2_ROTARY_STEPS, resource.getRotaryStepsState(), fullUpdate);
864 updateState(CHANNEL_2_TEMPERATURE, resource.getTemperatureState(), fullUpdate);
865 updateState(CHANNEL_2_TEMPERATURE_ENABLED, resource.getEnabledState(), fullUpdate);
868 case ZIGBEE_CONNECTIVITY:
869 updateConnectivityState(resource);
873 updateState(CHANNEL_2_SCENE, resource.getSceneState(), fullUpdate);
879 if (thisResource.getType() == ResourceType.DEVICE) {
880 updateState(CHANNEL_2_LAST_UPDATED, new DateTimeType(), fullUpdate);
886 * Check the Zigbee connectivity and set the thing online status accordingly. If the thing is offline then set all
887 * its channel states to undefined, otherwise execute a refresh command to update channels to the latest current
890 * @param resource a Resource that potentially contains the Zigbee connectivity state.
892 private void updateConnectivityState(Resource resource) {
893 ZigbeeStatus zigbeeStatus = resource.getZigbeeStatus();
894 if (Objects.nonNull(zigbeeStatus)) {
895 logger.debug("{} -> updateConnectivityState() thingStatus:{}, zigbeeStatus:{}", resourceId,
896 thing.getStatus(), zigbeeStatus);
897 hasConnectivityIssue = zigbeeStatus != ZigbeeStatus.CONNECTED;
898 if (hasConnectivityIssue) {
899 if (thing.getStatusInfo().getStatusDetail() != ThingStatusDetail.COMMUNICATION_ERROR) {
900 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE,
901 "@text/offline.api2.comm-error.zigbee-connectivity-issue");
902 supportedChannelIdSet.forEach(channelId -> updateState(channelId, UnDefType.UNDEF));
904 } else if (thing.getStatus() != ThingStatus.ONLINE) {
905 updateStatus(ThingStatus.ONLINE);
906 refreshAllChannels();
912 * Get all resources needed for building the thing state. Build the forward / reverse contributor lookup maps. Set
913 * up the final list of channels in the thing.
915 private synchronized void updateDependencies() {
916 if (!disposing && !updateDependenciesDone) {
917 logger.debug("{} -> updateDependencies()", resourceId);
919 if (!updatePropertiesDone) {
920 logger.debug("{} -> updateDependencies() properties not initialized", resourceId);
923 if (!updateSceneContributorsDone && !updateSceneContributors()) {
924 logger.debug("{} -> updateDependencies() scenes not initialized", resourceId);
928 updateServiceContributors();
930 updateChannelItemLinksFromLegacy();
931 if (!hasConnectivityIssue) {
932 updateStatus(ThingStatus.ONLINE);
934 updateDependenciesDone = true;
935 } catch (ApiException e) {
936 logger.debug("{} -> updateDependencies() {}", resourceId, e.getMessage(), e);
937 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
938 } catch (AssetNotLoadedException e) {
939 logger.debug("{} -> updateDependencies() {}", resourceId, e.getMessage(), e);
940 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
941 "@text/offline.api2.conf-error.assets-not-loaded");
942 } catch (InterruptedException e) {
948 * Process the incoming Resource to initialize the effects channel.
950 * @param resource a Resource possibly with an Effects element.
952 public void updateEffectChannel(Resource resource) {
953 Effects effects = resource.getEffects();
954 if (Objects.nonNull(effects)) {
955 List<StateOption> stateOptions = effects.getStatusValues().stream()
956 .map(effect -> EffectType.of(effect).name()).map(effectId -> new StateOption(effectId, effectId))
957 .collect(Collectors.toList());
958 if (!stateOptions.isEmpty()) {
959 stateDescriptionProvider.setStateOptions(new ChannelUID(thing.getUID(), CHANNEL_2_EFFECT),
961 logger.debug("{} -> updateEffects() found {} effects", resourceId, stateOptions.size());
967 * Update the light properties.
969 * @param resource a Resource object containing the property data.
971 private synchronized void updateLightProperties(Resource resource) {
972 if (!disposing && !updateLightPropertiesDone) {
973 logger.debug("{} -> updateLightProperties()", resourceId);
975 Dimming dimming = resource.getDimming();
976 thing.setProperty(PROPERTY_DIMMING_RANGE, Objects.nonNull(dimming) ? dimming.toPropertyValue() : null);
978 MirekSchema mirekSchema = resource.getMirekSchema();
979 thing.setProperty(PROPERTY_COLOR_TEMP_RANGE,
980 Objects.nonNull(mirekSchema) ? mirekSchema.toPropertyValue() : null);
982 ColorXy colorXy = resource.getColorXy();
983 Gamut2 gamut = Objects.nonNull(colorXy) ? colorXy.getGamut2() : null;
984 thing.setProperty(PROPERTY_COLOR_GAMUT, Objects.nonNull(gamut) ? gamut.toPropertyValue() : null);
986 updateLightPropertiesDone = true;
991 * Initialize the lookup maps of resources that contribute to the thing state.
993 private void updateLookups() {
995 logger.debug("{} -> updateLookups()", resourceId);
996 // get supported services
997 List<ResourceReference> services = thisResource.getServiceReferences();
999 // add supported services to contributorsCache
1000 serviceContributorsCache.clear();
1001 serviceContributorsCache.putAll(services.stream()
1002 .collect(Collectors.toMap(ResourceReference::getId, r -> new Resource(r.getType()))));
1004 // add supported services to commandResourceIds
1005 commandResourceIds.clear();
1006 commandResourceIds.putAll(services.stream() // use a 'mergeFunction' to prevent duplicates
1007 .collect(Collectors.toMap(ResourceReference::getType, ResourceReference::getId, (r1, r2) -> r1)));
1012 * Update the primary device properties.
1014 * @param resource a Resource object containing the property data.
1016 private synchronized void updateProperties(Resource resource) {
1017 if (!disposing && !updatePropertiesDone) {
1018 logger.debug("{} -> updateProperties()", resourceId);
1019 Map<String, String> properties = new HashMap<>(thing.getProperties());
1022 properties.put(PROPERTY_RESOURCE_TYPE, thisResource.getType().toString());
1023 properties.put(PROPERTY_RESOURCE_NAME, thisResource.getName());
1025 // owner information
1026 ResourceReference owner = thisResource.getOwner();
1027 if (Objects.nonNull(owner)) {
1028 String ownerId = owner.getId();
1029 if (Objects.nonNull(ownerId)) {
1030 properties.put(PROPERTY_OWNER, ownerId);
1032 ResourceType ownerType = owner.getType();
1033 properties.put(PROPERTY_OWNER_TYPE, ownerType.toString());
1037 MetaData metaData = thisResource.getMetaData();
1038 if (Objects.nonNull(metaData)) {
1039 properties.put(PROPERTY_RESOURCE_ARCHETYPE, metaData.getArchetype().toString());
1043 ProductData productData = thisResource.getProductData();
1044 if (Objects.nonNull(productData)) {
1045 String modelId = productData.getModelId();
1047 // standard properties
1048 properties.put(PROPERTY_RESOURCE_ID, resourceId);
1049 properties.put(Thing.PROPERTY_MODEL_ID, modelId);
1050 properties.put(Thing.PROPERTY_VENDOR, productData.getManufacturerName());
1051 properties.put(Thing.PROPERTY_FIRMWARE_VERSION, productData.getSoftwareVersion());
1052 String hardwarePlatformType = productData.getHardwarePlatformType();
1053 if (Objects.nonNull(hardwarePlatformType)) {
1054 properties.put(Thing.PROPERTY_HARDWARE_VERSION, hardwarePlatformType);
1057 // hue specific properties
1058 properties.put(PROPERTY_PRODUCT_NAME, productData.getProductName());
1059 properties.put(PROPERTY_PRODUCT_ARCHETYPE, productData.getProductArchetype().toString());
1060 properties.put(PROPERTY_PRODUCT_CERTIFIED, productData.getCertified().toString());
1062 // Check device for needed work-arounds.
1063 if (LK_WISER_DIMMER_MODEL_ID.equals(modelId)) {
1064 // Apply transition time as a workaround for LK Wiser Dimmer firmware bug.
1065 // Additional details here: https://techblog.vindvejr.dk/?p=455
1066 applyOffTransitionWorkaround = true;
1067 logger.debug("{} -> enabling work-around for turning off LK Wiser Dimmer", resourceId);
1071 thing.setProperties(properties);
1072 updatePropertiesDone = true;
1077 * Execute an HTTP GET command to fetch the resources data for the referenced resource.
1079 * @param reference to the required resource.
1080 * @throws ApiException if a communication error occurred.
1081 * @throws AssetNotLoadedException if one of the assets is not loaded.
1082 * @throws InterruptedException
1084 private void updateResource(ResourceReference reference)
1085 throws ApiException, AssetNotLoadedException, InterruptedException {
1087 logger.debug("{} -> updateResource() from resource {}", resourceId, reference);
1088 getBridgeHandler().getResources(reference).getResources().stream()
1089 .forEach(resource -> onResource(resource));
1094 * Fetch the full list of scenes from the bridge, and call {@code updateSceneContributors(List<Resource> allScenes)}
1096 * @throws ApiException if a communication error occurred.
1097 * @throws AssetNotLoadedException if one of the assets is not loaded.
1098 * @throws InterruptedException
1100 public boolean updateSceneContributors() throws ApiException, AssetNotLoadedException, InterruptedException {
1101 if (!disposing && !updateSceneContributorsDone) {
1102 ResourceReference scenesReference = new ResourceReference().setType(ResourceType.SCENE);
1103 updateSceneContributors(getBridgeHandler().getResources(scenesReference).getResources());
1105 return updateSceneContributorsDone;
1109 * Process the incoming list of scene resources to find those scenes which contribute to this thing. And if there
1110 * are any, include a scene channel in the supported channel list, and populate its respective state options.
1112 * @param allScenes the full list of scene resources.
1114 public synchronized boolean updateSceneContributors(List<Resource> allScenes) {
1115 if (!disposing && !updateSceneContributorsDone) {
1116 sceneContributorsCache.clear();
1117 sceneResourceIds.clear();
1119 ResourceReference thisReference = getResourceReference();
1120 List<Resource> scenes = allScenes.stream().filter(s -> thisReference.equals(s.getGroup()))
1121 .collect(Collectors.toList());
1123 if (!scenes.isEmpty()) {
1124 sceneContributorsCache.putAll(scenes.stream().collect(Collectors.toMap(s -> s.getId(), s -> s)));
1125 sceneResourceIds.putAll(scenes.stream().collect(Collectors.toMap(s -> s.getName(), s -> s.getId())));
1127 State state = scenes.stream().filter(s -> s.getSceneActive().orElse(false)).map(s -> s.getSceneState())
1128 .findAny().orElse(UnDefType.UNDEF);
1129 updateState(CHANNEL_2_SCENE, state, true);
1131 stateDescriptionProvider.setStateOptions(new ChannelUID(thing.getUID(), CHANNEL_2_SCENE), scenes
1132 .stream().map(s -> s.getName()).map(n -> new StateOption(n, n)).collect(Collectors.toList()));
1134 logger.debug("{} -> updateSceneContributors() found {} scenes", resourceId, scenes.size());
1136 updateSceneContributorsDone = true;
1138 return updateSceneContributorsDone;
1142 * Execute a series of HTTP GET commands to fetch the resource data for all service resources that contribute to the
1145 * @throws ApiException if a communication error occurred.
1146 * @throws AssetNotLoadedException if one of the assets is not loaded.
1147 * @throws InterruptedException
1149 private void updateServiceContributors() throws ApiException, AssetNotLoadedException, InterruptedException {
1151 logger.debug("{} -> updateServiceContributors() called for {} contributors", resourceId,
1152 serviceContributorsCache.size());
1153 ResourceReference reference = new ResourceReference();
1154 for (var entry : serviceContributorsCache.entrySet()) {
1155 updateResource(reference.setId(entry.getKey()).setType(entry.getValue().getType()));
1161 * Update the channel state, and if appropriate add the channel ID to the set of supportedChannelIds. Calls either
1162 * OH core updateState() or triggerChannel() methods depending on the channel kind.
1164 * Note: the particular 'UnDefType.UNDEF' value of the state argument is used to specially indicate the undefined
1165 * state, but yet that its channel shall nevertheless continue to be present in the thing.
1167 * @param channelID the id of the channel.
1168 * @param state the new state of the channel.
1169 * @param fullUpdate if true always update the channel, otherwise only update if state is not 'UNDEF'.
1171 private void updateState(String channelID, State state, boolean fullUpdate) {
1172 boolean isDefined = state != UnDefType.NULL;
1173 Channel channel = thing.getChannel(channelID);
1175 if ((fullUpdate || isDefined) && Objects.nonNull(channel)) {
1176 logger.debug("{} -> updateState() '{}' update with '{}' (fullUpdate:{}, isDefined:{})", resourceId,
1177 channelID, state, fullUpdate, isDefined);
1179 switch (channel.getKind()) {
1181 updateState(channelID, state);
1185 if (state instanceof DecimalType) {
1186 triggerChannel(channelID, String.valueOf(((DecimalType) state).intValue()));
1190 if (fullUpdate && isDefined) {
1191 addSupportedChannel(channelID);
1196 * Check if a PROPERTY_LEGACY_THING_UID value was set by the discovery process, and if so, clone the legacy thing's
1197 * settings into this thing.
1199 private void updateThingFromLegacy() {
1200 if (isInitialized()) {
1201 logger.warn("Cannot update thing '{}' from legacy thing since handler already initialized.",
1205 Map<String, String> properties = thing.getProperties();
1206 String legacyThingUID = properties.get(PROPERTY_LEGACY_THING_UID);
1207 if (Objects.nonNull(legacyThingUID)) {
1208 Thing legacyThing = thingRegistry.get(new ThingUID(legacyThingUID));
1209 if (Objects.nonNull(legacyThing)) {
1210 ThingBuilder editBuilder = editThing();
1212 String location = legacyThing.getLocation();
1213 if (Objects.nonNull(location) && !location.isBlank()) {
1214 editBuilder = editBuilder.withLocation(location);
1217 // save list of legacyLinkedChannelUIDs for use after channel list is initialised
1218 legacyLinkedChannelUIDs.clear();
1219 legacyLinkedChannelUIDs.addAll(legacyThing.getChannels().stream().map(Channel::getUID)
1220 .filter(uid -> REPLICATE_CHANNEL_ID_MAP.containsKey(uid.getId())
1221 && itemChannelLinkRegistry.isLinked(uid))
1222 .collect(Collectors.toList()));
1224 Map<String, String> newProperties = new HashMap<>(properties);
1225 newProperties.remove(PROPERTY_LEGACY_THING_UID);
1227 updateThing(editBuilder.withProperties(newProperties).build());