[rfxcom] Add ability to properly receive configured command ids, deprecated hard-coded guesses. (#10940)

Currently, when a message is received the command will be determined only from the hard-coded set of ON/OFF commands, which means if I configure
a thing and attach it to a switch there is no guarantee that it will respond as expected to receive commands. This PR changes the message factory
to require either bytes (from the RFXcom device) or all the details required to make a transmissable message, including the confguration of the
associated Thing. At the moment, this is only used by lighting4 and raw types, but I expect it will be useful for others in the future.

The hard-coded ON/OFF commands in lighting4 are based on experimentation with different devices, and are not at all consistent. This PR deprecates the
use of those so that in a future release, Lighting4 devices will only work when configured with the correct command ids up front. This will resolve
inconsistent behaviour where devices that have been discovered may work correctly, work only for ON or OFF but not both, have ON and OFF the wrong
way around, turn ON one physical device and OFF another, or any combination of those possibilities.

Signed-off-by: James Hewitt <james.hewitt@uk.ibm.com>
This commit is contained in:
James Hewitt
2021-07-18 20:37:44 +01:00
committed by GitHub
parent fcc23f0ab3
commit 487dc0e49f
72 changed files with 915 additions and 590 deletions

View File

@@ -21,7 +21,11 @@ public class RFXComLighting4DeviceConfiguration extends RFXComGenericDeviceConfi
public static final String PULSE_LABEL = "pulse";
public static final String ON_COMMAND_ID_LABEL = "onCommandId";
public static final String OFF_COMMAND_ID_LABEL = "offCommandId";
public static final String OPEN_COMMAND_ID_LABEL = "openCommandId";
public static final String CLOSED_COMMAND_ID_LABEL = "closedCommandId";
public Integer pulse;
public Integer onCommandId;
public Integer offCommandId;
public Integer openCommandId;
public Integer closedCommandId;
}

View File

