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.bticinosmarther.internal.account;
15 import java.util.List;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.bticinosmarther.internal.api.dto.Location;
19 import org.openhab.binding.bticinosmarther.internal.api.dto.Module;
20 import org.openhab.binding.bticinosmarther.internal.api.dto.ModuleStatus;
21 import org.openhab.binding.bticinosmarther.internal.api.dto.Plant;
22 import org.openhab.binding.bticinosmarther.internal.api.dto.Program;
23 import org.openhab.binding.bticinosmarther.internal.api.dto.Subscription;
24 import org.openhab.binding.bticinosmarther.internal.api.exception.SmartherGatewayException;
25 import org.openhab.binding.bticinosmarther.internal.model.ModuleSettings;
26 import org.openhab.core.thing.ThingUID;
27 import org.openhab.core.thing.binding.ThingHandler;
30 * The {@code SmartherAccountHandler} interface is used to decouple the Smarther account handler implementation from
33 * @author Fabio Possieri - Initial contribution
36 public interface SmartherAccountHandler extends ThingHandler {
39 * Returns the {@link ThingUID} associated with this Smarther account handler.
41 * @return the thing UID associated with this Smarther account handler
46 * Returns the label of the Smarther Bridge associated with this Smarther account handler.
48 * @return a string containing the bridge label associated with the account handler
53 * Returns the available locations associated with this Smarther account handler.
55 * @return the list of available locations, or an empty {@link List} in case of no locations found
57 List<Location> getLocations();
60 * Checks whether the given location is managed by this Smarther account handler
63 * the identifier of the location to search for
65 * @return {@code true} if the given location is found, {@code false} otherwise
67 boolean hasLocation(String plantId);
70 * Returns the plants registered under the Smarther account the bridge has been configured with.
72 * @return the list of registered plants, or an empty {@link List} in case of no plants found
74 * @throws {@link SmartherGatewayException}
75 * in case of communication issues with the Smarther API
77 List<Plant> getPlants() throws SmartherGatewayException;
80 * Returns the subscriptions registered to the C2C Webhook, where modules status notifications are currently sent
83 * @return the list of registered subscriptions, or an empty {@link List} in case of no subscriptions found
85 * @throws {@link SmartherGatewayException}
86 * in case of communication issues with the Smarther API
88 List<Subscription> getSubscriptions() throws SmartherGatewayException;
91 * Subscribes a plant to the C2C Webhook to start receiving modules status notifications.
94 * the identifier of the plant to be subscribed
95 * @param notificationUrl
96 * the url notifications will have to be sent to for the given plant
98 * @return the identifier this subscription has been registered under
100 * @throws {@link SmartherGatewayException}
101 * in case of communication issues with the Smarther API
103 String subscribePlant(String plantId, String notificationUrl) throws SmartherGatewayException;
106 * Unsubscribes a plant from the C2C Webhook to stop receiving modules status notifications.
109 * the identifier of the plant to be unsubscribed
110 * @param subscriptionId
111 * the identifier of the subscription to be removed for the given plant
113 * @return {@code true} if the plant is successfully unsubscribed, {@code false} otherwise
115 * @throws {@link SmartherGatewayException}
116 * in case of communication issues with the Smarther API
118 void unsubscribePlant(String plantId, String subscriptionId) throws SmartherGatewayException;
121 * Returns the chronothermostat modules registered at the given location.
124 * the identifier of the location
126 * @return the list of registered modules, or an empty {@link List} if the location contains no module or in case of
127 * communication issues with the Smarther API
129 List<Module> getLocationModules(Location location);
132 * Returns the current status of a given chronothermostat module.
135 * the identifier of the plant
137 * the identifier of the chronothermostat module inside the plant
139 * @return the current status of the chronothermostat module
141 * @throws {@link SmartherGatewayException}
142 * in case of communication issues with the Smarther API
144 ModuleStatus getModuleStatus(String plantId, String moduleId) throws SmartherGatewayException;
147 * Sends new settings to be applied to a given chronothermostat module.
150 * the module settings to be applied
152 * @return {@code true} if the settings have been successfully applied, {@code false} otherwise
154 * @throws {@link SmartherGatewayException}
155 * in case of communication issues with the Smarther API
157 boolean setModuleStatus(ModuleSettings moduleSettings) throws SmartherGatewayException;
160 * Returns the automatic mode programs registered for the given chronothermostat module.
163 * the identifier of the plant
165 * the identifier of the chronothermostat module inside the plant
167 * @return the list of registered programs, or an empty {@link List} in case of no programs found
169 * @throws {@link SmartherGatewayException}
170 * in case of communication issues with the Smarther API
172 List<Program> getModulePrograms(String plantId, String moduleId) throws SmartherGatewayException;
175 * Checks whether the Smarther Bridge associated with this Smarther account handler is authorized by Smarther API.
177 * @return {@code true} if the Bridge is authorized, {@code false} otherwise
179 boolean isAuthorized();
182 * Checks whether the Smarther Bridge thing is online.
184 * @return {@code true} if the Bridge is online, {@code false} otherwise
189 * Performs the authorization procedure with Legrand/Bticino portal.
190 * In case of success, the returned refresh/access tokens and the notification url are stored in the Bridge.
193 * the redirect url BTicino/Legrand portal calls back to
195 * the unique code passed by BTicino/Legrand portal to obtain the refresh and access tokens
196 * @param notificationUrl
197 * the endpoint C2C Webhook service will send module status notifications to, once authorized
199 * @return a string containing the name of the BTicino/Legrand portal user that is authorized
201 String authorize(String redirectUrl, String reqCode, String notificationUrl) throws SmartherGatewayException;
204 * Compares this Smarther account handler instance to a given Thing UID.
207 * the Thing UID the account handler is compared to
209 * @return {@code true} if the two instances match, {@code false} otherwise
211 boolean equalsThingUID(String thingUID);
214 * Formats the url used to call the Smarther API in order to authorize the Smarther Bridge associated with this
215 * Smarther account handler.
218 * the uri BTicino/Legrand portal redirects back to
220 * @return a string containing the formatted url, or the empty string ("") in case of issue
222 String formatAuthorizationUrl(String redirectUri);