]> git.basschouten.com Git - openhab-addons.git/blob
c4f75f67304329d9c1623b9209d6c3bd42d56884
[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.binding.hue.internal.dto.clip2;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.hue.internal.dto.clip2.enums.ButtonEventType;
18
19 import com.google.gson.annotations.SerializedName;
20
21 /**
22  * DTO for CLIP 2 button state.
23  *
24  * @author Andrew Fiddian-Green - Initial contribution
25  */
26 @NonNullByDefault
27 public class Button {
28     private @Nullable @SerializedName("last_event") String lastEvent;
29     private @Nullable @SerializedName("button_report") ButtonReport buttonReport;
30     private @SerializedName("repeat_interval") int repeatInterval;
31
32     /**
33      * The underlying field is deprecated in the CLIP 2 API.
34      * Moved to button_report/event
35      *
36      * @return the last button event as an enum (null if none or invalid).
37      */
38     public @Nullable ButtonEventType getLastEvent() {
39         String lastEvent = this.lastEvent;
40         if (lastEvent == null) {
41             return null;
42         }
43
44         try {
45             return ButtonEventType.valueOf(lastEvent.toUpperCase());
46         } catch (IllegalArgumentException e) {
47             return null;
48         }
49     }
50
51     public @Nullable ButtonReport getButtonReport() {
52         return buttonReport;
53     }
54 }