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.netatmo.internal.api;
15 import static org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.*;
17 import javax.ws.rs.core.UriBuilder;
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;
25 * The {@link EnergyApi} handles API endpoints related to Energy feature area
27 * @author Gaël L'hopital - Initial contribution
32 public class EnergyApi extends RestManager {
33 public EnergyApi(ApiBridgeHandler apiClient) {
34 super(apiClient, FeatureArea.ENERGY);
39 * The method switchSchedule switches the home's schedule to another existing schedule.
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
47 public void switchSchedule(String homeId, String scheduleId) throws NetatmoException {
48 UriBuilder uriBuilder = getApiUriBuilder(SUB_PATH_SWITCH_SCHEDULE, PARAM_HOME_ID, homeId, PARAM_SCHEDULE_ID,
50 post(uriBuilder, ApiResponse.Ok.class, null);
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
59 * "hg" corresponds to frostguard mode (7° by default)
61 * @param homeId The id of home (required)
62 * @param mode The mode. (required)
63 * @throws NetatmoException when call failed, e.g. server error or cannot deserialize
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);
72 * The method setThermpoint changes the Thermostat manual temperature setpoint.
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 NetatmoException when call failed, e.g. server error or cannot deserialize
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);
91 post(uriBuilder, ApiResponse.Ok.class, null);