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

[enocean] Add Ramping time to dimmer channel for central command #4585

Merged
merged 6 commits into from
Jan 27, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
<label>Dimmer</label>
<description>Dimmer</description>
<category>DimmableLight</category>
<config-description>
<parameter name="rampingTime" type="integer">
<label>Ramping time</label>
<description>A5-38-08: Ramping Time (in seconds), 0 = no ramping, 1..255 = seconds to 100%; D2-01-01: 0 = switch, 1-3 = timer 1-3, 4 = stop</description>
</parameter>
</config-description>
</channel-type>

<channel-type id="temperature">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Copyright (c) 2010-2019 by the respective copyright holders.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/

package org.openhab.binding.enocean.internal.config;

/**
*
* @author Dominik Krickl-Vorreiter - Initial contribution
*/
public class EnOceanChannelDimmerConfig {

public Integer rampingTime;

public EnOceanChannelDimmerConfig() {
rampingTime = 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.eclipse.smarthome.core.library.types.PercentType;
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.State;
import org.openhab.binding.enocean.internal.config.EnOceanChannelDimmerConfig;
import org.openhab.binding.enocean.internal.eep.Base._4BSMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;

Expand All @@ -40,26 +41,30 @@ public A5_38_08_Dimming(ERP1Message packet) {
protected void convertFromCommandImpl(String channelId, String channelTypeId, Command outputCommand,
State currentState, Configuration config) {

EnOceanChannelDimmerConfig c = config.as(EnOceanChannelDimmerConfig.class);
byte rampingTime = (c.rampingTime == null) ? Zero : c.rampingTime.byteValue();

if (outputCommand instanceof DecimalType) {
if (((DecimalType) outputCommand).equals(DecimalType.ZERO)) {
setData(CommandId, Zero, Zero, (byte) (TeachInBit | SwitchOff));
setData(CommandId, Zero, rampingTime, (byte) (TeachInBit | SwitchOff));
} else {
setData(CommandId, ((DecimalType) outputCommand).byteValue(), Zero, (byte) (TeachInBit | SwitchOn));
setData(CommandId, ((DecimalType) outputCommand).byteValue(), rampingTime,
(byte) (TeachInBit | SwitchOn));
}
} else if ((OnOffType) outputCommand == OnOffType.ON) {
setData(CommandId, Switch100Percent, Zero, (byte) (TeachInBit | SwitchOn));
setData(CommandId, Switch100Percent, rampingTime, (byte) (TeachInBit | SwitchOn));
} else {
setData(CommandId, Zero, Zero, (byte) (TeachInBit | SwitchOff));
setData(CommandId, Zero, rampingTime, (byte) (TeachInBit | SwitchOff));
}
}

@Override
public State convertToStateImpl(String channelId, String channelTypeId, State currentState, Configuration config) {

if (getDB_0() == (TeachInBit | SwitchOff)) {
return new PercentType(0);
} else {
return new PercentType(getDB_2Value());
if (getDB_0() == (TeachInBit | SwitchOff)) {
return new PercentType(0);
} else {
return new PercentType(getDB_2Value());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.smarthome.core.types.State;
import org.eclipse.smarthome.core.types.UnDefType;
import org.eclipse.smarthome.core.util.HexUtils;
import org.openhab.binding.enocean.internal.config.EnOceanChannelDimmerConfig;
import org.openhab.binding.enocean.internal.eep.Base._VLDMessage;
import org.openhab.binding.enocean.internal.messages.ERP1Message;

Expand Down Expand Up @@ -93,20 +94,25 @@ protected State getSwitchingData(byte channel) {
return UnDefType.UNDEF;
}

protected void setDimmingData(Command command, byte outputChannel) {
protected void setDimmingData(Command command, byte outputChannel, Configuration config) {
byte outputValue;

if (command instanceof DecimalType) {
if (((DecimalType) command).equals(DecimalType.ZERO)) {
setData(CMD_ACTUATOR_SET_STATUS, outputChannel, STATUS_SWITCHING_OFF);
outputValue = STATUS_SWITCHING_OFF;
} else {
setData(CMD_ACTUATOR_SET_STATUS, outputChannel, ((DecimalType) command).byteValue());
outputValue = ((DecimalType) command).byteValue();
}
} else if ((OnOffType) command == OnOffType.ON) {
setData(CMD_ACTUATOR_SET_STATUS, outputChannel, STATUS_DIMMING_100);
outputValue = STATUS_DIMMING_100;
} else {
setData(CMD_ACTUATOR_SET_STATUS, outputChannel, STATUS_SWITCHING_OFF);
outputValue = STATUS_SWITCHING_OFF;
}

setData(CMD_ACTUATOR_SET_STATUS, outputChannel);
EnOceanChannelDimmerConfig c = config.as(EnOceanChannelDimmerConfig.class);
byte rampingTime = (c.rampingTime == null) ? Zero : c.rampingTime.byteValue();

setData(CMD_ACTUATOR_SET_STATUS, (byte) ((rampingTime << 5) | outputChannel), outputValue);
}

protected State getDimmingData() {
Expand Down Expand Up @@ -207,7 +213,7 @@ protected void convertFromCommandImpl(String channelId, String channelTypeId, Co
if (command == RefreshType.REFRESH) {
setSwitchingQueryData(AllChannels_Mask);
} else {
setDimmingData(command, AllChannels_Mask);
setDimmingData(command, AllChannels_Mask, config);
}
} else if (channelId.equals(CHANNEL_INSTANTPOWER) && command == RefreshType.REFRESH) {
setPowerMeasurementQueryData(AllChannels_Mask);
Expand Down