Skip to content

Commit

Permalink
[deconz] add support for warning device (openhab#8096)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan N. Klug <[email protected]>
  • Loading branch information
J-N-K authored and andrewfg committed Aug 31, 2020
1 parent bc29670 commit f98a57e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions bundles/org.openhab.binding.deconz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Additionally lights, window coverings (blinds) and thermostats are supported:
| Extended Color Light (w/temperature) | Extended color light | `extendedcolorlight` |
| Blind / Window Covering | Window covering device | `windowcovering` |
| Thermostat | ZHAThermostat | `thermostat` |
| Warning Device (Siren) | Warning device | `warningdevice` |

## Discovery

Expand Down Expand Up @@ -154,6 +155,7 @@ Other devices support
| valve | Number:Dimensionless | R | Valve position in % | `thermostat` |
| mode | String | R/W | Mode: "auto", "heat" and "off" | `thermostat` |
| offset | Number | R | Temperature offset for sensor | `thermostat` |
| alert | Switch | R/W | Turn alerts on/off | `warningdevice` |

### Trigger Channels

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class BindingConstants {
public static final ThingTypeUID THING_TYPE_EXTENDED_COLOR_LIGHT = new ThingTypeUID(BINDING_ID,
"extendedcolorlight");
public static final ThingTypeUID THING_TYPE_WINDOW_COVERING = new ThingTypeUID(BINDING_ID, "windowcovering");
public static final ThingTypeUID THING_TYPE_WARNING_DEVICE = new ThingTypeUID(BINDING_ID, "warningdevice");

// List of all Channel ids
public static final String CHANNEL_PRESENCE = "presence";
Expand Down Expand Up @@ -101,6 +102,7 @@ public class BindingConstants {
public static final String CHANNEL_COLOR_TEMPERATURE = "color_temperature";
public static final String CHANNEL_COLOR = "color";
public static final String CHANNEL_POSITION = "position";
public static final String CHANNEL_ALERT = "alert";

// Thing configuration
public static final String CONFIG_HOST = "host";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ private void addLight(String lightID, LightMessage light) {
case WINDOW_COVERING_DEVICE:
thingTypeUID = THING_TYPE_WINDOW_COVERING;
break;
case WARNING_DEVICE:
thingTypeUID = THING_TYPE_WARNING_DEVICE;
break;
case CONFIGURATION_TOOL:
// ignore configuration tool device
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
public class LightThingHandler extends DeconzBaseThingHandler<LightMessage> {
public static final Set<ThingTypeUID> SUPPORTED_THING_TYPE_UIDS = Stream
.of(THING_TYPE_COLOR_TEMPERATURE_LIGHT, THING_TYPE_DIMMABLE_LIGHT, THING_TYPE_COLOR_LIGHT,
THING_TYPE_EXTENDED_COLOR_LIGHT, THING_TYPE_ONOFF_LIGHT, THING_TYPE_WINDOW_COVERING)
.collect(Collectors.toSet());
THING_TYPE_EXTENDED_COLOR_LIGHT, THING_TYPE_ONOFF_LIGHT, THING_TYPE_WINDOW_COVERING,
THING_TYPE_WARNING_DEVICE).collect(Collectors.toSet());

private static final double HUE_FACTOR = 65535 / 360.0;
private static final double BRIGHTNESS_FACTOR = 2.54;
Expand Down Expand Up @@ -157,6 +157,12 @@ public void handleCommand(ChannelUID channelUID, Command command) {
Integer currentBri = lightStateCache.bri;

switch (channelUID.getId()) {
case CHANNEL_ALERT:
if (command instanceof OnOffType) {
newLightState.alert = command == OnOffType.ON ? "alert" : "none";
} else {
return;
}
case CHANNEL_SWITCH:
if (command instanceof OnOffType) {
newLightState.on = (command == OnOffType.ON);
Expand Down Expand Up @@ -314,6 +320,9 @@ private void valueUpdated(String channelId, LightState newState) {
Boolean on = newState.on;

switch (channelId) {
case CHANNEL_ALERT:
updateState(channelId, "alert".equals(newState.alert) ? OnOffType.ON : OnOffType.OFF);
break;
case CHANNEL_SWITCH:
if (on != null) {
updateState(channelId, OnOffType.from(on));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public enum LightType {
DIMMABLE_PLUGIN_UNIT("Dimmable plug-in unit"),
WINDOW_COVERING_DEVICE("Window covering device"),
CONFIGURATION_TOOL("Configuration tool"),
WARNING_DEVICE("Warning device"),
UNKNOWN("");

private static final Map<String, LightType> MAPPING = Arrays.stream(LightType.values())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0"
xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd">

<thing-type id="warningdevice">
<supported-bridge-type-refs>
<bridge-type-ref id="deconz"/>
</supported-bridge-type-refs>
<label>Warning Device</label>
<description>A warning device</description>
<channels>
<channel id="alert" typeId="alert"></channel>
</channels>
</thing-type>

<thing-type id="windowcovering">
<supported-bridge-type-refs>
<bridge-type-ref id="deconz"/>
Expand Down Expand Up @@ -124,5 +135,9 @@
<state pattern="%d" min="15" max="100000" step="100"/>
</channel-type>

<channel-type id="alert">
<item-type>Switch</item-type>
<label>Alert</label>
</channel-type>

</thing:thing-descriptions>

0 comments on commit f98a57e

Please sign in to comment.