Skip to content

Commit

Permalink
[lutron] Add null annotations and minor clean-up (openhab#8104)
Browse files Browse the repository at this point in the history
Signed-off-by: Bob Adair <[email protected]>
  • Loading branch information
bobadair authored and andrewfg committed Aug 31, 2020
1 parent 4419c9b commit 211c802
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
*/
package org.openhab.binding.lutron.internal.config;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;

/**
* Configuration settings for an {@link org.openhab.binding.lutron.internal.handler.BlindHandler}.
*
* @author Bob Adair - Initial contribution
*/
@NonNullByDefault
public class BlindConfig {
public int integrationId = 0;
public String type;
public @Nullable String type;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,18 @@

import java.math.BigDecimal;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* Configuration settings for a {@link org.openhab.binding.lutron.internal.handler.DimmerHandler}.
*
* @author Allan Tong - Initial contribution
*/
@NonNullByDefault
public class DimmerConfig {
private static final int DEFAULT_FADE = 1;

private int integrationId;
private BigDecimal fadeInTime = new BigDecimal(DEFAULT_FADE);
private BigDecimal fadeOutTime = new BigDecimal(DEFAULT_FADE);

public int getIntegrationId() {
return this.integrationId;
}

public void setIntegrationId(int integrationId) {
this.integrationId = integrationId;
}

public BigDecimal getFadeInTime() {
return this.fadeInTime;
}

public void setFadeInTime(BigDecimal fadeInTime) {
this.fadeInTime = fadeInTime;
}

public BigDecimal getFadeOutTime() {
return this.fadeOutTime;
}

public void setFadeOutTime(BigDecimal fadeOutTime) {
this.fadeOutTime = fadeOutTime;
}
public int integrationId;
public BigDecimal fadeInTime = new BigDecimal(DEFAULT_FADE);
public BigDecimal fadeOutTime = new BigDecimal(DEFAULT_FADE);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ public DimmerHandler(Thing thing) {

@Override
public int getIntegrationId() {
if (this.config == null) {
if (config == null) {
throw new IllegalStateException("handler not initialized");
}

return this.config.getIntegrationId();
return config.integrationId;
}

@Override
public void initialize() {
config = getThing().getConfiguration().as(DimmerConfig.class);
if (config.getIntegrationId() <= 0) {
if (config.integrationId <= 0) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "No integrationId configured");
return;
}
Expand Down Expand Up @@ -97,9 +97,9 @@ public void handleCommand(ChannelUID channelUID, Command command) {

output(ACTION_ZONELEVEL, level, 0.25);
} else if (command.equals(OnOffType.ON)) {
output(ACTION_ZONELEVEL, 100, this.config.getFadeInTime());
output(ACTION_ZONELEVEL, 100, this.config.fadeInTime);
} else if (command.equals(OnOffType.OFF)) {
output(ACTION_ZONELEVEL, 0, this.config.getFadeOutTime());
output(ACTION_ZONELEVEL, 0, this.config.fadeOutTime);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ public ComponentType type() {
}
}

private static final List<Component> BUTTONGROUP = Arrays.asList(Component.BUTTON1, Component.BUTTON2,
private static final List<Component> BUTTON_GROUP = Arrays.asList(Component.BUTTON1, Component.BUTTON2,
Component.BUTTON3, Component.BUTTON4, Component.BUTTON5, Component.BUTTON6);

private static final List<Component> LEDGROUP = Arrays.asList(Component.LED1, Component.LED2, Component.LED3,
private static final List<Component> LED_GROUP = Arrays.asList(Component.LED1, Component.LED2, Component.LED3,
Component.LED4, Component.LED5, Component.LED6);

private static final List<Component> CCIGROUP = Arrays.asList(Component.CCI1, Component.CCI2, Component.CCI3,
private static final List<Component> CCI_GROUP = Arrays.asList(Component.CCI1, Component.CCI2, Component.CCI3,
Component.CCI4);

private final Logger logger = LoggerFactory.getLogger(VcrxHandler.class);
Expand All @@ -114,9 +114,9 @@ protected boolean isCCI(int id) {
protected void configureComponents(@Nullable String model) {
logger.debug("Configuring components for VCRX");

buttonList.addAll(BUTTONGROUP);
ledList.addAll(LEDGROUP);
cciList.addAll(CCIGROUP);
buttonList.addAll(BUTTON_GROUP);
ledList.addAll(LED_GROUP);
cciList.addAll(CCI_GROUP);
}

public VcrxHandler(Thing thing) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,29 @@ public ComponentType type() {
}
}

private static final List<KeypadComponent> BUTTONGROUP1 = Arrays.asList(Component.BUTTON1, Component.BUTTON2,
private static final List<KeypadComponent> BUTTON_GROUP1 = Arrays.asList(Component.BUTTON1, Component.BUTTON2,
Component.BUTTON3, Component.BUTTON4, Component.BUTTON5);
private static final List<KeypadComponent> BUTTONGROUP2 = Arrays.asList(Component.BUTTON6, Component.BUTTON7,
private static final List<KeypadComponent> BUTTON_GROUP2 = Arrays.asList(Component.BUTTON6, Component.BUTTON7,
Component.BUTTON8, Component.BUTTON9, Component.BUTTON10);
private static final List<KeypadComponent> BUTTONGROUP3 = Arrays.asList(Component.BUTTON11, Component.BUTTON12,
private static final List<KeypadComponent> BUTTON_GROUP3 = Arrays.asList(Component.BUTTON11, Component.BUTTON12,
Component.BUTTON13, Component.BUTTON14, Component.BUTTON15);

private static final List<KeypadComponent> BUTTONGROUPBOTTOM_RL = Arrays.asList(Component.BUTTON16,
private static final List<KeypadComponent> BUTTON_GROUPBOTTOM_RL = Arrays.asList(Component.BUTTON16,
Component.BUTTON17, Component.LOWER3, Component.RAISE3);
private static final List<KeypadComponent> BUTTONGROUPBOTTOM_CRL = Arrays.asList(Component.LOWER1, Component.RAISE1,
private static final List<KeypadComponent> BUTTON_GROUPBOTTOM_CRL = Arrays.asList(Component.LOWER1, Component.RAISE1,
Component.LOWER2, Component.RAISE2, Component.LOWER3, Component.RAISE3);
private static final List<KeypadComponent> BUTTONGROUPBOTTOM_GENERIC = Arrays.asList(Component.BUTTON16,
private static final List<KeypadComponent> BUTTON_GROUPBOTTOM_GENERIC = Arrays.asList(Component.BUTTON16,
Component.BUTTON17, Component.LOWER1, Component.RAISE1, Component.LOWER2, Component.RAISE2,
Component.LOWER3, Component.RAISE3);

private static final List<KeypadComponent> LEDGROUP1 = Arrays.asList(Component.LED1, Component.LED2, Component.LED3,
private static final List<KeypadComponent> LED_GROUP1 = Arrays.asList(Component.LED1, Component.LED2, Component.LED3,
Component.LED4, Component.LED5);
private static final List<KeypadComponent> LEDGROUP2 = Arrays.asList(Component.LED6, Component.LED7, Component.LED8,
private static final List<KeypadComponent> LED_GROUP2 = Arrays.asList(Component.LED6, Component.LED7, Component.LED8,
Component.LED9, Component.LED10);
private static final List<KeypadComponent> LEDGROUP3 = Arrays.asList(Component.LED11, Component.LED12,
private static final List<KeypadComponent> LED_GROUP3 = Arrays.asList(Component.LED11, Component.LED12,
Component.LED13, Component.LED14, Component.LED15);

private static final List<KeypadComponent> LEDGROUPBOTTOM_RL = Arrays.asList(Component.LED16, Component.LED17);
private static final List<KeypadComponent> LED_GROUPBOTTOM_RL = Arrays.asList(Component.LED16, Component.LED17);

@Override
public boolean isLed(int id) {
Expand All @@ -146,22 +146,22 @@ public boolean isCCI(int id) {
}

public KeypadConfigTabletopSeetouch() {
modelData.put("T5RL", combinedList(BUTTONGROUP1, BUTTONGROUPBOTTOM_RL, LEDGROUP1, LEDGROUPBOTTOM_RL));
modelData.put("T5RL", combinedList(BUTTON_GROUP1, BUTTON_GROUPBOTTOM_RL, LED_GROUP1, LED_GROUPBOTTOM_RL));

modelData.put("T10RL", combinedList(BUTTONGROUP1, BUTTONGROUP2, BUTTONGROUPBOTTOM_RL, LEDGROUP1, LEDGROUP2,
LEDGROUPBOTTOM_RL));
modelData.put("T10RL", combinedList(BUTTON_GROUP1, BUTTON_GROUP2, BUTTON_GROUPBOTTOM_RL, LED_GROUP1, LED_GROUP2,
LED_GROUPBOTTOM_RL));

modelData.put("T15RL", combinedList(BUTTONGROUP1, BUTTONGROUP2, BUTTONGROUP3, BUTTONGROUPBOTTOM_RL, LEDGROUP1,
LEDGROUP2, LEDGROUP3, LEDGROUPBOTTOM_RL));
modelData.put("T15RL", combinedList(BUTTON_GROUP1, BUTTON_GROUP2, BUTTON_GROUP3, BUTTON_GROUPBOTTOM_RL, LED_GROUP1,
LED_GROUP2, LED_GROUP3, LED_GROUPBOTTOM_RL));

modelData.put("T5CRL", combinedList(BUTTONGROUP1, BUTTONGROUPBOTTOM_CRL, LEDGROUP1));
modelData.put("T5CRL", combinedList(BUTTON_GROUP1, BUTTON_GROUPBOTTOM_CRL, LED_GROUP1));

modelData.put("T10CRL", combinedList(BUTTONGROUP1, BUTTONGROUP2, BUTTONGROUPBOTTOM_CRL, LEDGROUP1, LEDGROUP2));
modelData.put("T10CRL", combinedList(BUTTON_GROUP1, BUTTON_GROUP2, BUTTON_GROUPBOTTOM_CRL, LED_GROUP1, LED_GROUP2));

modelData.put("T15CRL", combinedList(BUTTONGROUP1, BUTTONGROUP2, BUTTONGROUP3, BUTTONGROUPBOTTOM_CRL, LEDGROUP1,
LEDGROUP2, LEDGROUP3));
modelData.put("T15CRL", combinedList(BUTTON_GROUP1, BUTTON_GROUP2, BUTTON_GROUP3, BUTTON_GROUPBOTTOM_CRL, LED_GROUP1,
LED_GROUP2, LED_GROUP3));

modelData.put("Generic", combinedList(BUTTONGROUP1, BUTTONGROUP2, BUTTONGROUP3, BUTTONGROUPBOTTOM_GENERIC,
LEDGROUP1, LEDGROUP2, LEDGROUP3, LEDGROUPBOTTOM_RL)); // Superset of all models
modelData.put("Generic", combinedList(BUTTON_GROUP1, BUTTON_GROUP2, BUTTON_GROUP3, BUTTON_GROUPBOTTOM_GENERIC,
LED_GROUP1, LED_GROUP2, LED_GROUP3, LED_GROUPBOTTOM_RL)); // Superset of all models
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.io.Reader;
import java.net.URL;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.lutron.internal.discovery.project.Area;
import org.openhab.binding.lutron.internal.discovery.project.Component;
import org.openhab.binding.lutron.internal.discovery.project.Device;
Expand All @@ -37,6 +39,7 @@
* @author Bob Adair - Added support for reading XML from a file. Requires using XStream directly
* instead of XmlDocumentReader.
*/
@NonNullByDefault
public class DbXmlInfoReader {

private final XStream xstream;
Expand Down Expand Up @@ -115,31 +118,31 @@ public void registerAliases(XStream xstream) {
xstream.ignoreUnknownElements();
}

public Project readFromXML(URL xmlURL) throws ConversionException {
public @Nullable Project readFromXML(@Nullable URL xmlURL) throws ConversionException {
if (xmlURL != null) {
return (Project) xstream.fromXML(xmlURL);
}

return null;
}

public Project readFromXML(File xmlFile) throws ConversionException {
public @Nullable Project readFromXML(@Nullable File xmlFile) throws ConversionException {
if (xmlFile != null) {
return (Project) xstream.fromXML(xmlFile);
}

return null;
}

public Project readFromXML(Reader xmlReader) throws ConversionException {
public @Nullable Project readFromXML(@Nullable Reader xmlReader) throws ConversionException {
if (xmlReader != null) {
return (Project) xstream.fromXML(xmlReader);
}

return null;
}

public Project readFromXML(String xmlString) throws ConversionException {
public @Nullable Project readFromXML(@Nullable String xmlString) throws ConversionException {
if (xmlString != null) {
return (Project) xstream.fromXML(xmlString);
}
Expand Down

0 comments on commit 211c802

Please sign in to comment.