Skip to content

Commit

Permalink
Made param optional and throw a configuration exception if not config…
Browse files Browse the repository at this point in the history
…ured
  • Loading branch information
renarj committed Nov 23, 2015
1 parent 3313221 commit 04143c6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
import com.oberasoftware.home.zwave.api.messages.ZWaveRawMessage;
import com.oberasoftware.home.zwave.core.utils.IOSupplier;
import com.oberasoftware.home.zwave.exceptions.RuntimeAutomationException;
import com.oberasoftware.home.zwave.exceptions.ZWaveConfigurationException;
import com.oberasoftware.home.zwave.exceptions.ZWaveException;
import com.oberasoftware.home.zwave.threading.ReceiverThread;
import com.oberasoftware.home.zwave.threading.SenderThread;
import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.NoSuchPortException;
import gnu.io.PortInUseException;
import gnu.io.SerialPort;
import gnu.io.UnsupportedCommOperationException;
import gnu.io.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.annotation.PreDestroy;
import java.io.IOException;
Expand All @@ -34,7 +31,7 @@
public class SerialZWaveConnector implements ControllerConnector {
private static final Logger LOG = LoggerFactory.getLogger(SerialZWaveConnector.class);

@Value("${zwave.serial.port}")
@Value("${zwave.serial.port:}")
private String portName;

private SerialPort serialPort;
Expand All @@ -53,6 +50,10 @@ public class SerialZWaveConnector implements ControllerConnector {
* @throws ZWaveException if unable to connect to the serial device
*/
public synchronized void connect() throws ZWaveException {
if(StringUtils.isEmpty(portName)) {
throw new ZWaveConfigurationException("No port configured for ZWave");
}

if(!isConnected) {
LOG.info("Connecting to ZWave serial port device: {}", portName);
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.oberasoftware.home.zwave.exceptions;

/**
* @author Renze de Vries
*/
public class ZWaveConfigurationException extends ZWaveException {
public ZWaveConfigurationException(String message) {
super(message);
}
}
20 changes: 1 addition & 19 deletions src/test/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,7 @@
</appender>


<logger name="com.oberasoftware" level="error"/>
<logger name="com.oberasoftware.home.zwave.LocalZwaveSessionTest" level="info"/>
<!--<logger name="com.oberasoftware.home.zwave.core.impl.EventBusImpl" level="debug"/>-->

<!--<logger name="com.oberasoftware.home.zwave.rules" level="debug"/>-->
<!--<logger name="com.oberasoftware.home.zwave.threading" level="error"/>-->
<!--<logger name="com.oberasoftware.home.zwave.filters" level="error"/>-->
<!--<logger name="com.oberasoftware.home.zwave.api.messages.ZWaveRawMessage" level="error"/>-->
<!--<logger name="com.oberasoftware.base.event.impl.HandlerEntryImpl" level="error"/>-->
<!--<logger name="com.oberasoftware.base.event.impl.LocalEventBus" level="error"/>-->
<!--<logger name="com.oberasoftware.home.zwave.TransactionManagerImpl" level="error"/>-->
<!--<logger name="com.oberasoftware.home.zwave.core.utils" level="error"/>-->
<!--<logger name="com.oberasoftware.home.zwave.converter" level="info"/>-->
<!--<logger name="com.oberasoftware.home.zwave.converter.controller.ApplicationUpdateCommandConverter" level="debug"/>-->
<!--<logger name="com.oberasoftware.home.zwave.converter.events.VersionConverter" level="debug"/>-->
<!--<logger name="com.oberasoftware.home.zwave.handlers.ApplicationCommandHandler" level="debug"/>-->
<!--<logger name="com.oberasoftware.home.zwave.handlers.NodeEventHandler" level="debug"/>-->
<!--<logger name="com.oberasoftware.home.zwave.handlers.WakeUpHandler" level="info"/>-->
<!--<logger name="com.oberasoftware.home.zwave.handlers.MainEventHandler" level="debug"/>-->
<logger name="com.oberasoftware" level="info"/>
<logger name="org.springframework" level="info"/>

<root level="OFF">
Expand Down

0 comments on commit 04143c6

Please sign in to comment.