]> git.basschouten.com Git - openhab-addons.git/blob
682a70b7bf8c355c87e20125f3989e879baca92b
[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.mielecloud.internal.webservice;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.mielecloud.internal.webservice.api.json.ProcessAction;
17 import org.openhab.binding.mielecloud.internal.webservice.exception.AuthorizationFailedException;
18 import org.openhab.binding.mielecloud.internal.webservice.exception.MieleWebserviceException;
19 import org.openhab.binding.mielecloud.internal.webservice.exception.TooManyRequestsException;
20
21 /**
22  * The {@link MieleWebservice} serves as an interface to the Miele REST API and wraps all calls to it.
23  *
24  * @author Björn Lange and Roland Edelhoff - Initial contribution
25  */
26 @NonNullByDefault
27 public interface MieleWebservice extends AutoCloseable {
28     /**
29      * Sets the OAuth2 access token to use.
30      */
31     void setAccessToken(String accessToken);
32
33     /**
34      * Returns whether an access token is available.
35      */
36     boolean hasAccessToken();
37
38     /**
39      * Connects to the Miele webservice SSE endpoint and starts receiving events.
40      */
41     void connectSse();
42
43     /**
44      * Disconnects a running connection from the Miele SSE endpoint.
45      */
46     void disconnectSse();
47
48     /**
49      * Fetches the available actions for the device with the given {@code deviceId}.
50      *
51      * @param deviceId The unique ID of the device to fetch the available actions for.
52      * @throws MieleWebserviceException if an error occurs during webservice requests or content parsing.
53      * @throws AuthorizationFailedException if the authorization against the webservice failed.
54      * @throws TooManyRequestsException if too many requests have been made against the webservice recently.
55      */
56     void fetchActions(String deviceId);
57
58     /**
59      * Performs a PUT operation with the given {@code processAction}.
60      *
61      * @param deviceId ID of the device to trigger the action for.
62      * @param processAction The action to perform.
63      * @throws MieleWebserviceException if an error occurs during webservice requests or content parsing.
64      * @throws AuthorizationFailedException if the authorization against the webservice failed.
65      * @throws TooManyRequestsException if too many requests have been made against the webservice recently.
66      */
67     void putProcessAction(String deviceId, ProcessAction processAction);
68
69     /**
70      * Performs a PUT operation enabling or disabling the device's light.
71      *
72      * @param deviceId ID of the device to trigger the action for.
73      * @param enabled {@code true} to enable or {@code false} to disable the light.
74      * @throws MieleWebserviceException if an error occurs during webservice requests or content parsing.
75      * @throws AuthorizationFailedException if the authorization against the webservice failed.
76      * @throws TooManyRequestsException if too many requests have been made against the webservice recently.
77      */
78     void putLight(String deviceId, boolean enabled);
79
80     /**
81      * Performs a PUT operation switching the device on or off.
82      *
83      * @param deviceId ID of the device to trigger the action for.
84      * @param enabled {@code true} to switch on or {@code false} to switch off the device.
85      * @throws MieleWebserviceException if an error occurs during webservice requests or content parsing.
86      * @throws AuthorizationFailedException if the authorization against the webservice failed.
87      * @throws TooManyRequestsException if too many requests have been made against the webservice recently.
88      */
89     void putPowerState(String deviceId, boolean enabled);
90
91     /**
92      * Performs a PUT operation setting the active program.
93      *
94      * @param deviceId ID of the device to trigger the action for.
95      * @param programId The program to activate.
96      * @throws MieleWebserviceException if an error occurs during webservice requests or content parsing.
97      * @throws AuthorizationFailedException if the authorization against the webservice failed.
98      * @throws TooManyRequestsException if too many requests have been made against the webservice recently.
99      */
100     void putProgram(String deviceId, long programId);
101
102     /**
103      * Performs a logout and invalidates the current OAuth2 token. This operation is assumed to work on the first try
104      * and is never retried. HTTP errors are ignored.
105      *
106      * @throws MieleWebserviceException if the request operation fails.
107      */
108     void logout();
109
110     /**
111      * Dispatches the cached state of the device identified by the given device identifier.
112      */
113     void dispatchDeviceState(String deviceIdentifier);
114
115     /**
116      * Adds a {@link DeviceStateListener}.
117      *
118      * @param listener The listener to add.
119      */
120     void addDeviceStateListener(DeviceStateListener listener);
121
122     /**
123      * Removes a {@link DeviceStateListener}.
124      *
125      * @param listener The listener to remove.
126      */
127     void removeDeviceStateListener(DeviceStateListener listener);
128
129     /**
130      * Adds a {@link ConnectionStatusListener}.
131      *
132      * @param listener The listener to add.
133      */
134     void addConnectionStatusListener(ConnectionStatusListener listener);
135
136     /**
137      * Removes a {@link ConnectionStatusListener}.
138      *
139      * @param listener The listener to remove.
140      */
141     void removeConnectionStatusListener(ConnectionStatusListener listener);
142 }