]> git.basschouten.com Git - openhab-addons.git/blob
0f615d31f9ed647b01371861511b6565b963b2c2
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.io.hueemulation.internal.dto;
14
15 import java.lang.reflect.Type;
16 import java.time.LocalDateTime;
17 import java.time.ZoneOffset;
18 import java.time.ZonedDateTime;
19 import java.time.format.DateTimeFormatter;
20 import java.util.Map;
21 import java.util.TreeMap;
22
23 import org.eclipse.jdt.annotation.NonNullByDefault;
24
25 import com.google.gson.JsonElement;
26 import com.google.gson.JsonSerializationContext;
27 import com.google.gson.JsonSerializer;
28
29 /**
30  * Hue API config object
31  *
32  * @author David Graeff - Initial contribution
33  */
34 @NonNullByDefault
35 public class HueAuthorizedConfig extends HueUnauthorizedConfig {
36     public String uuid = ""; // Example: 5673dfa7-272c-4315-9955-252cdd86131c
37
38     public String timeformat = "24h";
39     public String timezone = ZonedDateTime.now().getOffset().getId().replace("Z", "+00:00");
40     public String UTC = "2018-11-10T15:24:23";
41     public String localtime = "2018-11-10T16:24:23";
42
43     public String devicename = "openHAB";
44
45     public String fwversion = "0x262e0500";
46
47     public boolean rfconnected = true;
48     public int zigbeechannel = 15;
49     public boolean linkbutton = false;
50     public transient boolean createNewUserOnEveryEndpoint = false;
51     public int panid = 19367;
52
53     public boolean dhcp = true;
54     public String gateway = "192.168.0.1";
55     public String ipaddress = ""; // Example: 192.168.0.46
56     public String netmask = ""; // Example: 255.255.255.0
57     public int networkopenduration = 60;
58
59     public String proxyaddress = "none";
60     public int proxyport = 0;
61
62     public final Map<String, HueUserAuth> whitelist = new TreeMap<>();
63
64     public void makeV1bridge() {
65         apiversion = "1.16.0";
66         datastoreversion = "60";
67         modelid = "BSB001";
68         swversion = "01041302";
69         fwversion = "0x262e0500";
70     }
71
72     public void makeV2bridge() {
73         apiversion = "1.22.0";
74         datastoreversion = "60";
75         modelid = "BSB002";
76         swversion = "1901181309";
77         fwversion = "0x262e0500";
78     }
79
80     /**
81      * Return a json serializer that behaves like the default one, but updates the UTC and localtime fields
82      * before each serialization.
83      */
84     @NonNullByDefault({})
85     public static class Serializer implements JsonSerializer<HueAuthorizedConfig> {
86         static class HueAuthorizedConfigHelper extends HueAuthorizedConfig {
87
88         }
89
90         @Override
91         public JsonElement serialize(HueAuthorizedConfig src, Type typeOfSrc, JsonSerializationContext context) {
92             src.UTC = LocalDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
93             src.localtime = LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
94             JsonElement jsonSubscription = context.serialize(src, HueAuthorizedConfigHelper.class);
95             return jsonSubscription;
96         }
97     }
98 }