]> git.basschouten.com Git - openhab-addons.git/blob
ca6a9bf74d8744977896e556006f4e11f4d6fbda
[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.sleepiq.internal.api;
14
15 import java.util.List;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.eclipse.jetty.client.HttpClient;
20 import org.openhab.binding.sleepiq.internal.api.dto.Bed;
21 import org.openhab.binding.sleepiq.internal.api.dto.FamilyStatusResponse;
22 import org.openhab.binding.sleepiq.internal.api.dto.LoginInfo;
23 import org.openhab.binding.sleepiq.internal.api.dto.PauseModeResponse;
24 import org.openhab.binding.sleepiq.internal.api.dto.SleepDataResponse;
25 import org.openhab.binding.sleepiq.internal.api.dto.Sleeper;
26 import org.openhab.binding.sleepiq.internal.api.enums.Side;
27 import org.openhab.binding.sleepiq.internal.api.enums.SleepDataInterval;
28 import org.openhab.binding.sleepiq.internal.api.impl.SleepIQImpl;
29
30 /**
31  * This interface is the main API to access the SleepIQ system.
32  *
33  * @author Gregory Moyer - Initial contribution
34  */
35 @NonNullByDefault
36 public interface SleepIQ {
37     /**
38      * Login to the {@link Configuration configured} account. This method is not
39      * required to be called before other methods because all methods must
40      * ensure login before acting. However, when the only desired action is to
41      * login and not retrieve other data, this method is the most efficient
42      * option.
43      *
44      * @return basic information about the logged in user
45      * @throws UnauthorizedException
46      *             if the credentials provided are not valid
47      * @throws LoginException
48      *             if the login request fails for any reason other than bad
49      *             credentials (including missing credentials)
50      */
51     public @Nullable LoginInfo login() throws LoginException, UnauthorizedException;
52
53     /**
54      * Get a list of beds connected to the account.
55      *
56      * @return the list of beds
57      * @throws LoginException
58      *             if the login request fails for any reason other than bad
59      *             credentials (including missing credentials)
60      * @throws SleepIQException
61      */
62     public List<Bed> getBeds() throws LoginException, SleepIQException, BedNotFoundException;
63
64     /**
65      * Get a list of sleepers registered to this account for beds or bed positions
66      * (left or right side).
67      *
68      * @return the list of sleepers
69      * @throws LoginException
70      * @throws SleepIQException
71      */
72     public List<Sleeper> getSleepers() throws LoginException, SleepIQException;
73
74     /**
75      * Get the status of all beds and all air chambers registered to this
76      * account.
77      *
78      * @return the complete status of beds on the account
79      * @throws LoginException
80      * @throws SleepIQException
81      */
82     public FamilyStatusResponse getFamilyStatus() throws LoginException, SleepIQException;
83
84     /**
85      * Get the Sleep Data for a sleeper registered to this account.
86      *
87      * @param sleeperId the sleeper Id to query
88      * @param interval The time period for which data is to be queried
89      * @return the Sleep Data
90      * @throws BedNotFoundException
91      *             if the bed identifier was not found on the account
92      * @throws LoginException
93      * @throws SleepIQException
94      */
95     public SleepDataResponse getSleepData(String sleeperId, SleepDataInterval interval)
96             throws BedNotFoundException, LoginException, SleepIQException;
97
98     /**
99      * Get the status of "pause mode" (disabling SleepIQ data upload) for a
100      * specific bed. A bed in pause mode will send no information to the SleepIQ
101      * cloud services. For example, if a sleeper is in bed and disables SleepIQ
102      * (enables pause mode), the service will continue to report that the bed is
103      * occupied even after the sleeper exits the bed until pause mode is
104      * disabled.
105      *
106      * @return the status of pause mode for the specified bed
107      * @throws BedNotFoundException
108      *             if the bed identifier was not found on the account
109      * @throws LoginException
110      * @throws SleepIQException
111      */
112     public PauseModeResponse getPauseMode(String bedId) throws BedNotFoundException, LoginException, SleepIQException;
113
114     /**
115      * Set the sleep number for a chamber of a bed
116      *
117      * @param bedId the unique identifier of the bed
118      * @param side thethe chamber of the bed
119      * @param sleepNumber the new sleep number
120      *
121      * @throws LoginException
122      * @throws SleepIQException
123      */
124     public void setSleepNumber(String bedId, Side side, int sleepNumber) throws LoginException, SleepIQException;
125
126     /**
127      * Set the pause (privacy) mode for a bed
128      *
129      * @param bedId the unique identifier of the bed
130      *
131      * @throws LoginException
132      * @throws SleepIQException
133      */
134     public void setPauseMode(String bedId, boolean command) throws LoginException, SleepIQException;
135
136     /**
137      * Create a default implementation instance of this interface. Each call to
138      * this method will create a new object.
139      *
140      * @param config the configuration to use for the new instance
141      * @param httpClient handle to the Jetty http client
142      * @return a concrete implementation of this interface
143      */
144     public static SleepIQ create(Configuration config, HttpClient httpClient) {
145         return new SleepIQImpl(config, httpClient);
146     }
147
148     /**
149      * Close down the cloud service
150      */
151     public void shutdown();
152 }