Skip to content

Commit

Permalink
Worked on repairing support for RFXThermostat3 messages
Browse files Browse the repository at this point in the history
Signed-off-by: Martin van Wingerden <martin@martinvw.nl>
  • Loading branch information
martinvw committed Jun 26, 2019
1 parent f3219ac commit 070ca83
Show file tree
Hide file tree
Showing 8 changed files with 381 additions and 26 deletions.
16 changes: 12 additions & 4 deletions bundles/org.openhab.binding.rfxcom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,12 @@ This binding currently supports following channel types:
| chimesound | Number | Id of the chime sound |
| command | Switch | Command channel. |
| commandId | String | Id of the command. |
| commandString | String | Id of the command. |
| contact | Contact | Contact channel. |
| datetime | DateTime | DateTime channel. |
| dimminglevel | Dimmer | Dimming level channel. |
| forecast | String | Weather forecast from device: NO\_INFO\_AVAILABLE/SUNNY/PARTLY\_CLOUDY/CLOUDY/RAIN |
| tempcontrol | Dimmer | Global control for temperature also setting ON, OFF, UP, DOWN |
| humidity | Number | Relative humidity level in percentages. |
| humiditystatus | String | Current humidity status: NORMAL/COMFORT/DRY/WET |
| instantamp | Number | Instant current in Amperes. |
Expand Down Expand Up @@ -964,10 +966,13 @@ A Thermostat3 device.

#### Channels

