]> git.basschouten.com Git - openhab-addons.git/blob
9b6de00ecd666d964183d8e77573d26cd5b2540f
[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.api.dto.clip2;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.core.library.types.OnOffType;
18 import org.openhab.core.types.State;
19 import org.openhab.core.types.UnDefType;
20
21 import com.google.gson.annotations.SerializedName;
22
23 /**
24  * DTO for CLIP 2 motion sensor.
25  *
26  * @author Andrew Fiddian-Green - Initial contribution
27  */
28 @NonNullByDefault
29 public class Motion {
30     private boolean motion;
31     private @SerializedName("motion_valid") boolean motionValid;
32     private @Nullable @SerializedName("motion_report") MotionReport motionReport;
33
34     /**
35      * The underlying field is deprecated in the CLIP 2 API.
36      * Moved to motion_report/motion.
37      * Should be used only as fallback for older firmwares.
38      *
39      * @return true if motion is detected
40      */
41     public boolean isMotion() {
42         return motion;
43     }
44
45     /**
46      * The underlying field is deprecated in the CLIP 2 API.
47      * Motion is valid when motion_report property is present, invalid when absent.
48      * Should be used only as fallback for older firmwares.
49      */
50     public boolean isMotionValid() {
51         return motionValid;
52     }
53
54     public State getMotionState() {
55         return motionValid ? OnOffType.from(motion) : UnDefType.UNDEF;
56     }
57
58     public State getMotionValidState() {
59         return OnOffType.from(motionValid);
60     }
61
62     public @Nullable MotionReport getMotionReport() {
63         return motionReport;
64     }
65 }