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.binding.mielecloud.internal.webservice;
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;
22 * The {@link MieleWebservice} serves as an interface to the Miele REST API and wraps all calls to it.
24 * @author Björn Lange and Roland Edelhoff - Initial contribution
27 public interface MieleWebservice extends AutoCloseable {
29 * Sets the OAuth2 access token to use.
31 void setAccessToken(String accessToken);
34 * Returns whether an access token is available.
36 boolean hasAccessToken();
39 * Connects to the Miele webservice SSE endpoint and starts receiving events.
44 * Disconnects a running connection from the Miele SSE endpoint.
49 * Fetches the available actions for the device with the given {@code deviceId}.
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.
56 void fetchActions(String deviceId);
59 * Performs a PUT operation with the given {@code processAction}.
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.
67 void putProcessAction(String deviceId, ProcessAction processAction);
70 * Performs a PUT operation enabling or disabling the device's light.
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.
78 void putLight(String deviceId, boolean enabled);
81 * Performs a PUT operation switching the device on or off.
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.
89 void putPowerState(String deviceId, boolean enabled);
92 * Performs a PUT operation setting the active program.
94 * @param deviceId ID of the device to trigger the action for.
95 * @param program 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.
100 void putProgram(String deviceId, long programId);
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.
106 * @throws MieleWebserviceException if the request operation fails.
111 * Dispatches the cached state of the device identified by the given device identifier.
113 void dispatchDeviceState(String deviceIdentifier);
116 * Adds a {@link DeviceStateListener}.
118 * @param listener The listener to add.
120 void addDeviceStateListener(DeviceStateListener listener);
123 * Removes a {@link DeviceStateListener}.
125 * @param listener The listener to remove.
127 void removeDeviceStateListener(DeviceStateListener listener);
130 * Adds a {@link ConnectionStatusListener}.
132 * @param listener The listener to add.
134 void addConnectionStatusListener(ConnectionStatusListener listener);
137 * Removes a {@link ConnectionStatusListener}.
139 * @param listener The listener to remove.
141 void removeConnectionStatusListener(ConnectionStatusListener listener);