]> git.basschouten.com Git - openhab-addons.git/blob
4fbb9052aef9f8434ff6a87bdc4ec2f351d584f6
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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, String serverType, @Nullable String loginName,
35             @Nullable String loginPassword) {
36     }
37
38     public AfpManager(FreeboxOsSession session, UriBuilder uriBuilder) throws FreeboxException {
39         super(session, LoginManager.Permission.NONE, ConfigResponse.class, uriBuilder.path(AFP_PATH), null);
40     }
41
42     public boolean getStatus() throws FreeboxException {
43         return getConfig().enabled;
44     }
45
46     public boolean setStatus(boolean enabled) throws FreeboxException {
47         Afp config = getConfig();
48         Afp newConfig = new Afp(enabled, config.guestAllow, config.serverType, config.loginName, config.loginPassword);
49         return setConfig(newConfig).enabled;
50     }
51 }