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.io.hueemulation.internal.dto;
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;
21 import java.util.TreeMap;
23 import org.eclipse.jdt.annotation.NonNullByDefault;
25 import com.google.gson.JsonElement;
26 import com.google.gson.JsonSerializationContext;
27 import com.google.gson.JsonSerializer;
30 * Hue API config object
32 * @author David Graeff - Initial contribution
35 public class HueAuthorizedConfig extends HueUnauthorizedConfig {
36 public String uuid = ""; // Example: 5673dfa7-272c-4315-9955-252cdd86131c
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";
43 public String devicename = "openHAB";
45 public String fwversion = "0x262e0500";
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;
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;
59 public String proxyaddress = "none";
60 public int proxyport = 0;
62 public final Map<String, HueUserAuth> whitelist = new TreeMap<>();
64 public void makeV1bridge() {
65 apiversion = "1.16.0";
66 datastoreversion = "60";
68 swversion = "01041302";
69 fwversion = "0x262e0500";
72 public void makeV2bridge() {
73 apiversion = "1.22.0";
74 datastoreversion = "60";
76 swversion = "1901181309";
77 fwversion = "0x262e0500";
81 * Return a json serializer that behaves like the default one, but updates the UTC and localtime fields
82 * before each serialization.
85 public static class Serializer implements JsonSerializer<HueAuthorizedConfig> {
86 static class HueAuthorizedConfigHelper extends HueAuthorizedConfig {
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 return context.serialize(src, HueAuthorizedConfigHelper.class);