]> git.basschouten.com Git - openhab-addons.git/blob
95f2301792694e3165b8fa5e047edf2fec00ba9c
[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.netatmo.internal.api;
14
15 import static org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.*;
16
17 import javax.ws.rs.core.UriBuilder;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FeatureArea;
21 import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.SetpointMode;
22 import org.openhab.binding.netatmo.internal.handler.ApiBridgeHandler;
23
24 /**
25  * The {@link EnergyApi} handles API endpoints related to Energy feature area
26  *
27  * @author Gaël L'hopital - Initial contribution
28  *
29  */
30
31 @NonNullByDefault
32 public class EnergyApi extends RestManager {
33     public EnergyApi(ApiBridgeHandler apiClient) {
34         super(apiClient, FeatureArea.ENERGY);
35     }
36
37     /**
38      *
39      * The method switchSchedule switches the home's schedule to another existing schedule.
40      *
41      * @param homeId The id of home (required)
42      * @param scheduleId The schedule id. It can be found in the getthermstate response, under the keys
43      *            therm_program_backup and therm_program. (required)
44      * @throws NetatmoException If fail to call the API, e.g. server error or cannot deserialize the
45      *             response body
46      */
47     public void switchSchedule(String homeId, String scheduleId) throws NetatmoException {
48         UriBuilder uriBuilder = getAppUriBuilder(SUB_PATH_SWITCH_SCHEDULE, PARAM_HOME_ID, homeId, PARAM_SCHEDULE_ID,
49                 scheduleId);
50         post(uriBuilder, ApiResponse.Ok.class, null);
51     }
52
53     /**
54      *
55      * This endpoint permits to control the heating of a specific home. A home can be set in 3 differents modes:
56      * "schedule" mode in which the home will follow the user schedule
57      * "away" mode which will put the whole house to away (default is 12° but can be changed by the user in its
58      * settings)
59      * "hg" corresponds to frostguard mode (7° by default)
60      *
61      * @param homeId The id of home (required)
62      * @param mode The mode. (required)
63      * @throws NetatmoCommunicationException when call failed, e.g. server error or cannot deserialize
64      */
65     public void setThermMode(String homeId, String mode) throws NetatmoException {
66         UriBuilder uriBuilder = getApiUriBuilder(SUB_PATH_SET_THERM_MODE, PARAM_HOME_ID, homeId, PARAM_MODE, mode);
67         post(uriBuilder, ApiResponse.Ok.class, null);
68     }
69
70     /**
71      *
72      * The method setThermpoint changes the Thermostat manual temperature setpoint.
73      *
74      * @param homeId The id of home (required)
75      * @param roomId The id of the room (required)
76      * @param mode The mode. (required)
77      * @param endtime For manual or max setpoint_mode, defines when the setpoint expires.
78      * @param temp For manual setpoint_mode, defines the temperature setpoint (in °C)
79      * @throws NetatmoCommunicationException when call failed, e.g. server error or cannot deserialize
80      */
81     public void setThermpoint(String homeId, String roomId, SetpointMode mode, long endtime, double temp)
82             throws NetatmoException {
83         UriBuilder uriBuilder = getApiUriBuilder(SUB_PATH_SET_ROOM_THERMPOINT, PARAM_HOME_ID, homeId, PARAM_ROOM_ID,
84                 roomId, PARAM_MODE, mode.apiDescriptor);
85         if (mode == SetpointMode.MANUAL || mode == SetpointMode.MAX) {
86             uriBuilder.queryParam("endtime", endtime);
87             if (mode == SetpointMode.MANUAL) {
88                 uriBuilder.queryParam("temp", temp > THERM_MAX_SETPOINT ? THERM_MAX_SETPOINT : temp);
89             }
90         }
91         post(uriBuilder, ApiResponse.Ok.class, null);
92     }
93 }