@@ -102,8 +102,10 @@ public class RFXComBridgeHandler extends BaseBridgeHandler {
RFXComBaseMessage msg = queue.peek();
try {
logger.debug("Transmitting message '{}'", msg);
byte[] data = msg.decodeMessage();
if (logger.isDebugEnabled()) {
logger.debug("Transmitting bytes '{}' for message '{}'", HexUtils.bytesToHex(data), msg);
}
connector.sendMessage(data);
break;
} catch (RFXComException rfxe) {

View File

@@ -95,10 +95,7 @@ public class RFXComHandler extends BaseThingHandler implements DeviceMessageList
PacketType packetType = RFXComMessageFactoryImpl
.convertPacketType(getThing().getThingTypeUID().getId().toUpperCase());
RFXComMessage msg = messageFactory.createMessage(packetType);
msg.setConfig(config);
msg.convertFromState(channelUID.getId(), command);
RFXComMessage msg = messageFactory.createMessage(packetType, config, channelUID, command);
bridgeHandler.sendMessage(msg);
} catch (RFXComMessageNotImplementedException e) {
@@ -180,9 +177,9 @@ public class RFXComHandler extends BaseThingHandler implements DeviceMessageList
try {
if (config.matchesMessage(message)) {
String receivedId = PACKET_TYPE_THING_TYPE_UID_MAP.get(message.getPacketType()).getId();
logger.debug("Received message from bridge: {} message: {}", bridge, message);
if (receivedId.equals(getThing().getThingTypeUID().getId())) {
logger.debug("Message from bridge [{}] matches thing [{}] message: {}", bridge,
getThing().getUID().toString(), message);
updateStatus(ThingStatus.ONLINE);
for (Channel channel : getThing().getChannels()) {
@@ -194,19 +191,21 @@ public class RFXComHandler extends BaseThingHandler implements DeviceMessageList
case CHANNEL_COMMAND:
case CHANNEL_CHIME_SOUND:
case CHANNEL_MOOD:
postNullableCommand(uid, message.convertToCommand(channelId, this));
postNullableCommand(uid, message.convertToCommand(channelId, config, this));
break;
case CHANNEL_LOW_BATTERY:
updateNullableState(uid,
isLowBattery(message.convertToState(CHANNEL_BATTERY_LEVEL, this)));
isLowBattery(message.convertToState(CHANNEL_BATTERY_LEVEL, config, this)));
break;
default:
updateNullableState(uid, message.convertToState(channelId, this));
updateNullableState(uid, message.convertToState(channelId, config, this));
break;
}
} catch (RFXComException e) {
} catch (RFXComInvalidStateException e) {
logger.trace("{} not configured for {}", channelId, message);
} catch (RFXComUnsupportedChannelException e) {
logger.trace("{} does not handle {}", channelId, message);
}
}

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -124,13 +126,14 @@ public class RFXComBBQTemperatureMessage extends RFXComBatteryDeviceMessage<RFXC
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
if (CHANNEL_FOOD_TEMPERATURE.equals(channelId)) {
return new DecimalType(foodTemperature);
} else if (CHANNEL_BBQ_TEMPERATURE.equals(channelId)) {
return new DecimalType(bbqTemperature);
} else {
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -14,6 +14,8 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.CHANNEL_BATTERY_LEVEL;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
import org.openhab.core.library.types.DecimalType;
@@ -36,13 +38,14 @@ abstract class RFXComBatteryDeviceMessage<T> extends RFXComDeviceMessageImpl<T>
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_BATTERY_LEVEL:
return convertBatteryLevelToSystemWideLevel(batteryLevel);
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -174,11 +176,12 @@ public class RFXComBlinds1Message extends RFXComBatteryDeviceMessage<RFXComBlind
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
if (CHANNEL_COMMAND.equals(channelId)) {
return (command == Commands.CLOSE ? OpenClosedType.CLOSED : OpenClosedType.OPEN);
} else {
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.CHANNEL_CHIME_SOUND;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -133,11 +135,12 @@ public class RFXComChimeMessage extends RFXComDeviceMessageImpl<RFXComChimeMessa
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
if (CHANNEL_CHIME_SOUND.equals(channelId)) {
return new DecimalType(chimeSound);
} else {
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -136,7 +138,8 @@ public class RFXComCurrentEnergyMessage extends RFXComBatteryDeviceMessage<RFXCo
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_CHANNEL1_AMPS:
return new DecimalType(channel1Amps);
@@ -151,7 +154,7 @@ public class RFXComCurrentEnergyMessage extends RFXComBatteryDeviceMessage<RFXCo
return new DecimalType(totalUsage);
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -125,7 +127,8 @@ public class RFXComCurrentMessage extends RFXComBatteryDeviceMessage<RFXComCurre
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_CHANNEL1_AMPS:
return new DecimalType(channel1Amps);
@@ -137,7 +140,7 @@ public class RFXComCurrentMessage extends RFXComBatteryDeviceMessage<RFXComCurre
return new DecimalType(channel3Amps);
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -131,11 +133,12 @@ public class RFXComCurtain1Message extends RFXComBatteryDeviceMessage<RFXComCurt
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
if (channelId.equals(CHANNEL_COMMAND)) {
return (command == Commands.CLOSE ? OpenClosedType.CLOSED : OpenClosedType.OPEN);
} else {
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.CHANNEL_DATE_TIME;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -122,11 +124,12 @@ public class RFXComDateTimeMessage extends RFXComBatteryDeviceMessage<RFXComDate
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
if (channelId.equals(CHANNEL_DATE_TIME)) {
return new DateTimeType(dateTime);
} else {
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -14,6 +14,7 @@ package org.openhab.binding.rfxcom.internal.messages;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -31,21 +32,27 @@ public interface RFXComDeviceMessage<T> extends RFXComMessage {
* Procedure for converting RFXCOM value to openHAB command.
*
* @param channelId id of the channel
* @param config Configuration of the thing being handled
* @param deviceState
* @return openHAB command.
* @throws RFXComUnsupportedChannelException if the channel is not supported
* @throws RFXComInvalidStateException if the channel is supported, but the device is not configured for the value
*/
Command convertToCommand(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException;
Command convertToCommand(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException;
/**
* Procedure for converting RFXCOM value to openHAB state.
*
* @param channelId id of the channel
* @param config configuration of the thing being handled
* @param deviceState
* @return openHAB state.
* @throws RFXComUnsupportedChannelException if the channel is not supported
* @throws RFXComInvalidStateException if the channel is supported, but the device is not configured for the value
*/
State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException;
State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException;
/**
* Procedure to get device id.

View File

@@ -17,6 +17,7 @@ import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.CHANNEL
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.config.RFXComGenericDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
@@ -48,13 +49,14 @@ abstract class RFXComDeviceMessageImpl<T> extends RFXComBaseMessage implements R
}
@Override
public Command convertToCommand(String channelId, DeviceState deviceState)
throws RFXComUnsupportedChannelException {
return (Command) convertToState(channelId, deviceState);
public Command convertToCommand(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
return (Command) convertToState(channelId, config, deviceState);
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_SIGNAL_LEVEL:
return convertSignalLevelToSystemWideLevel(signalLevel);

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -145,7 +147,8 @@ public class RFXComEnergyMessage extends RFXComBatteryDeviceMessage<RFXComEnergy
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_INSTANT_POWER:
return new DecimalType(instantPower);
@@ -160,7 +163,7 @@ public class RFXComEnergyMessage extends RFXComBatteryDeviceMessage<RFXComEnergy
return new DecimalType(totalAmpHour);
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -21,7 +21,9 @@ import java.util.Arrays;
import java.util.List;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -263,7 +265,8 @@ public class RFXComFanMessage extends RFXComDeviceMessageImpl<RFXComFanMessage.S
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_FAN_LIGHT:
return handleLightChannel();
@@ -278,7 +281,7 @@ public class RFXComFanMessage extends RFXComDeviceMessageImpl<RFXComFanMessage.S
return handleCommandStringChannel();
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -15,7 +15,9 @@ 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 org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -125,11 +127,12 @@ public class RFXComHomeConfortMessage extends RFXComDeviceMessageImpl<RFXComHome
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
if (channelId.equals(CHANNEL_COMMAND)) {
return (command == Commands.OFF || command == Commands.GROUP_OFF ? OnOffType.OFF : OnOffType.ON);
} else {
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -129,7 +131,8 @@ public class RFXComHumidityMessage extends RFXComBatteryDeviceMessage<RFXComHumi
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_HUMIDITY:
return new DecimalType(humidity);
@@ -138,7 +141,7 @@ public class RFXComHumidityMessage extends RFXComBatteryDeviceMessage<RFXComHumi
return new StringType(humidityStatus.toString());
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -271,7 +271,7 @@ public class RFXComInterfaceMessage extends RFXComBaseMessage {
transceiverType = TransceiverType._UNKNOWN;
logger.warn(
"The transceiver type reported ({}) isn't known to the RFXCom binding. Please raise an issue at https://github.com/openhab/openhab-addons/ to have it included.",
data[5]);
Byte.toUnsignedInt(data[5]));
}
hardwareVersion1 = data[11];

View File

@@ -14,7 +14,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -126,11 +128,11 @@ public class RFXComLighting1Message extends RFXComDeviceMessageImpl<RFXComLighti
// the message unless the last X<n> ON they saw was for them. So we
// redirect an incoming broadcast DIM/BRIGHT to the correct item
// based on the last X<n> we saw or sent.
unitCode = lastUnit[(int) houseCode - (int) 'A'];
unitCode = lastUnit[houseCode - 'A'];
} else {
unitCode = data[5];
if (command == Commands.ON) {
lastUnit[(int) houseCode - (int) 'A'] = unitCode;
lastUnit[houseCode - 'A'] = unitCode;
}
}
@@ -162,8 +164,8 @@ public class RFXComLighting1Message extends RFXComDeviceMessageImpl<RFXComLighti
}
@Override
public Command convertToCommand(String channelId, DeviceState deviceState)
throws RFXComUnsupportedChannelException {
public Command convertToCommand(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_COMMAND:
switch (command) {
@@ -190,11 +192,13 @@ public class RFXComLighting1Message extends RFXComDeviceMessageImpl<RFXComLighti
}
default:
return super.convertToCommand(channelId, deviceState);
return super.convertToCommand(channelId, config, deviceState);
}
}
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
@Override
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException {
switch (channelId) {
case CHANNEL_COMMAND:
switch (command) {

View File

@@ -20,7 +20,9 @@ import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting2Messag
import java.math.BigDecimal;
import java.math.RoundingMode;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -173,7 +175,8 @@ public class RFXComLighting2Message extends RFXComDeviceMessageImpl<RFXComLighti
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_DIMMING_LEVEL:
return RFXComLighting2Message.getPercentTypeFromDimLevel(dimmingLevel);
@@ -211,7 +214,7 @@ public class RFXComLighting2Message extends RFXComDeviceMessageImpl<RFXComLighti
}
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -13,12 +13,17 @@
package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.config.RFXComLighting4DeviceConfiguration.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import static org.openhab.binding.rfxcom.internal.config.RFXComLighting4DeviceConfiguration.PULSE_LABEL;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.config.RFXComLighting4DeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -28,8 +33,6 @@ import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.OpenClosedType;
import org.openhab.core.types.State;
import org.openhab.core.types.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* RFXCOM data class for lighting4 message.
@@ -57,14 +60,10 @@ import org.slf4j.LoggerFactory;
* @author Alessandro Ballini (ITA) - Initial contribution
* @author Pauli Anttila - Migrated to OH2
* @author Martin van Wingerden - Extended support for more complex PT2262 devices
* @author James Hewitt - Use the thing config to identify what incoming commandIds map to
* @author James Hewitt - Deprecate using previously discovered commandIds because they are unreliable
*/
public class RFXComLighting4Message extends RFXComDeviceMessageImpl<RFXComLighting4Message.SubType> {
// this logger is used from a static context, so is static as well
private static final Logger LOGGER = LoggerFactory.getLogger(RFXComLighting4Message.class);
private static final byte DEFAULT_OFF_COMMAND_ID = Commands.OFF_4.toByte();
private static final byte DEFAULT_ON_COMMAND_ID = Commands.ON_1.toByte();
public enum SubType implements ByteEnumWrapper {
PT2262(0);
@@ -80,62 +79,21 @@ public class RFXComLighting4Message extends RFXComDeviceMessageImpl<RFXComLighti
}
}
public enum Commands implements ByteEnumWrapper {
OFF_0(0, false),
ON_1(1, true),
OFF_2(2, false),
ON_3(3, true),
OFF_4(4, false),
ON_5(5, true),
ON_6(6, true),
ON_7(7, true),
ON_8(8, true),
ON_9(9, true),
ON_10(10, true),
ON_11(11, true),
ON_12(12, true),
OFF_14(14, false),
ON_15(15, true),
UNKNOWN(-1, false);
private final int command;
private final boolean on;
Commands(int command, boolean on) {
this.command = command;
this.on = on;
}
@Override
public byte toByte() {
return (byte) command;
}
public boolean isOn() {
return on;
}
public static Commands fromByte(int input) {
for (Commands c : Commands.values()) {
if (c.command == input) {
return c;
}
}
LOGGER.info(
"A not completely supported command with value {} was received, we can send it but please report "
+ "it as an issue including what the command means, this helps to extend the binding with better support.",
input);
return UNKNOWN;
}
}
// These are historical behaviour, are deprecated, and will be removed in a future openHAB release.
@Deprecated
private static final byte DEFAULT_OFF_COMMAND_ID = 4;
@Deprecated
private static final byte DEFAULT_ON_COMMAND_ID = 1;
@Deprecated
private Set<Integer> ON_COMMAND_IDS = Stream.of(1, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15)
.collect(Collectors.toCollection(HashSet::new));
private SubType subType;
private int sensorId;
private int pulse;
private Commands command;
private int commandId;
private int offCommandId;
private int onCommandId;
private RFXComLighting4DeviceConfiguration config;
public RFXComLighting4Message() {
super(PacketType.LIGHTING4);
@@ -152,7 +110,7 @@ public class RFXComLighting4Message extends RFXComDeviceMessageImpl<RFXComLighti
str += super.toString();
str += ", Sub type = " + subType;
str += ", Device Id = " + getDeviceId();
str += ", Command = " + command + "(" + commandId + ")";
str += ", Command Id = " + commandId;
str += ", Pulse = " + pulse;
return str;
@@ -162,13 +120,10 @@ public class RFXComLighting4Message extends RFXComDeviceMessageImpl<RFXComLighti
public void encodeMessage(byte[] data) throws RFXComException {
super.encodeMessage(data);
subType = fromByte(SubType.class, super.subType);
subType = ByteEnumUtil.fromByte(SubType.class, super.subType);
sensorId = (data[4] & 0xFF) << 12 | (data[5] & 0xFF) << 4 | (data[6] & 0xF0) >> 4;
commandId = (data[6] & 0x0F);
command = Commands.fromByte(commandId);
onCommandId = command.isOn() ? commandId : DEFAULT_ON_COMMAND_ID;
offCommandId = command.isOn() ? DEFAULT_OFF_COMMAND_ID : commandId;
pulse = (data[7] & 0xFF) << 8 | (data[8] & 0xFF);
@@ -205,20 +160,45 @@ public class RFXComLighting4Message extends RFXComDeviceMessageImpl<RFXComLighti
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration configuration, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
RFXComLighting4DeviceConfiguration config = (RFXComLighting4DeviceConfiguration) configuration;
switch (channelId) {
case CHANNEL_COMMAND:
case CHANNEL_MOTION:
return command.isOn() ? OnOffType.ON : OnOffType.OFF;
if (config.onCommandId != null && commandId == config.onCommandId) {
return OnOffType.ON;
}
if (config.offCommandId != null && commandId == config.offCommandId) {
return OnOffType.OFF;
}
// Deprecated if statement - to be removed in a future release
if (config.onCommandId == null && config.offCommandId == null) {
return ON_COMMAND_IDS.contains(commandId) ? OnOffType.ON : OnOffType.OFF;
}
throw new RFXComInvalidStateException(channelId, Integer.toString(commandId),
"Device not configured for received commandId");
case CHANNEL_CONTACT:
return command.isOn() ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
if (config.openCommandId != null && commandId == config.openCommandId) {
return OpenClosedType.OPEN;
}
if (config.closedCommandId != null && commandId == config.closedCommandId) {
return OpenClosedType.CLOSED;
}
// Deprecated if statement - to be removed in a future release
if (config.onCommandId == null && config.offCommandId == null) {
return ON_COMMAND_IDS.contains(commandId) ? OpenClosedType.OPEN : OpenClosedType.CLOSED;
}
throw new RFXComInvalidStateException(channelId, Integer.toString(commandId),
"Device not configured for received commandId");
case CHANNEL_COMMAND_ID:
return new DecimalType(commandId);
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}
@@ -233,30 +213,70 @@ public class RFXComLighting4Message extends RFXComDeviceMessageImpl<RFXComLighti
}
@Override
public void convertFromState(String channelId, Type type) throws RFXComUnsupportedChannelException {
public void convertFromState(String channelId, Type type)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_COMMAND:
if (type instanceof OnOffType) {
command = Commands.fromByte(type == OnOffType.ON ? onCommandId : offCommandId);
commandId = command.toByte();
if (type == OnOffType.ON) {
if (config.onCommandId != null) {
commandId = config.onCommandId;
} else {
// Deprecated - to throw RFXComInvalidStateException in a future release, see contact
// channel
commandId = DEFAULT_ON_COMMAND_ID;
}
}
if (type == OnOffType.OFF) {
if (config.offCommandId != null) {
commandId = config.offCommandId;
} else {
// Deprecated - to throw RFXComInvalidStateException in a future release, see contact
// channel
commandId = DEFAULT_OFF_COMMAND_ID;
}
}
} else {
throw new RFXComUnsupportedChannelException("Channel " + channelId + " does not accept " + type);
throw new RFXComInvalidStateException(channelId, type.toString(),
"Channel only supports OnOffType");
}
break;
case CHANNEL_CONTACT:
if (type instanceof OpenClosedType) {
if (type == OpenClosedType.OPEN) {
if (config.openCommandId != null) {
commandId = config.openCommandId;
} else {
throw new RFXComInvalidStateException(channelId, type.toString(),
"openCommandId not configured for this device");
}
}
if (type == OpenClosedType.CLOSED) {
if (config.closedCommandId != null) {
commandId = config.closedCommandId;
} else {
throw new RFXComInvalidStateException(channelId, type.toString(),
"closedCommandId not configured for this device");
}
}
} else {
throw new RFXComInvalidStateException(channelId, type.toString(),
"Channel only supports OpenClosedType");
}
break;
case CHANNEL_COMMAND_ID:
if (type instanceof DecimalType) {
commandId = ((DecimalType) type).toBigDecimal().byteValue();
command = Commands.fromByte(commandId);
commandId = (byte) ((DecimalType) type).intValue();
} else {
throw new RFXComUnsupportedChannelException("Channel " + channelId + " does not accept " + type);
throw new RFXComInvalidStateException(channelId, type.toString(),
"Channel only supports DecimalType");
}
break;
default:
throw new RFXComUnsupportedChannelException("Channel " + channelId + " is not relevant here");
throw new RFXComUnsupportedChannelException("Channel " + channelId + " is not supported by Lighting4");
}
}
@@ -269,23 +289,12 @@ public class RFXComLighting4Message extends RFXComDeviceMessageImpl<RFXComLighti
public void addDevicePropertiesTo(DiscoveryResultBuilder discoveryResultBuilder) throws RFXComException {
super.addDevicePropertiesTo(discoveryResultBuilder);
discoveryResultBuilder.withProperty(PULSE_LABEL, pulse);
discoveryResultBuilder.withProperty(ON_COMMAND_ID_LABEL, onCommandId);
discoveryResultBuilder.withProperty(OFF_COMMAND_ID_LABEL, offCommandId);
}
@Override
public void setConfig(RFXComDeviceConfiguration config) throws RFXComException {
RFXComLighting4DeviceConfiguration lighting4Config = (RFXComLighting4DeviceConfiguration) config;
super.setConfig(lighting4Config);
this.pulse = lighting4Config.pulse != null ? lighting4Config.pulse : 350;
this.onCommandId = valueOrDefault(lighting4Config.onCommandId, DEFAULT_ON_COMMAND_ID);
this.offCommandId = valueOrDefault(lighting4Config.offCommandId, DEFAULT_OFF_COMMAND_ID);
}
private int valueOrDefault(Integer commandId, byte defaultValue) {
if (commandId != null) {
return commandId;
}
return defaultValue;
super.setConfig(config);
this.config = (RFXComLighting4DeviceConfiguration) config;
this.pulse = this.config.pulse != null ? this.config.pulse : 350;
}
}

View File

@@ -21,7 +21,9 @@ import java.math.RoundingMode;
import java.util.Arrays;
import java.util.List;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -234,7 +236,8 @@ public class RFXComLighting5Message extends RFXComDeviceMessageImpl<RFXComLighti
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_MOOD:
switch (command) {
@@ -292,7 +295,7 @@ public class RFXComLighting5Message extends RFXComDeviceMessageImpl<RFXComLighti
}
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -134,7 +136,8 @@ public class RFXComLighting6Message extends RFXComDeviceMessageImpl<RFXComLighti
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_COMMAND:
switch (command) {
@@ -165,7 +168,7 @@ public class RFXComLighting6Message extends RFXComDeviceMessageImpl<RFXComLighti
}
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -12,8 +12,11 @@
*/
package org.openhab.binding.rfxcom.internal.messages;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.types.Command;
/**
* Factory to create RFXCom messages from either bytes delivered by the RFXCom device
@@ -21,9 +24,11 @@ import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType
*
* @author Pauli Anttila - Initial contribution
* @author James Hewitt-Thomas - Convert to interface to allow dependency injection
* @author James Hewitt-Thomas - Switch to making messages for a specific command
*/
public interface RFXComMessageFactory {
public RFXComMessage createMessage(PacketType packetType) throws RFXComException;
public RFXComMessage createMessage(PacketType packetType, RFXComDeviceConfiguration config, ChannelUID channelUID,
Command command) throws RFXComException;
public RFXComMessage createMessage(byte[] packet) throws RFXComException;
}

View File

@@ -18,9 +18,12 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComMessageNotImplementedException;
import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType;
import org.openhab.core.thing.ChannelUID;
import org.openhab.core.types.Command;
/**
* Factory to create RFXCom messages from either bytes delivered by the RFXCom device
@@ -98,13 +101,17 @@ public enum RFXComMessageFactoryImpl implements RFXComMessageFactory {
* Create message for transmission from the packet type associated with the thing.
*/
@Override
public RFXComMessage createMessage(PacketType packetType) throws RFXComException {
public RFXComMessage createMessage(PacketType packetType, RFXComDeviceConfiguration config, ChannelUID channelUID,
Command command) throws RFXComException {
try {
Class<? extends RFXComMessage> cl = MESSAGE_CLASSES.get(packetType);
if (cl == null) {
throw new RFXComMessageNotImplementedException("Message " + packetType + " not implemented");
}
return cl.getDeclaredConstructor().newInstance();
RFXComMessage msg = cl.getDeclaredConstructor().newInstance();
msg.setConfig(config);
msg.convertFromState(channelUID.getId(), command);
return msg;
} catch (ReflectiveOperationException e) {
throw new RFXComException(e);
}

View File

@@ -18,7 +18,9 @@ import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte
import java.math.BigDecimal;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -201,7 +203,8 @@ public class RFXComRFXSensorMessage extends RFXComDeviceMessageImpl<RFXComRFXSen
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_TEMPERATURE:
return subType == SubType.TEMPERATURE ? getTemperature() : null;
@@ -219,7 +222,7 @@ public class RFXComRFXSensorMessage extends RFXComDeviceMessageImpl<RFXComRFXSen
return subType == SubType.A_D ? handlePressure(deviceState) : null;
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -135,7 +137,8 @@ public class RFXComRainMessage extends RFXComBatteryDeviceMessage<RFXComRainMess
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_RAIN_RATE:
return new DecimalType(rainRate);
@@ -144,7 +147,7 @@ public class RFXComRainMessage extends RFXComBatteryDeviceMessage<RFXComRainMess
return new DecimalType(rainTotal);
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -142,7 +142,8 @@ public class RFXComRawMessage extends RFXComDeviceMessageImpl<RFXComRawMessage.S
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException {
switch (channelId) {
case CHANNEL_RAW_MESSAGE:
return new StringType(HexUtils.bytesToHex(rawMessage));

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -134,13 +136,14 @@ public class RFXComRfyMessage extends RFXComDeviceMessageImpl<RFXComRfyMessage.S
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_COMMAND:
return (command == Commands.DOWN ? OpenClosedType.CLOSED : OpenClosedType.OPEN);
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -233,7 +235,8 @@ public class RFXComSecurity1Message extends RFXComBatteryDeviceMessage<RFXComSec
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_MOTION:
switch (status) {
@@ -263,7 +266,7 @@ public class RFXComSecurity1Message extends RFXComBatteryDeviceMessage<RFXComSec
return new StringType(status.toString());
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -17,7 +17,9 @@ import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte
import java.util.Arrays;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -115,7 +117,8 @@ public class RFXComSecurity2Message extends RFXComBatteryDeviceMessage<RFXComSec
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_CONTACT:
return ((buttonStatus & BUTTON_0_BIT) == 0) ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
@@ -130,7 +133,7 @@ public class RFXComSecurity2Message extends RFXComBatteryDeviceMessage<RFXComSec
return ((buttonStatus & BUTTON_3_BIT) == 0) ? OpenClosedType.CLOSED : OpenClosedType.OPEN;
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -178,7 +180,8 @@ public class RFXComTemperatureHumidityBarometricMessage
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_TEMPERATURE:
return new DecimalType(temperature);
@@ -196,7 +199,7 @@ public class RFXComTemperatureHumidityBarometricMessage
return new StringType(forecastStatus.toString());
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -158,7 +160,8 @@ public class RFXComTemperatureHumidityMessage
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_TEMPERATURE:
return new DecimalType(temperature);
@@ -170,7 +173,7 @@ public class RFXComTemperatureHumidityMessage
return new StringType(humidityStatus.toString());
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.CHANNEL_TEMPERATURE;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -126,13 +128,14 @@ public class RFXComTemperatureMessage extends RFXComBatteryDeviceMessage<RFXComT
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_TEMPERATURE:
return new DecimalType(temperature);
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -120,7 +122,8 @@ public class RFXComTemperatureRainMessage extends RFXComBatteryDeviceMessage<RFX
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_TEMPERATURE:
return new DecimalType(temperature);
@@ -129,7 +132,7 @@ public class RFXComTemperatureRainMessage extends RFXComBatteryDeviceMessage<RFX
return new DecimalType(rainTotal);
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -155,7 +157,8 @@ public class RFXComThermostat1Message extends RFXComDeviceMessageImpl<RFXComTher
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_TEMPERATURE:
return new DecimalType(temperature);
@@ -174,7 +177,7 @@ public class RFXComThermostat1Message extends RFXComDeviceMessageImpl<RFXComTher
}
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -19,7 +19,9 @@ import static org.openhab.binding.rfxcom.internal.messages.RFXComThermostat3Mess
import java.util.Arrays;
import java.util.List;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -152,7 +154,8 @@ public class RFXComThermostat3Message extends RFXComDeviceMessageImpl<RFXComTher
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_COMMAND:
switch (command) {
@@ -202,7 +205,7 @@ public class RFXComThermostat3Message extends RFXComDeviceMessageImpl<RFXComTher
return command == null ? UnDefType.UNDEF : StringType.valueOf(command.toString());
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -125,7 +127,8 @@ public class RFXComUVMessage extends RFXComBatteryDeviceMessage<RFXComUVMessage.
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_UV:
return new DecimalType(uv);
@@ -134,7 +137,7 @@ public class RFXComUVMessage extends RFXComBatteryDeviceMessage<RFXComUVMessage.
return (subType == SubType.UV3 ? new DecimalType(temperature) : UnDefType.UNDEF);
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -17,6 +17,7 @@ import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.Pac
import java.util.Arrays;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComMessageTooLongException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
@@ -140,7 +141,8 @@ public class RFXComUndecodedRFMessage extends RFXComDeviceMessageImpl<RFXComUnde
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException {
switch (channelId) {
case CHANNEL_RAW_MESSAGE:
return new StringType(HexUtils.bytesToHex(rawMessage));

View File

@@ -15,7 +15,9 @@ package org.openhab.binding.rfxcom.internal.messages;
import static org.openhab.binding.rfxcom.internal.RFXComBindingConstants.*;
import static org.openhab.binding.rfxcom.internal.messages.ByteEnumUtil.fromByte;
import org.openhab.binding.rfxcom.internal.config.RFXComDeviceConfiguration;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComInvalidStateException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedChannelException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;
import org.openhab.binding.rfxcom.internal.handler.DeviceState;
@@ -168,7 +170,8 @@ public class RFXComWindMessage extends RFXComBatteryDeviceMessage<RFXComWindMess
}
@Override
public State convertToState(String channelId, DeviceState deviceState) throws RFXComUnsupportedChannelException {
public State convertToState(String channelId, RFXComDeviceConfiguration config, DeviceState deviceState)
throws RFXComUnsupportedChannelException, RFXComInvalidStateException {
switch (channelId) {
case CHANNEL_WIND_DIRECTION:
return new DecimalType(windDirection);
@@ -186,7 +189,7 @@ public class RFXComWindMessage extends RFXComBatteryDeviceMessage<RFXComWindMess
return new DecimalType(chillTemperature);
default:
return super.convertToState(channelId, deviceState);
return super.convertToState(channelId, config, deviceState);
}
}

View File

@@ -38,51 +38,31 @@
<description>Pulse length of the device</description>
<default>350</default>
</parameter>
<parameter name="onCommandId" type="integer" required="true">
<parameter name="onCommandId" type="integer" required="false" min="0" max="15">
<label>On Command</label>
<description>Specifies command to be send when ON must be transmitted</description>
<options>
<option value="0">OFF (value 0)</option>
<option value="1">ON (value 1)</option>
<option value="2">OFF (value 2)</option>
<option value="3">ON (value 3)</option>
<option value="4">OFF (value 4)</option>
<option value="5">ON (value 5)</option>
<option value="6">value 5</option>
<option value="7">ON (value 7)</option>
<option value="8">value 8</option>
<option value="9">ON (value 9)</option>
<option value="10">ON (value 10)</option>
<option value="11">ON (value 11)</option>
<option value="12">ON (value 12)</option>
<option value="13">value 13</option>
<option value="14">OFF (value 14)</option>
<option value="15">value 15</option>
</options>
<default>1</default>
<description>Specifies command that represents ON for this device. If not
specified, will treat 1, 3, 5-13 and 15 as
ON commands for receiving message, and will send 1 as an ON
command. This behaviour is deprecated. In a future
version, if this is not specified, the on command will
not be available.</description>
</parameter>
<parameter name="offCommandId" type="integer" required="true">
<parameter name="offCommandId" type="integer" required="false" min="0" max="15">
<label>Off Command</label>
<description>Specifies command to be send when OFF must be transmitted</description>
<options>
<option value="0">OFF (value 0)</option>
<option value="1">ON (value 1)</option>
<option value="2">OFF (value 2)</option>
<option value="3">ON (value 3)</option>
<option value="4">OFF (value 4)</option>
<option value="5">ON (value 5)</option>
<option value="6">value 5</option>
<option value="7">ON (value 7)</option>
<option value="8">value 8</option>
<option value="9">ON (value 9)</option>
<option value="10">ON (value 10)</option>
<option value="11">ON (value 11)</option>
<option value="12">ON (value 12)</option>
<option value="13">value 13</option>
<option value="14">OFF (value 14)</option>
<option value="15">value 15</option>
</options>
<default>4</default>
<description>Specifies command that represents OFF for this device. For historical reasons, if not
specified, will
treat 0, 2, 4 and 14 as OFF commands for receiving message, and will send 4 as an OFF
command. This behaviour is
deprecated. In a future version, if this is not specified, the off command will
not be available.</description>
</parameter>
<parameter name="openCommandId" type="integer" required="false" min="0" max="15">
<label>Open Command</label>
<description>Specifies command that represents OPEN for this device.</description>
</parameter>
<parameter name="closedCommandId" type="integer" required="false" min="0" max="15">
<label>Closed Command</label>
<description>Specifies command that represents CLOSED for this device.</description>
</parameter>
</config-description>
</thing-type>