]> git.basschouten.com Git - openhab-addons.git/blob
b19678f545861218ece6885ee49cb9a673c53a81
[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.concurrent.Callable;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.freeboxos.internal.api.FreeboxException;
19 import org.openhab.binding.freeboxos.internal.api.Response;
20
21 /**
22  * The {@link LcdManager} is the Java class used to handle api requests related to lcd screen of the server
23  * https://dev.freebox.fr/sdk/os/system/#
24  *
25  * @author GaĆ«l L'hopital - Initial contribution
26  */
27 @NonNullByDefault
28 public class LcdManager extends ConfigurableRest<LcdManager.Config, LcdManager.ConfigResponse> {
29     private static final String PATH = "lcd";
30
31     protected static class ConfigResponse extends Response<Config> {
32     }
33
34     public static record Config(int brightness, int orientation, boolean orientationForced) {
35     }
36
37     public LcdManager(FreeboxOsSession session) throws FreeboxException {
38         super(session, LoginManager.Permission.NONE, ConfigResponse.class, session.getUriBuilder().path(PATH),
39                 CONFIG_PATH);
40     }
41
42     private void setBrightness(int brightness) throws FreeboxException {
43         Config oldConfig = getConfig();
44         setConfig(new Config(brightness, oldConfig.orientation, oldConfig.orientationForced));
45     }
46
47     public void setOrientation(int orientation) throws FreeboxException {
48         Config oldConfig = getConfig();
49         setConfig(new Config(oldConfig.brightness, orientation, oldConfig.orientationForced));
50     }
51
52     public void setOrientationForced(boolean forced) throws FreeboxException {
53         Config oldConfig = getConfig();
54         setConfig(new Config(oldConfig.brightness, oldConfig.orientation, forced));
55     }
56
57     public void setBrightness(Callable<Integer> function) throws FreeboxException {
58         try {
59             setBrightness(function.call());
60         } catch (Exception e) {
61             throw new FreeboxException(e, "Error setting brightness");
62         }
63     }
64 }