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.surepetcare.internal.dto;
15 import java.time.ZonedDateTime;
16 import java.util.Arrays;
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.openhab.core.thing.Thing;
23 * The {@link SurePetcareDevice} is the Java class used
24 * as a DTO to represent a Sure Petcare device, such as a hub, a cat flap, a feeder etc.
26 * @author Rene Scherer - Initial contribution
28 public class SurePetcareDevice extends SurePetcareBaseObject {
30 public enum ProductType {
32 UNKNOWN(0, "Unknown"),
34 PET_FLAP(3, "Pet Flap"),
35 PET_FEEDER(4, "Pet Feeder"),
36 CAT_FLAP(6, "Cat Flap");
38 public final Integer id;
39 public final String name;
41 private ProductType(int id, String name) {
46 public static @NonNull ProductType findByTypeId(final int id) {
47 return Arrays.stream(values()).filter(value -> value.id.equals(id)).findFirst().orElse(UNKNOWN);
51 public Long parentDeviceId;
52 public Integer productId;
53 public Long householdId;
55 public String serialNumber;
56 public String macAddress;
58 public ZonedDateTime pairingAt;
59 public SurePetcareDeviceControl control = new SurePetcareDeviceControl();
60 public SurePetcareDevice parent;
61 public SurePetcareDeviceStatus status = new SurePetcareDeviceStatus();
64 public @NonNull Map<@NonNull String, @NonNull String> getThingProperties() {
66 Map<@NonNull String, @NonNull String> properties = super.getThingProperties();
67 properties.put("householdId", householdId.toString());
68 properties.put("productType", productId.toString());
69 properties.put("productName", ProductType.findByTypeId(productId).name);
70 properties.put(Thing.PROPERTY_MAC_ADDRESS, macAddress);
71 properties.put(Thing.PROPERTY_SERIAL_NUMBER, serialNumber);
72 if (status.version.device != null) {
73 properties.put(Thing.PROPERTY_HARDWARE_VERSION, status.version.device.hardware);
74 properties.put(Thing.PROPERTY_FIRMWARE_VERSION, status.version.device.firmware);
76 if (status.version.lcd != null) {
77 properties.put(Thing.PROPERTY_HARDWARE_VERSION, status.version.lcd.hardware);
78 properties.put(Thing.PROPERTY_FIRMWARE_VERSION, status.version.lcd.firmware);
80 if (status.version.rf != null) {
81 properties.put("rfHardwareVersion", status.version.rf.hardware);
82 properties.put("rfFirmwareVersion", status.version.rf.firmware);
84 if (pairingAt != null) {
85 properties.put("pairingAt", pairingAt.toString());
91 public String toString() {
92 return "Device [id=" + id + ", name=" + name + ", product=" + ProductType.findByTypeId(productId).name + "]";
95 public SurePetcareDevice assign(SurePetcareDevice newdev) {
97 this.parentDeviceId = newdev.parentDeviceId;
98 this.productId = newdev.productId;
99 this.householdId = newdev.householdId;
100 this.name = newdev.name;
101 this.serialNumber = newdev.serialNumber;
102 this.macAddress = newdev.macAddress;
103 this.index = newdev.index;
104 this.pairingAt = newdev.pairingAt;
105 this.control = newdev.control;
106 this.parent = newdev.parent;
107 this.status = newdev.status;