Skip to content

Commit

Permalink
Remove redundant brightness channel
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Laursen <[email protected]>
  • Loading branch information
jlaur committed Nov 11, 2023
1 parent 1b466fb commit 8369788
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 37 deletions.
15 changes: 8 additions & 7 deletions bundles/org.openhab.binding.hdpowerview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,13 @@ On Generation 3 gateways the signal strength is displayed in dBm (deciBel-milliW

### Channels for Repeaters (Thing type `repeater`)<sup>[1/2]</sup>

| Channel | Item Type | Description |
|-----------------|-----------|---------------------------------------------------------------------------------------------|
| color | Color | Controls the color of the LED ring. A switch item can be linked: ON = white, OFF = turn off |
| brightness | Dimmer | Controls the brightness of the LED ring. |
| identify | String | Flash repeater to identify. Valid values are: `IDENTIFY` |
| blinkingEnabled | Switch | Blink during commands. |
| Channel | Item Type | Description |
|-----------------|-----------|----------------------------------------------------------|
| color | Color | Controls the color of the LED ring. |
| color | Dimmer | Controls the brightness of the LED ring. |
| color | Switch | Switches the LED ring on or off. |
| identify | String | Flash repeater to identify. Valid values are: `IDENTIFY` |
| blinkingEnabled | Switch | Blink during commands. |

### Roller Shutter Up/Down Position vs. Open/Close State

Expand Down Expand Up @@ -292,7 +293,7 @@ Repeater items<sup>[1/2]</sup>:

```java
Color Bedroom_Repeater_Color "Bedroom Repeater Color" {channel="hdpowerview:repeater:home:r16384:color"}
Dimmer Bedroom_Repeater_Brightness "Bedroom Repeater Brightness" {channel="hdpowerview:repeater:home:r16384:brightness"}
Dimmer Bedroom_Repeater_Brightness "Bedroom Repeater Brightness" {channel="hdpowerview:repeater:home:r16384:color"}
String Bedroom_Repeater_Identify "Bedroom Repeater Identify" {channel="hdpowerview:repeater:home:r16384:identify"}
Switch Bedroom_Repeater_BlinkingEnabled "Bedroom Repeater Blinking Enabled [%s]" {channel="hdpowerview:repeater:home:r16384:blinkingEnabled"}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public class HDPowerViewBindingConstants {
public static final String CHANNEL_SHADE_REPEATER_RSSI = "repeaterRssi";

public static final String CHANNEL_REPEATER_COLOR = "color";
public static final String CHANNEL_REPEATER_BRIGHTNESS = "brightness";
public static final String CHANNEL_REPEATER_IDENTIFY = "identify";
public static final String CHANNEL_REPEATER_BLINKING_ENABLED = "blinkingEnabled";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@ public Color(int brightness, java.awt.Color color) {
this(brightness, color.getRed(), color.getGreen(), color.getBlue());
}

public Color(int brightness, Color color) {
this(brightness, color.red, color.green, color.blue);
}

public Color(int brightness, int red, int green, int blue) {
this.brightness = brightness;
this.red = red;
this.green = green;
this.blue = blue;
}

public boolean isBlack() {
return red == 0 && green == 0 && blue == 0;
}

@Override
public String toString() {
return String.format("%d.%d.%d/%d%%", red, green, blue, brightness);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.openhab.core.thing.ThingStatus;
import org.openhab.core.thing.ThingStatusDetail;
import org.openhab.core.types.Command;
import org.openhab.core.types.RefreshType;
import org.openhab.core.types.UnDefType;
import org.openhab.core.util.ColorUtil;
import org.slf4j.Logger;
Expand Down Expand Up @@ -94,6 +95,10 @@ public void handleCommand(ChannelUID channelUID, Command command) {
logger.warn("Missing bridge handler");
return;
}
if (command == RefreshType.REFRESH) {
scheduleRefreshJob();
return;
}
HDPowerViewWebTargets webTargets = bridge.getWebTargets();
try {
RepeaterData repeaterData;
Expand All @@ -107,23 +112,38 @@ public void handleCommand(ChannelUID channelUID, Command command) {
repeaterData = webTargets.setRepeaterColor(repeaterId, color);
scheduler.submit(() -> updatePropertyAndStates(repeaterData));
}
} else if (command instanceof OnOffType) {
} else if (command instanceof PercentType brightnessCommand) {
Color currentColor = webTargets.getRepeater(repeaterId).color;
if (currentColor != null) {
var color = command == OnOffType.ON
? new Color(currentColor.brightness, java.awt.Color.WHITE)
: new Color(currentColor.brightness, java.awt.Color.BLACK);
Color color;
if (currentColor.isBlack()) {
// Light is off when RGB black, so set to white as otherwise brightness
// would have no effect.
color = new Color(brightnessCommand.intValue(), java.awt.Color.WHITE);
} else {
color = new Color(brightnessCommand.intValue(), currentColor);
}
repeaterData = webTargets.setRepeaterColor(repeaterId, color);
scheduler.submit(() -> updatePropertyAndStates(repeaterData));
}
}
break;
case CHANNEL_REPEATER_BRIGHTNESS:
if (command instanceof PercentType brightnessCommand) {
} else if (command instanceof OnOffType) {
Color currentColor = webTargets.getRepeater(repeaterId).color;
if (currentColor != null) {
var color = new Color(brightnessCommand.intValue(), currentColor.red, currentColor.green,
currentColor.blue);
// Light is turned off either by RGB black or zero brightness.
// Restore what we can.
Color color;
if (command == OnOffType.ON) {
int brightness = currentColor.brightness > 0 ? currentColor.brightness : 100;
if (currentColor.isBlack()) {
// Light is off when RGB black, so set to white as otherwise brightness
// would have no effect.
color = new Color(brightness, java.awt.Color.WHITE);
} else {
color = new Color(brightness, currentColor);
}
} else {
color = new Color(0, currentColor);
}
repeaterData = webTargets.setRepeaterColor(repeaterId, color);
scheduler.submit(() -> updatePropertyAndStates(repeaterData));
}
Expand Down Expand Up @@ -228,10 +248,17 @@ private void updatePropertyAndStates(RepeaterData repeaterData) {
Color color = repeaterData.color;
if (color != null) {
logger.debug("Repeater color data received: {}", color.toString());
updateState(CHANNEL_REPEATER_COLOR, HSBType.fromRGB(color.red, color.green, color.red));
updateState(CHANNEL_REPEATER_BRIGHTNESS, new PercentType(color.brightness));
HSBType hsb;
if (color.isBlack()) {
// Light is off when RGB black, so discard brightness as otherwise it would appear on.
hsb = HSBType.BLACK;
} else {
hsb = HSBType.fromRGB(color.red, color.green, color.red);
hsb = new HSBType(hsb.getHue(), hsb.getSaturation(), new PercentType(color.brightness));
}
updateState(CHANNEL_REPEATER_COLOR, hsb);
}

updateState(CHANNEL_REPEATER_BLINKING_ENABLED, repeaterData.blinkEnabled ? OnOffType.ON : OnOffType.OFF);
updateState(CHANNEL_REPEATER_BLINKING_ENABLED, OnOffType.from(repeaterData.blinkEnabled));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@

<channels>
<channel id="color" typeId="system.color">
<description>Controls the color of the LED ring</description>
</channel>
<channel id="brightness" typeId="system.brightness">
<description>Controls the brightness of the LED ring</description>
<description>Controls the color and brightness of the LED ring</description>
</channel>
<channel id="identify" typeId="repeater-identify"/>
<channel id="blinkingEnabled" typeId="repeater-blinking-enabled"/>
</channels>

<properties>
<property name="thingTypeVersion">1</property>
<property name="vendor">Hunter Douglas (Luxaflex)</property>
<property name="modelId">PowerView Repeater</property>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,9 @@
xmlns:update="https://openhab.org/schemas/update-description/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/update-description/v1.0.0 https://openhab.org/schemas/update-description-1.0.0.xsd">

<thing-type uid="powerview:shade">
<thing-type uid="hdpowerview:repeater">
<instruction-set targetVersion="1">
<update-channel id="position">
<type>powerview:shade-position</type>
</update-channel>
<update-channel id="secondary">
<type>powerview:shade-position</type>
<label>Secondary Position</label>
<description>The secondary vertical position (on top-down/bottom-up shades)</description>
</update-channel>
<update-channel id="vane">
<type>powerview:shade-vane</type>
</update-channel>
<remove-channel id="brightness"/>
</instruction-set>
</thing-type>

Expand Down

0 comments on commit 8369788

Please sign in to comment.