Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lutron] Added a feature to override dimmer Thing configuration fade in/out times #8133

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bundles/org.openhab.binding.lutron/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,8 @@ The following is a summary of channels for all RadioRA 2 binding things:
| Thing | Channel | Item Type | Description |
|---------------------|-------------------|---------------|--------------------------------------------- |
| dimmer | lightlevel | Dimmer | Increase/decrease the light level |
| dimmer | enablefadetime | Switch | Override default fade in/out time |
| dimmer | fadetime | Number | Fade time when changing light level |
| switch | switchstatus | Switch | On/off status of the switch |
| occupancysensor | occupancystatus | Switch | Occupancy status |
| cco | switchstatus | Switch | On/off status of the CCO |
Expand All @@ -556,6 +558,8 @@ Appropriate channels will be created automatically by the keypad, ttkeypad, intl
| Thing | Channel | Native Type | Accepts |
|-----------|---------------|--------------|-------------------------------------------------------|
|dimmer |lightlevel |PercentType |OnOffType, PercentType |
|dimmer |enablefadetime |OnOffType |OnOffType |
|dimmer |fadetime |DecimalType |DecimalType |
|switch |switchstatus |OnOffType |OnOffType |
|occ. sensor|occupancystatus|OnOffType |(*readonly*) |
|cco |switchstatus |OnOffType |OnOffType, RefreshType |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class LutronBindingConstants {
public static final String CHANNEL_STEP = "step";
public static final String CHANNEL_BLINDLIFTLEVEL = "blindliftlevel";
public static final String CHANNEL_BLINDTILTLEVEL = "blindtiltlevel";
public static final String CHANNEL_ENABLEFADETIME = "enablefadetime";
public static final String CHANNEL_FADETIME = "fadetime";

// Bridge config properties (used by discovery service)
public static final String HOST = "ipAddress";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
*/
package org.openhab.binding.lutron.internal.handler;

import static org.openhab.binding.lutron.internal.LutronBindingConstants.CHANNEL_LIGHTLEVEL;

import java.math.BigDecimal;

import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.PercentType;
import org.eclipse.smarthome.core.thing.Bridge;
Expand All @@ -29,6 +28,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.openhab.binding.lutron.internal.LutronBindingConstants.*;

/**
* Handler responsible for communicating with a light dimmer.
*
Expand All @@ -41,6 +42,8 @@ public class DimmerHandler extends LutronHandler {
private final Logger logger = LoggerFactory.getLogger(DimmerHandler.class);

private DimmerConfig config;
private Boolean overrideDefaultFadeTime = false;
private BigDecimal customFadeTime = new BigDecimal(0);

public DimmerHandler(Thing thing) {
super(thing);
Expand Down Expand Up @@ -95,11 +98,19 @@ public void handleCommand(ChannelUID channelUID, Command command) {
if (command instanceof Number) {
int level = ((Number) command).intValue();

output(ACTION_ZONELEVEL, level, 0.25);
output(ACTION_ZONELEVEL, level, getFadeTime(new BigDecimal(.25)));
} else if (command.equals(OnOffType.ON)) {
output(ACTION_ZONELEVEL, 100, this.config.fadeInTime);
output(ACTION_ZONELEVEL, 100, getFadeTime(this.config.fadeInTime));
} else if (command.equals(OnOffType.OFF)) {
output(ACTION_ZONELEVEL, 0, this.config.fadeOutTime);
output(ACTION_ZONELEVEL, 0, getFadeTime(this.config.fadeOutTime));
}
} else if (channelUID.getId().equals(CHANNEL_ENABLEFADETIME)) {
if (command instanceof OnOffType) {
this.overrideDefaultFadeTime = command.equals(OnOffType.ON);
}
} else if (channelUID.getId().equals(CHANNEL_FADETIME)) {
if (command instanceof DecimalType) {
customFadeTime= ((DecimalType) command).toBigDecimal();
}
}
}
Expand All @@ -114,5 +125,14 @@ public void handleUpdate(LutronCommandType type, String... parameters) {
}
updateState(CHANNEL_LIGHTLEVEL, new PercentType(level));
}
updateState(CHANNEL_ENABLEFADETIME, overrideDefaultFadeTime ? OnOffType.ON : OnOffType.OFF);
updateState(CHANNEL_FADETIME, new DecimalType(customFadeTime));
}

private BigDecimal getFadeTime(BigDecimal defaultFadeTime) {
if (overrideDefaultFadeTime && customFadeTime != null) {
return customFadeTime;
}
return defaultFadeTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@

<channels>
<channel id="lightlevel" typeId="lightDimmer"/>
<channel id="enablefadetime" typeId="enableFadeTime"/>
<channel id="fadetime" typeId="fadeTime"/>
</channels>

<representation-property>integrationId</representation-property>
Expand Down Expand Up @@ -1100,6 +1102,20 @@
<state min="0" max="100" pattern="%d %%"/>
</channel-type>

<channel-type id="enableFadeTime">
<item-type>Switch</item-type>
<label>Enable Fade Time</label>
<description>Allows config fade in/out time to be overridden</description>
</channel-type>

<channel-type id="fadeTime">
<item-type>Number</item-type>
<label>Fade In/Out Time</label>
<description>Sets time in seconds to increase/decrease light level</description>
<category>Number</category>
<state min="0"/>
</channel-type>

<channel-type id="shadeControl">
<item-type>Rollershutter</item-type>
<label>Shade Level</label>
Expand Down