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 java.util.Collection;
20 import javax.ws.rs.core.UriBuilder;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.openhab.binding.netatmo.internal.api.data.ModuleType;
25 import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FeatureArea;
26 import org.openhab.binding.netatmo.internal.api.dto.HomeData;
27 import org.openhab.binding.netatmo.internal.api.dto.NAHomeStatus;
28 import org.openhab.binding.netatmo.internal.api.dto.NAHomeStatus.HomeStatus;
29 import org.openhab.binding.netatmo.internal.api.dto.NAHomeStatus.NAHomeStatusResponse;
30 import org.openhab.binding.netatmo.internal.handler.ApiBridgeHandler;
33 * The {@link HomeApi} handles general API endpoints not requiring specific scope area
35 * @author Gaƫl L'hopital - Initial contribution
40 public class HomeApi extends RestManager {
42 public HomeApi(ApiBridgeHandler apiClient) {
43 super(apiClient, FeatureArea.NONE);
46 public @Nullable HomeStatus getHomeStatus(String homeId) throws NetatmoException {
47 UriBuilder uriBuilder = getApiUriBuilder(SUB_PATH_HOMESTATUS, PARAM_HOME_ID, homeId);
49 NAHomeStatusResponse response = get(uriBuilder, NAHomeStatusResponse.class);
50 NAHomeStatus body = response.getBody();
51 return body != null ? body.getHomeStatus().orElse(null) : null;
54 public @Nullable HomeData getHomeData(String homeId) throws NetatmoException {
55 Collection<HomeData> result = getHomesData(homeId, null);
56 return result.isEmpty() ? null : result.iterator().next();
59 public Collection<HomeData> getHomesData(@Nullable String homeId, @Nullable ModuleType type)
60 throws NetatmoException {
61 UriBuilder uriBuilder = getApiUriBuilder(SUB_PATH_HOMES_DATA, PARAM_HOME_ID, homeId);
64 uriBuilder.queryParam(PARAM_GATEWAY_TYPE, type.name());
67 HomeData.HomesDataResponse response = get(uriBuilder, HomeData.HomesDataResponse.class);
68 ListBodyResponse<HomeData> body = response.getBody();
69 return body != null ? body.getElements() : Set.of();