]> git.basschouten.com Git - openhab-addons.git/blob
2ed5b0a66368c736ed52aa72109b1f33da2d312a
[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 org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.freeboxos.internal.api.FreeboxException;
19 import org.openhab.binding.freeboxos.internal.api.Response;
20 import org.openhab.binding.freeboxos.internal.api.rest.FreeboxOsSession.BoxModel;
21
22 import inet.ipaddr.mac.MACAddress;
23
24 /**
25  * The {@link SystemManager} is the Java class used to handle api requests related to system
26  *
27  * @author GaĆ«l L'hopital - Initial contribution
28  */
29 @NonNullByDefault
30 public class SystemManager extends ConfigurableRest<SystemManager.Config, SystemManager.ConfigurationResponse> {
31
32     protected static class ConfigurationResponse extends Response<Config> {
33     }
34
35     public static record Sensor(String id, String name, int value) {
36         public enum SensorKind {
37             FAN,
38             TEMP,
39             UNKNOWN;
40         }
41
42         public SensorKind getKind() {
43             String[] elements = id.split("_");
44             if (elements.length > 0) {
45                 String kind = elements[0].replaceAll("\\d", "").toUpperCase();
46                 try {
47                     return SensorKind.valueOf(kind);
48                 } catch (IllegalArgumentException ignore) { // returning UNKNOWN
49                 }
50             }
51             return SensorKind.UNKNOWN;
52         }
53     }
54
55     private static record Expansion(int slot, boolean probeDone, boolean present, boolean supported, String bundle,
56             Type type) {
57         private static enum Type {
58             UNKNOWN, // unknown module
59             DSL_LTE, // xDSL + LTE
60             DSL_LTE_EXTERNAL_ANTENNAS, // xDSL + LTE with external antennas switch
61             FTTH_P2P, // FTTH P2P
62             FTTH_PON, // FTTH PON
63             SECURITY; // Security module
64         }
65     }
66
67     public static record ModelInfo(BoxModel name, String prettyName, boolean hasExpansions, boolean hasLanSfp,
68             boolean hasDect, boolean hasHomeAutomation, boolean hasFemtocellExp, boolean hasFixedFemtocell,
69             boolean hasVm) {
70     }
71
72     public static record Config(String firmwareVersion, MACAddress mac, String serial, String uptime, long uptimeVal,
73             String boardName, boolean boxAuthenticated, DiskStatus diskStatus, String userMainStorage,
74             List<Sensor> sensors, ModelInfo modelInfo, List<Sensor> fans, List<Expansion> expansions) {
75         private static enum DiskStatus {
76             NOT_DETECTED,
77             DISABLED,
78             INITIALIZING,
79             ERROR,
80             ACTIVE,
81             UNKNOWN;
82         }
83     }
84
85     public SystemManager(FreeboxOsSession session) throws FreeboxException {
86         super(session, LoginManager.Permission.NONE, ConfigurationResponse.class,
87                 session.getUriBuilder().path(SYSTEM_PATH), null);
88     }
89
90     public void reboot() throws FreeboxException {
91         post(REBOOT_ACTION);
92     }
93 }