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.gardena.internal.util;
15 import static org.openhab.binding.gardena.internal.GardenaBindingConstants.BINDING_ID;
17 import java.util.ArrayList;
18 import java.util.List;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.gardena.internal.handler.GardenaDeviceConfig;
22 import org.openhab.binding.gardena.internal.model.dto.Device;
23 import org.openhab.core.thing.Bridge;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.thing.ThingTypeUID;
26 import org.openhab.core.thing.ThingUID;
29 * Utility class for converting between a Thing and a Gardena device.
31 * @author Gerhard Riegler - Initial contribution
34 public class UidUtils {
37 * Generates the ThingUID for the given device in the given account.
39 public static ThingUID generateThingUID(Device device, Bridge account) {
40 ThingTypeUID thingTypeUID = new ThingTypeUID(BINDING_ID, device.deviceType);
41 return new ThingUID(thingTypeUID, account.getUID(), device.id);
45 * Returns all ThingUIDs for a given device.
47 public static List<ThingUID> getThingUIDs(Device device, Bridge account) {
48 List<ThingUID> thingUIDs = new ArrayList<>();
49 for (Thing thing : account.getThings()) {
50 String deviceId = thing.getConfiguration().as(GardenaDeviceConfig.class).deviceId;
51 if (deviceId == null) {
52 deviceId = thing.getUID().getId();
54 if (deviceId.equals(device.id)) {
55 thingUIDs.add(thing.getUID());
62 * Returns the device id of the Gardena device from the given thing.
64 public static String getGardenaDeviceId(Thing thing) {
65 String deviceId = thing.getConfiguration().as(GardenaDeviceConfig.class).deviceId;
66 if (deviceId != null) {
70 return thing.getUID().getId();