Skip to content

Commit

Permalink
[sbus] some comments and optimized calls
Browse files Browse the repository at this point in the history
Signed-off-by: Ciprian Pascu <[email protected]>
  • Loading branch information
Ciprian Pascu committed Jan 12, 2025
1 parent 20fc495 commit de08032
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bundles/org.openhab.binding.sbus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<dependency>
<groupId>ro.ciprianpascu</groupId>
<artifactId>j2sbus</artifactId>
<version>1.5.4</version>
<version>1.5.5</version>
<scope>compile</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
&& command instanceof HSBType hsbCommand) {
// Handle color command
int[] rgbw = hsbToRgbw(hsbCommand);
adapter.writeRgbw(config.subnetId, config.id, channelConfig.channelNumber, rgbw[0], rgbw[1],
rgbw[2], rgbw[3]);
adapter.writeRgbw(config.subnetId, config.id, channelConfig.channelNumber, rgbw);
updateState(channelUID, hsbCommand);
} else if (BindingConstants.CHANNEL_TYPE_SWITCH.equals(channelTypeId)
&& command instanceof OnOffType onOffCommand) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ public interface SbusService {
*
* @param subnetId the subnet ID of the device
* @param id the device ID
* @param temperatureUnit The unit of measurement (e.g., 0 for Fahrenheit, 1 for Celsius)
* @return array of temperature values in Celsius
* @throws Exception if reading fails
*/
float[] readTemperatures(int subnetId, int id) throws Exception;
float[] readTemperatures(int subnetId, int id, int temperatureUnit) throws Exception;

/**
* Reads RGBW values from a device channel.
Expand Down Expand Up @@ -59,13 +60,10 @@ public interface SbusService {
* @param subnetId the subnet ID of the device
* @param id the device ID
* @param channelNumber the channel number to write to
* @param r red value (0-255)
* @param g green value (0-255)
* @param b blue value (0-255)
* @param w white value (0-255)
* @param color An array of 4 integers representing RGBW values (0-255 each)
* @throws Exception if writing fails
*/
void writeRgbw(int subnetId, int id, int channelNumber, int r, int g, int b, int w) throws Exception;
void writeRgbw(int subnetId, int id, int channelNumber, int[] color) throws Exception;

/**
* Writes a value to a single channel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected void pollDevice() {
SbusDeviceConfig config = getConfigAs(SbusDeviceConfig.class);

// Read temperatures in Celsius from device
float[] temperatures = adapter.readTemperatures(config.subnetId, config.id);
float[] temperatures = adapter.readTemperatures(config.subnetId, config.id, 1);

// Iterate over all channels and update their states with corresponding temperatures
for (Channel channel : getThing().getChannels()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public SbusServiceImpl() {
* @param port the port number to use
* @throws Exception if initialization fails
*/
@Override
public void initialize(String host, int port) throws Exception {
this.adapter = new SbusAdapter(host, port);
}
Expand All @@ -53,12 +54,12 @@ public void deactivate() {
}

@Override
public float[] readTemperatures(int subnetId, int id) throws Exception {
public float[] readTemperatures(int subnetId, int id, int temperatureUnit) throws Exception {
final SbusAdapter adapter = this.adapter;
if (adapter == null) {
throw new IllegalStateException("SbusAdapter not initialized");
}
return adapter.readTemperatures(subnetId, id);
return adapter.readTemperatures(subnetId, id, temperatureUnit);
}

@Override
Expand All @@ -80,12 +81,12 @@ public int[] readStatusChannels(int subnetId, int id) throws Exception {
}

@Override
public void writeRgbw(int subnetId, int id, int channelNumber, int r, int g, int b, int w) throws Exception {
public void writeRgbw(int subnetId, int id, int channelNumber, int[] color) throws Exception {
final SbusAdapter adapter = this.adapter;
if (adapter == null) {
throw new IllegalStateException("SbusAdapter not initialized");
}
adapter.writeRgbw(subnetId, id, channelNumber, r, g, b, w);
adapter.writeRgbw(subnetId, id, channelNumber, color);
}

@Override
Expand Down

0 comments on commit de08032

Please sign in to comment.