]> git.basschouten.com Git - openhab-addons.git/blob
f88b30d89dd232ae5bfa4646f73757390979a4f0
[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.freeboxos.internal.api.rest;
14
15 import java.util.List;
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.freeboxos.internal.api.FreeboxException;
22 import org.openhab.binding.freeboxos.internal.api.Response;
23
24 /**
25  * The {@link ListableRest} is the Java class used to handle rest answers holding a list of known equipments
26  *
27  * @author GaĆ«l L'hopital - Initial contribution
28  */
29 @NonNullByDefault
30 public class ListableRest<T, Z extends Response<T>> extends RestManager {
31     private final Class<Z> deviceResponseClass;
32
33     protected @Nullable String listSubPath = null;
34
35     public ListableRest(FreeboxOsSession session, LoginManager.Permission required, Class<Z> respClass, UriBuilder uri)
36             throws FreeboxException {
37         super(session, required, uri);
38         this.deviceResponseClass = respClass;
39     }
40
41     public List<T> getDevices() throws FreeboxException {
42         return listSubPath == null ? get(deviceResponseClass) : get(deviceResponseClass, listSubPath);
43     }
44
45     public T getDevice(int deviceId) throws FreeboxException {
46         return getSingle(deviceResponseClass, Integer.toString(deviceId));
47     }
48 }