]> git.basschouten.com Git - openhab-addons.git/blob
95c391e2258c89d61e73704f36cad4bd6415f6d9
[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.enphase.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.core.thing.ThingTypeUID;
18
19 /**
20  * The {@link EnphaseBindingConstants} class defines common constants, which are
21  * used across the whole binding.
22  *
23  * @author Hilbrand Bouwkamp - Initial contribution
24  */
25 @NonNullByDefault
26 public class EnphaseBindingConstants {
27
28     private static final String BINDING_ID = "enphase";
29
30     // List of all Thing Type UIDs
31     public static final ThingTypeUID THING_TYPE_ENPHASE_ENVOY = new ThingTypeUID(BINDING_ID, "envoy");
32     public static final ThingTypeUID THING_TYPE_ENPHASE_INVERTER = new ThingTypeUID(BINDING_ID, "inverter");
33     public static final ThingTypeUID THING_TYPE_ENPHASE_RELAY = new ThingTypeUID(BINDING_ID, "relay");
34
35     // Configuration parameters
36     public static final String CONFIG_SERIAL_NUMBER = "serialNumber";
37     public static final String CONFIG_HOSTNAME = "hostname";
38     public static final String CONFIG_USERNAME = "username";
39     public static final String CONFIG_PASSWORD = "password";
40     public static final String CONFIG_REFRESH = "refresh";
41     public static final String PROPERTY_VERSION = "version";
42
43     // Envoy gateway channels
44     public static final String ENVOY_CHANNELGROUP_CONSUMPTION = "consumption";
45     public static final String ENVOY_WATT_HOURS_TODAY = "wattHoursToday";
46     public static final String ENVOY_WATT_HOURS_SEVEN_DAYS = "wattHoursSevenDays";
47     public static final String ENVOY_WATT_HOURS_LIFETIME = "wattHoursLifetime";
48     public static final String ENVOY_WATTS_NOW = "wattsNow";
49
50     // Device channels
51     public static final String DEVICE_CHANNEL_STATUS = "status";
52     public static final String DEVICE_CHANNEL_PRODUCING = "producing";
53     public static final String DEVICE_CHANNEL_COMMUNICATING = "communicating";
54     public static final String DEVICE_CHANNEL_PROVISIONED = "provisioned";
55     public static final String DEVICE_CHANNEL_OPERATING = "operating";
56
57     // Inverter channels
58     public static final String INVERTER_CHANNEL_LAST_REPORT_WATTS = "lastReportWatts";
59     public static final String INVERTER_CHANNEL_MAX_REPORT_WATTS = "maxReportWatts";
60     public static final String INVERTER_CHANNEL_LAST_REPORT_DATE = "lastReportDate";
61
62     // Relay channels
63     public static final String RELAY_CHANNEL_RELAY = "relay";
64     public static final String RELAY_CHANNEL_LINE_1_CONNECTED = "line1Connected";
65     public static final String RELAY_CHANNEL_LINE_2_CONNECTED = "line2Connected";
66     public static final String RELAY_CHANNEL_LINE_3_CONNECTED = "line3Connected";
67
68     public static final String RELAY_STATUS_CLOSED = "closed";
69
70     // Properties
71     public static final String DEVICE_PROPERTY_PART_NUMBER = "partNumber";
72
73     // Discovery constants
74     public static final String DISCOVERY_SERIAL = "serialnum";
75     public static final String DISCOVERY_VERSION = "protovers";
76
77     // Status messages
78     public static final String DEVICE_STATUS_OK = "envoy.global.ok";
79     public static final String ERROR_NODATA = "error.nodata";
80
81     public enum EnphaseDeviceType {
82         ACB, // AC Battery
83         PSU, // Inverter
84         NSRB; // Network system relay controller
85
86         public static @Nullable EnphaseDeviceType safeValueOf(final String type) {
87             try {
88                 return valueOf(type);
89             } catch (final IllegalArgumentException e) {
90                 return null;
91             }
92         }
93     }
94
95     /**
96      * Derives the default password from the serial number.
97      *
98      * @param serialNumber serial number to use
99      * @return the default password or empty string if serial number is to short.
100      */
101     public static String defaultPassword(final String serialNumber) {
102         return isValidSerial(serialNumber) ? serialNumber.substring(serialNumber.length() - 6) : "";
103     }
104
105     /**
106      * Checks if the serial number is at least long enough to contain the default password.
107      *
108      * @param serialNumber serial number to check
109      * @return true if not null and at least 6 characters long.
110      */
111     public static boolean isValidSerial(@Nullable final String serialNumber) {
112         return serialNumber != null && serialNumber.length() > 6;
113     }
114 }