| Name | Channel Type | Item Type | Remarks |
|-------------|-------------------------------------|-----------|----------|
| command | [command](#channels) | Switch | |
| signalLevel | [system.signal-strength](#channels) | Number | |
| Name | Channel Type | Item Type | Remarks |
|---------------|-------------------------------------|-----------|----------|
| command | [command](#channels) | Switch | |
| command2nd | [command](#channels) | Switch | |
| control | [tempcontrol](#channels) | Dimmer | |
| commandString | [commandString](#channels) | String | |
| signalLevel | [system.signal-strength](#channels) | Number | |

#### Configuration Options

Expand All @@ -982,6 +987,9 @@ A Thermostat3 device.
* MERTIK\_\_G6R\_H4TD\_\_G6R\_H4T16 - Mertik (G6R H4TD or G6R H4T16)
* MERTIK\_\_G6R\_H4S\_TRANSMIT\_ONLY - Mertik (G6R H4S \- transmit only)

#### Examples



### undecoded - RFXCOM Undecoded RF Messages

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ public class RFXComBindingConstants {
public static final String CHANNEL_VENETIAN_BLIND = "venetianBlind";
public static final String CHANNEL_SUN_WIND_DETECTOR = "sunWindDetector";
public static final String CHANNEL_COMMAND = "command";
public static final String CHANNEL_COMMAND_SECOND = "command2nd";
public static final String CHANNEL_CONTROL = "control";
public static final String CHANNEL_PROGRAM = "program";
public static final String CHANNEL_COMMAND_ID = "commandId";
public static final String CHANNEL_COMMAND_STRING = "commandString";
public static final String CHANNEL_MOOD = "mood";
public static final String CHANNEL_SIGNAL_LEVEL = "signalLevel";
public static final String CHANNEL_DIMMING_LEVEL = "dimmingLevel";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,17 @@ public void onDeviceMessageReceived(ThingUID bridge, RFXComDeviceMessage message
updateStatus(ThingStatus.ONLINE);

for (Channel channel : getThing().getChannels()) {
String channelId = channel.getUID().getId();
ChannelUID uid = channel.getUID();
String channelId = uid.getId();

try {
if (channelId.equals(CHANNEL_LOW_BATTERY)) {
updateState(channelId, isLowBattery(message.convertToState(CHANNEL_BATTERY_LEVEL)));
updateState(uid, isLowBattery(message.convertToState(CHANNEL_BATTERY_LEVEL)));
} else {
updateState(channelId, message.convertToState(channelId));
State state = message.convertToState(channelId);
if (state != null) {
updateState(uid, state);
}
}
} catch (RFXComException e) {
logger.trace("{} does not handle {}", channelId, message);
Expand All @@ -174,4 +178,4 @@ private State isLowBattery(State batteryLevel) {
return OnOffType.OFF;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public byte toByte() {
/**
* Note: for the lighting5 commands, some command are only supported for certain sub types and
* command-bytes might even have a different meaning for another sub type.
* <p>
*
* If no sub types are specified for a command, its supported by all sub types.
* An example is the command OFF which is represented by the byte 0x00 for all subtypes.
* <p>
*
* Otherwise the list of sub types after the command-bytes indicates the sub types
* which support this command with this byte.
* Example byte value 0x03 means GROUP_ON for IT and some others while it means MOOD1 for LIGHTWAVERF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,25 @@
*/
package org.openhab.binding.rfxcom.internal.messages;

import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.CHANNEL_COMMAND;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import static org.openhab.binding.rfxcom.internal.messages.RFXComThermostat3Message.SubType.*;

import java.util.Arrays;
import java.util.List;

import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.library.types.OpenClosedType;
import org.eclipse.smarthome.core.library.types.StopMoveType;
import org.eclipse.smarthome.core.library.types.StringType;
import org.eclipse.smarthome.core.library.types.UpDownType;
import org.eclipse.smarthome.core.types.State;
import org.eclipse.smarthome.core.types.Type;
import org.eclipse.smarthome.core.types.UnDefType;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;

import java.util.Arrays;
import java.util.List;

import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import static org.openhab.binding.rfxcom.internal.messages.RFXComThermostat3Message.SubType.MERTIK__G6R_H4T1;
import static org.openhab.binding.rfxcom.internal.messages.RFXComThermostat3Message.SubType.MERTIK__G6R_H4TB__G6R_H4T__G6R_H4T21_Z22;

/**
* RFXCOM data class for thermostat3message.
*
Expand Down Expand Up @@ -159,19 +162,51 @@ public State convertToState(String channelId) throws RFXComUnsupportedChannelExc
switch (channelId) {
case CHANNEL_COMMAND:
switch (command) {
case RUN_DOWN:
case OFF:
case SECOND_OFF:
return OnOffType.OFF;
case ON:
case RUN_UP:
case UP:
return OnOffType.ON;
case SECOND_ON:
case SECOND_OFF:
return null;
default:
return UnDefType.UNDEF;

}
case CHANNEL_CONTROL:
switch (command) {
case ON:
return OnOffType.ON;
case UP:
case RUN_UP:
return UpDownType.UP;
case OFF:
return OnOffType.OFF;
case DOWN:
case RUN_DOWN:
return UpDownType.DOWN;
case SECOND_ON:
case SECOND_OFF:
case STOP:
return null;
default:
throw new RFXComUnsupportedChannelException("Can't convert " + command + " for " + channelId);
}
case CHANNEL_COMMAND_SECOND:
switch (command) {
case SECOND_OFF:
return OnOffType.OFF;
case SECOND_ON:
return OnOffType.ON;
default:
return null;
}
case CHANNEL_COMMAND_STRING:
return command == null ? UnDefType.UNDEF : StringType.valueOf(command.toString());

default:
return super.convertToState(channelId);
}
Expand All @@ -181,17 +216,37 @@ public State convertToState(String channelId) throws RFXComUnsupportedChannelExc
public void convertFromState(String channelId, Type type) throws RFXComUnsupportedChannelException {
switch (channelId) {
case CHANNEL_COMMAND:
if (type instanceof OnOffType) {
command = (type == OnOffType.ON ? Commands.ON : Commands.OFF);
} else {
throw new RFXComUnsupportedChannelException("Channel " + channelId + " does not accept " + type);
}
break;

case CHANNEL_COMMAND_SECOND:
if (type instanceof OnOffType) {
command = (type == OnOffType.ON ? Commands.SECOND_ON : Commands.SECOND_OFF);
} else {
throw new RFXComUnsupportedChannelException("Channel " + channelId + " does not accept " + type);
}
break;

case CHANNEL_CONTROL:
if (type instanceof OnOffType) {
command = (type == OnOffType.ON ? Commands.ON : Commands.OFF);
} else if (type instanceof UpDownType) {
command = (type == UpDownType.UP ? Commands.UP : Commands.DOWN);
} else if (type instanceof OpenClosedType) {
command = (type == OpenClosedType.CLOSED ? Commands.ON : Commands.OFF);
} else if (type == StopMoveType.STOP) {
command = Commands.STOP;
} else {
throw new RFXComUnsupportedChannelException("Channel " + channelId + " does not accept " + type);
}
break;

case CHANNEL_COMMAND_STRING:
command = Commands.valueOf(type.toString().toUpperCase());
break;

default:
throw new RFXComUnsupportedChannelException("Channel " + channelId + " is not relevant here");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
<state min="0" max="255" step="1" pattern="%d" readOnly="false"></state>
</channel-type>

<channel-type id="commandString">
<item-type>String</item-type>
<label>Command String</label>
<description>Command channel, Name of the channel</description>
<state min="0" max="255" step="1" pattern="%d" readOnly="false"></state>
</channel-type>

<channel-type id="contact">
<item-type>Contact</item-type>
<label>Contact</label>
Expand Down Expand Up @@ -70,6 +77,12 @@
<state min="0" max="255" step="1" pattern="%d °C" readOnly="false"></state>
</channel-type>

<channel-type id="tempcontrol">
<item-type>Dimmer</item-type>
<label>Global Temperature Control</label>
<description>Requested temperature setting, ON, OFF, UP, DOWN</description>
</channel-type>

<channel-type id="motion">
<item-type>Switch</item-type>
<label>Motion</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

<channels>
<channel id="command" typeId="command" />
<channel id="command2nd" typeId="command" />
<channel id="control" typeId="tempcontrol" />
<channel id="commandString" typeId="commandString" />
<channel id="signalLevel" typeId="system.signal-strength" />
</channels>

Expand Down
Loading

0 comments on commit 070ca83

Please sign in to comment.