Skip to content

Commit

Permalink
[lutron] Add support for bridged RadioRA (classic) systems (openhab#1…
Browse files Browse the repository at this point in the history
…0302)

Signed-off-by: Bob Adair <bob.github@att.net>
Signed-off-by: John Marshall <john.marshall.au@gmail.com>
  • Loading branch information
bobadair authored and themillhousegroup committed May 10, 2021
1 parent dab5693 commit 33b8388
Show file tree
Hide file tree
Showing 25 changed files with 279 additions and 102 deletions.
32 changes: 20 additions & 12 deletions bundles/org.openhab.binding.lutron/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,12 @@ end
This binding integrates with the legacy Lutron RadioRA (Classic) lighting system.

This binding depends on RS232 communication.
It has only been tested using the Chronos time module but the RS232 module should work as well.
It has only been tested using the Chronos System Bridge and Timeclock (RA-SBT-CHR) module, but Lutron's RA-RS232 or RB-RS232 module should work as well.

Support has been added for bridged RadioRA systems.
A system is considered “bridged” when a Chronos System Bridge and Timeclock is used to integrate two RadioRA Systems in a single residence.
In a bridged system, the `system` parameter of each configured ra-dimmer, ra-switch, or ra-phantomButton thing should be set to indicate which RadioRA system it is a part of (i.e. 1 or 2).
In a non-bridged system, these parameters should be left at their default of 0.

## Supported Things

Expand All @@ -808,17 +813,20 @@ This binding currently supports the following thing types:
| ra-phantomButton | Thing | Phantom Button to control multiple controls (Scenes) |


## Thing Configurations

| Thing | Config | Description |
|------------------|--------------|-----------------------------------------------------------------------|
| ra-rs232 | portName | The serial port to use to communicate with Chronos or RS232 module |
| | baud | (Optional) Baud Rate (defaults to 9600) |
| ra-dimmer | zoneNumber | Assigned Zone Number within the Lutron RadioRA system |
| | fadeOutSec | (Optional) Time in seconds dimmer should take when lowering the level |
| | fadeInSec | (Optional) Time in seconds dimmer should take when lowering the level |
| ra-switch | zoneNumber | Assigned Zone Number within the Lutron RadioRA system |
| ra-phantomButton | buttonNumber | Phantom Button Number within the Lutron RadioRA system |
## Thing Configuration Parameters

| Thing | Parameter | Description |
|------------------|--------------|------------------------------------------------------------------------|
| ra-rs232 | portName | The serial port to use to communicate with Chronos or RS232 module |
| | baud | (Optional) Baud Rate (defaults to 9600) |
| ra-dimmer | zoneNumber | Assigned Zone Number within the Lutron RadioRA system |
| | system | (Optional) System number (1 or 2) in a bridged system. Default=0 (n/a) |
| | fadeOutSec | (Optional) Time in seconds dimmer should take when lowering the level |
| | fadeInSec | (Optional) Time in seconds dimmer should take when lowering the level |
| ra-switch | zoneNumber | Assigned Zone Number within the Lutron RadioRA system |
| | system | (Optional) System number (1 or 2) in a bridged system. Default=0 (n/a) |
| ra-phantomButton | buttonNumber | Phantom Button Number within the Lutron RadioRA system |
| | system | (Optional) System number (1 or 2) in a bridged system. Default=0 (n/a) |

