]> git.basschouten.com Git - openhab-addons.git/blob
ed077efada41cc972c7017849e0707a9c338a0a2
[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 javax.ws.rs.core.UriBuilder;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.freeboxos.internal.api.FreeboxException;
20 import org.openhab.binding.freeboxos.internal.api.Response;
21
22 /**
23  * The {@link AfpManager} is the Java class used to handle api requests related to Afp shares
24  *
25  * @author GaĆ«l L'hopital - Initial contribution
26  */
27 @NonNullByDefault
28 public class AfpManager extends ConfigurableRest<AfpManager.Afp, AfpManager.ConfigResponse> {
29     private static final String AFP_PATH = "afp";
30
31     protected static class ConfigResponse extends Response<Afp> {
32     }
33
34     protected static record Afp(boolean enabled, boolean guestAllow, ServerType serverType, @Nullable String loginName,
35             @Nullable String loginPassword) {
36         private static enum ServerType {
37             POWERBOOK,
38             POWERMAC,
39             MACMINI,
40             IMAC,
41             MACBOOK,
42             MACBOOKPRO,
43             MACBOOKAIR,
44             MACPRO,
45             APPLETV,
46             AIRPORT,
47             XSERVE,
48             UNKNOWN;
49         }
50     }
51
52     public AfpManager(FreeboxOsSession session, UriBuilder uriBuilder) throws FreeboxException {
53         super(session, LoginManager.Permission.NONE, ConfigResponse.class, uriBuilder.path(AFP_PATH), null);
54     }
55
56     public boolean getStatus() throws FreeboxException {
57         return getConfig().enabled;
58     }
59
60     public boolean setStatus(boolean enabled) throws FreeboxException {
61         Afp config = getConfig();
62         Afp newConfig = new Afp(enabled, config.guestAllow, config.serverType, config.loginName, config.loginPassword);
63         return setConfig(newConfig).enabled;
64     }
65 }