2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.lutron.internal.grxprg;
16 * Configuration class for the Grafik Eye controlled by the PRG interface
18 * @author Tim Roberts - Initial contribution
20 public class GrafikEyeConfig {
22 * The control unit identifier
24 private int controlUnit;
27 * The default fade for the unit
32 * The zones designated as shades as parsed
34 private boolean[] shades = new boolean[8];
37 * A string representing if the shade configuration was invalid. Will be null if valid, not-null if invalid
39 private String shadeError;
42 * Polling time (in seconds) to refresh state for the unit.
47 * Validates the configuration. Ensures the control unit. fade and shadeError are valid.
49 * @return a non-null text if invalid (explaining why), a null if valid
52 if (controlUnit < 1 || controlUnit > 8) {
53 return "controlUnit must be between 1-8";
56 if (fade < 0 || fade > 3600) {
57 return "fade must be between 0-3600";
60 if (shadeError != null) {
67 * Returns the Control Unit identifier
69 * @return the control unit identifier
71 public int getControlUnit() {
76 * Sets the control unit identifier
78 * @param controlUnit the control unit identifier
80 public void setControlUnit(int controlUnit) {
81 this.controlUnit = controlUnit;
85 * Returns the default fade
87 * @return the default fade
89 public int getFade() {
94 * Sets the default fade
96 * @param fade the default fade
98 public void setFade(int fade) {
103 * Helper method to determine if the zone is a shade zone or not. If zone number is invalid, false will be returned.
105 * @param zone the zone number
106 * @return true if designated as a shade, false otherwise
108 boolean isShadeZone(int zone) {
109 if (zone >= 1 && zone <= shades.length) {
110 return shades[zone - 1];
116 * Returns a comma formatted list of shade zones
118 * @returna non-null, non-empty comma delimited list of shade zones
120 public String getShadeZones() {
121 final StringBuilder sb = new StringBuilder();
122 for (int z = 0; z < shades.length; z++) {
124 if (sb.length() > 0) {
130 return sb.toString();
134 * Sets the shade zones from a comma delimited list (ex: "2,3,4")
136 * @param shadeZones a, possibly null, list of zones
138 public void setShadeZones(String shadeZones) {
141 for (int zone = 0; zone < 8; zone++) {
142 shades[zone] = false;
145 if (shadeZones != null) {
146 for (String shadeZone : shadeZones.split(",")) {
148 final int zone = Integer.parseInt(shadeZone);
149 if (zone >= 1 && zone <= 8) {
150 shades[zone - 1] = true;
152 shadeError = "Shade zone must be between 1-8: " + zone + " - ignoring";
154 } catch (NumberFormatException e) {
155 shadeError = "Unknown shade zone (can't parse to numeric): " + shadeZone + " - ignoring";
162 * Gets the polling (in seconds) to refresh state
164 * @return the polling (in seconds) to refresh state
166 public int getPolling() {
171 * Sets the polling (in seconds) to refresh state
173 * @param polling the polling (in seconds) to refresh state
175 public void setPolling(int polling) {
176 this.polling = polling;