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.dto.clip2;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.hue.internal.dto.clip2.enums.ResourceType;
20 * DTO that contains an API reference element.
22 * The V2 API is set up in such a way that all resources of the same type are grouped together under the
23 * /resource/<resourcetype> endpoint, but all those resources commonly reference each other, which is done in a
24 * standardized way by indicating the resource type (rtype) and resource id (rid).
26 * A typical usage is in a single physical device that hosts multiple services. An existing example is the Philips Hue
27 * Motion sensor which has a motion, light_level, and temperature service, but theoretically any combination can be
28 * supported such as an integrated device with two independently controllable light points and a motion sensor.
30 * This means that the information of the device itself can be found under the /device resource endpoint, but it then
31 * contains a services array which references for example the light and motion resources, for which the details can be
32 * found under the /light and /motion resource endpoints respectively. Other services the device might have, such as a
33 * Zigbee radio (zigbee_connectivy) or battery (device_power) are modeled in the same way.
35 * @author Andrew Fiddian-Green - Initial contribution
38 public class ResourceReference {
39 private @Nullable String rid;
40 private @NonNullByDefault({}) String rtype;
43 public boolean equals(@Nullable Object obj) {
44 String rid = this.rid;
45 return (obj instanceof ResourceReference) && (rid != null) && rid.equals(((ResourceReference) obj).rid);
48 public @Nullable String getId() {
52 public ResourceType getType() {
53 return ResourceType.of(rtype);
56 public ResourceReference setId(String id) {
61 public ResourceReference setType(ResourceType resourceType) {
62 rtype = resourceType.name().toLowerCase();
67 public String toString() {
69 return String.format("id:%s, type:%s", id != null ? id : "*" + " ".repeat(35), getType().name().toLowerCase());