## Channels

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.TooManyListenersException;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.lutron.internal.radiora.protocol.RadioRAFeedback;
import org.openhab.core.io.transport.serial.PortInUseException;
import org.openhab.core.io.transport.serial.SerialPort;
Expand All @@ -34,16 +37,17 @@
* @author Jeff Lauterbach - Initial Contribution
*
*/
@NonNullByDefault
public class RS232Connection implements RadioRAConnection, SerialPortEventListener {

private final Logger logger = LoggerFactory.getLogger(RS232Connection.class);

protected SerialPortManager serialPortManager;
protected SerialPort serialPort;
protected @Nullable SerialPort serialPort;

protected BufferedReader inputReader;
protected @Nullable BufferedReader inputReader;

protected RadioRAFeedbackListener listener;
protected @Nullable RadioRAFeedbackListener listener;
protected RS232MessageParser parser = new RS232MessageParser();

public RS232Connection(SerialPortManager serialPortManager) {
Expand All @@ -59,7 +63,8 @@ public void open(String portName, int baud) throws RadioRAConnectionException {
}

try {
serialPort = portIdentifier.open("openhab", 5000);
SerialPort serialPort = portIdentifier.open("openhab", 5000);
this.serialPort = serialPort;
serialPort.notifyOnDataAvailable(true);
serialPort.setSerialPortParams(baud, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
serialPort.addEventListener(this);
Expand All @@ -78,24 +83,39 @@ public void open(String portName, int baud) throws RadioRAConnectionException {
@Override
public void write(String command) {
logger.debug("Writing to serial port: {}", command.toString());
SerialPort serialPort = this.serialPort;

try {
serialPort.getOutputStream().write(command.getBytes());
if (serialPort != null) {
OutputStream outputStream = serialPort.getOutputStream();
if (outputStream != null) {
outputStream.write(command.getBytes());
} else {
logger.debug("Cannot write to serial port. outputStream is null.");
}
} else {
logger.debug("Cannot write to serial port. serialPort is null.");
}
} catch (IOException e) {
logger.debug("An error occurred writing to serial port", e);
}
}

@Override
public void disconnect() {
serialPort.close();
SerialPort serialPort = this.serialPort;
if (serialPort != null) {
serialPort.close();
}
}

@Override
public void serialEvent(SerialPortEvent ev) {
switch (ev.getEventType()) {
case SerialPortEvent.DATA_AVAILABLE:
BufferedReader inputReader = this.inputReader;
try {
if (!inputReader.ready()) {
if (inputReader == null || !inputReader.ready()) {
logger.debug("Serial Data Available but input reader not ready");
return;
}
Expand All @@ -106,7 +126,12 @@ public void serialEvent(SerialPortEvent ev) {

if (feedback != null) {
logger.debug("Msg Parsed as {}", feedback.getClass().getName());
listener.handleRadioRAFeedback(feedback);
RadioRAFeedbackListener listener = this.listener;
if (listener != null) {
listener.handleRadioRAFeedback(feedback);
} else {
logger.debug("Cannot handle feedback message. Listener is null.");
}
}
logger.debug("Finished handling feedback");
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package org.openhab.binding.lutron.internal.radiora;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.lutron.internal.radiora.protocol.LEDMapFeedback;
import org.openhab.binding.lutron.internal.radiora.protocol.LocalZoneChangeFeedback;
import org.openhab.binding.lutron.internal.radiora.protocol.RadioRAFeedback;
Expand All @@ -25,11 +27,12 @@
* @author Jeff Lauterbach - Initial Contribution
*
*/
@NonNullByDefault
public class RS232MessageParser {

private Logger logger = LoggerFactory.getLogger(RS232MessageParser.class);
private final Logger logger = LoggerFactory.getLogger(RS232MessageParser.class);

public RadioRAFeedback parse(String msg) {
public @Nullable RadioRAFeedback parse(String msg) {
String prefix = parsePrefix(msg);

switch (prefix) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
*/
package org.openhab.binding.lutron.internal.radiora;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* Interface to the RadioRA Classic system
*
* @author Jeff Lauterbach - Initial Contribution
*
*/
@NonNullByDefault
public interface RadioRAConnection {

public void open(String portName, int baud) throws RadioRAConnectionException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
*/
package org.openhab.binding.lutron.internal.radiora;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* Thrown when an attempt to open a RadioRA Connection fails.
*
* @author Jeff Lauterbach - Initial Contribution
*
*/
@NonNullByDefault
public class RadioRAConnectionException extends Exception {

private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.openhab.binding.lutron.internal.radiora;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.lutron.internal.radiora.protocol.RadioRAFeedback;

/**
Expand All @@ -20,6 +21,7 @@
* @author Jeff Lauterbach - Initial Contribution
*
*/
@NonNullByDefault
public interface RadioRAFeedbackListener {

void handleRadioRAFeedback(RadioRAFeedback feedback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,20 @@
*
*/
public class DimmerConfig {
private int zoneNumber;
private BigDecimal fadeOutSec;
private BigDecimal fadeInSec;
public int zoneNumber;
public int system = 0;
public BigDecimal fadeOutSec;
public BigDecimal fadeInSec;

public int getZoneNumber() {
return zoneNumber;
}

public void setZoneNumber(int zoneNumber) {
this.zoneNumber = zoneNumber;
}

public BigDecimal getFadeOutSec() {
return fadeOutSec;
}

public void setFadeOutSec(BigDecimal fadeOutSec) {
this.fadeOutSec = fadeOutSec;
}

public BigDecimal getFadeInSec() {
return fadeInSec;
}

public void setFadeInSec(BigDecimal fadeInSec) {
this.fadeInSec = fadeInSec;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,21 @@
*/
package org.openhab.binding.lutron.internal.radiora.config;

import java.math.BigDecimal;
import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* Configuration class for PhantomButton thing type.
*
*
* @author Jeff Lauterbach - Initial Contribution
*
*/
@NonNullByDefault
public class PhantomButtonConfig {

private int buttonNumber;
private BigDecimal fadeSec;
public int buttonNumber;
public int system = 0;

public int getButtonNumber() {
return buttonNumber;
}

public void setButtonNumber(int buttonNumber) {
this.buttonNumber = buttonNumber;
}

public BigDecimal getFadeSec() {
return fadeSec;
}

public void setFadeSec(BigDecimal fadeSec) {
this.fadeSec = fadeSec;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,30 @@
*/
package org.openhab.binding.lutron.internal.radiora.config;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* Configuration class for RS232 thing type.
*
* @author Jeff Lauterbach - Initial Contribution
*
*/
@NonNullByDefault
public class RS232Config {

private String portName;
private int baud = 9600;
private int zoneMapQueryInterval = 60;
public String portName = "";
public int baud = 9600;
public int zoneMapQueryInterval = 60;

public String getPortName() {
return portName;
}

public void setPortName(String portName) {
this.portName = portName;
}

public int getBaud() {
return baud;
}

public void setBaud(int baud) {
this.baud = baud;
}

public int getZoneMapQueryInterval() {
return zoneMapQueryInterval;
}

public void setZoneMapQueryInterval(int zoneMapQueryInterval) {
this.zoneMapQueryInterval = zoneMapQueryInterval;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
*/
package org.openhab.binding.lutron.internal.radiora.config;

import org.eclipse.jdt.annotation.NonNullByDefault;

/**
* Configuration class for Switch thing type.
*
*
* @author Jeff Lauterbach - Initial Contribution
*
*/
@NonNullByDefault
public class SwitchConfig {

private int zoneNumber;
public int zoneNumber;
public int system = 0;

public int getZoneNumber() {
return zoneNumber;
}

public void setZoneNumber(int zoneNumber) {
this.zoneNumber = zoneNumber;
}
}
Loading

0 comments on commit 33b8388

Please sign in to comment.