]> git.basschouten.com Git - openhab-addons.git/blob
be9fc9fa631d782f0c6da6f39a34bec5c49647c6
[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.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FeatureArea;
22 import org.openhab.binding.netatmo.internal.api.dto.NAMain;
23 import org.openhab.binding.netatmo.internal.api.dto.NAMain.StationDataResponse;
24 import org.openhab.binding.netatmo.internal.handler.ApiBridgeHandler;
25
26 /**
27  * Base class for all Air Care related endpoints
28  *
29  * @author GaĆ«l L'hopital - Initial contribution
30  */
31 @NonNullByDefault
32 public class AircareApi extends RestManager {
33
34     public AircareApi(ApiBridgeHandler apiClient) {
35         super(apiClient, FeatureArea.AIR_CARE);
36     }
37
38     /**
39      * Returns data from Healthy Home Coach Station (measures and device specific data).
40      *
41      * @param deviceId Id of the device you want to retrieve information of (optional)
42      * @return StationDataResponse
43      * @throws NetatmoException If fail to call the API, e.g. server error or deserializing
44      */
45     public StationDataResponse getHomeCoachData(@Nullable String deviceId) throws NetatmoException {
46         UriBuilder uriBuilder = getApiUriBuilder(SUB_PATH_HOMECOACH, PARAM_DEVICE_ID, deviceId);
47         return get(uriBuilder, StationDataResponse.class);
48     }
49
50     public NAMain getHomeCoach(String deviceId) throws NetatmoException {
51         ListBodyResponse<NAMain> answer = getHomeCoachData(deviceId).getBody();
52         if (answer != null) {
53             NAMain station = answer.getElement(deviceId);
54             if (station != null) {
55                 return station;
56             }
57         }
58         throw new NetatmoException("Unexpected answer querying device '%s' : not found.", deviceId);
59     }
60 }