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 SmartherGatewayException in case of communication issues with the Smarther API
87 List<Subscription> getSubscriptions() throws SmartherGatewayException;
90 * Subscribes a plant to the C2C Webhook to start receiving modules status notifications.
93 * the identifier of the plant to be subscribed
94 * @param notificationUrl
95 * the url notifications will have to be sent to for the given plant
97 * @return the identifier this subscription has been registered under
99 * @throws SmartherGatewayException in case of communication issues with the Smarther API
101 String subscribePlant(String plantId, String notificationUrl) throws SmartherGatewayException;
104 * Unsubscribes a plant from the C2C Webhook to stop receiving modules status notifications.
107 * the identifier of the plant to be unsubscribed
108 * @param subscriptionId
109 * the identifier of the subscription to be removed for the given plant
111 * @throws SmartherGatewayException in case of communication issues with the Smarther API
113 void unsubscribePlant(String plantId, String subscriptionId) throws SmartherGatewayException;
116 * Returns the chronothermostat modules registered at the given location.
119 * the identifier of the location
121 * @return the list of registered modules, or an empty {@link List} if the location contains no module or in case of
122 * communication issues with the Smarther API
124 List<Module> getLocationModules(Location location);
127 * Returns the current status of a given chronothermostat module.
130 * the identifier of the plant
132 * the identifier of the chronothermostat module inside the plant
134 * @return the current status of the chronothermostat module
136 * @throws SmartherGatewayException in case of communication issues with the Smarther API
138 ModuleStatus getModuleStatus(String plantId, String moduleId) throws SmartherGatewayException;
141 * Sends new settings to be applied to a given chronothermostat module.
143 * @param moduleSettings
144 * the module settings to be applied
146 * @return {@code true} if the settings have been successfully applied, {@code false} otherwise
148 * @throws SmartherGatewayException in case of communication issues with the Smarther API
150 boolean setModuleStatus(ModuleSettings moduleSettings) throws SmartherGatewayException;
153 * Returns the automatic mode programs registered for the given chronothermostat module.
156 * the identifier of the plant
158 * the identifier of the chronothermostat module inside the plant
160 * @return the list of registered programs, or an empty {@link List} in case of no programs found
162 * @throws SmartherGatewayException in case of communication issues with the Smarther API
164 List<Program> getModulePrograms(String plantId, String moduleId) throws SmartherGatewayException;
167 * Checks whether the Smarther Bridge associated with this Smarther account handler is authorized by Smarther API.
169 * @return {@code true} if the Bridge is authorized, {@code false} otherwise
171 boolean isAuthorized();
174 * Checks whether the Smarther Bridge thing is online.
176 * @return {@code true} if the Bridge is online, {@code false} otherwise
181 * Performs the authorization procedure with Legrand/Bticino portal.
182 * In case of success, the returned refresh/access tokens and the notification url are stored in the Bridge.
185 * the redirect url BTicino/Legrand portal calls back to
187 * the unique code passed by BTicino/Legrand portal to obtain the refresh and access tokens
188 * @param notificationUrl
189 * the endpoint C2C Webhook service will send module status notifications to, once authorized
191 * @return a string containing the name of the BTicino/Legrand portal user that is authorized
193 String authorize(String redirectUrl, String reqCode, String notificationUrl) throws SmartherGatewayException;
196 * Compares this Smarther account handler instance to a given Thing UID.
199 * the Thing UID the account handler is compared to
201 * @return {@code true} if the two instances match, {@code false} otherwise
203 boolean equalsThingUID(String thingUID);
206 * Formats the url used to call the Smarther API in order to authorize the Smarther Bridge associated with this
207 * Smarther account handler.
210 * the uri BTicino/Legrand portal redirects back to
212 * @return a string containing the formatted url, or the empty string ("") in case of issue
214 String formatAuthorizationUrl(String redirectUri);