]> git.basschouten.com Git - openhab-addons.git/blob
ccafd3d78e65ad23851ea49ccc3017e34ef8acc6
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.surepetcare.internal.dto;
14
15 import java.time.ZonedDateTime;
16 import java.util.Arrays;
17 import java.util.Map;
18
19 import org.eclipse.jdt.annotation.NonNull;
20 import org.openhab.core.thing.Thing;
21
22 /**
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.
25  *
26  * @author Rene Scherer - Initial contribution
27  */
28 public class SurePetcareDevice extends SurePetcareBaseObject {
29
30     public enum ProductType {
31
32         UNKNOWN(0, "Unknown"),
33         HUB(1, "Hub"),
34         PET_FLAP(3, "Pet Flap"),
35         PET_FEEDER(4, "Pet Feeder"),
36         CAT_FLAP(6, "Cat Flap");
37
38         public final Integer id;
39         public final String name;
40
41         private ProductType(int id, String name) {
42             this.id = id;
43             this.name = name;
44         }
45
46         public static @NonNull ProductType findByTypeId(final int id) {
47             return Arrays.stream(values()).filter(value -> value.id.equals(id)).findFirst().orElse(UNKNOWN);
48         }
49     }
50
51     public Long parentDeviceId;
52     public Integer productId;
53     public Long householdId;
54     public String name;
55     public String serialNumber;
56     public String macAddress;
57     public Integer index;
58     public ZonedDateTime pairingAt;
59     public SurePetcareDeviceControl control = new SurePetcareDeviceControl();
60     public SurePetcareDevice parent;
61     public SurePetcareDeviceStatus status = new SurePetcareDeviceStatus();
62
63     @Override
64     public @NonNull Map<@NonNull String, @NonNull String> getThingProperties() {
65         @NonNull
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);
75         }
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);
79         }
80         if (status.version.rf != null) {
81             properties.put("rfHardwareVersion", status.version.rf.hardware);
82             properties.put("rfFirmwareVersion", status.version.rf.firmware);
83         }
84         if (pairingAt != null) {
85             properties.put("pairingAt", pairingAt.toString());
86         }
87         return properties;
88     }
89
90     @Override
91     public String toString() {
92         return "Device [id=" + id + ", name=" + name + ", product=" + ProductType.findByTypeId(productId).name + "]";
93     }
94
95     public SurePetcareDevice assign(SurePetcareDevice newdev) {
96         super.assign(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;
108         return this;
109     }
110 }