Skip to content

Commit

Permalink
Worked changed discovery for lighting4 (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin van Wingerden committed Feb 23, 2017
1 parent ff3ec7b commit b0932be
Show file tree
Hide file tree
Showing 26 changed files with 119 additions and 103 deletions.
Expand Up @@ -12,7 +12,7 @@
import java.util.Set;

import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType;
import org.openhab.binding.rfxcom.internal.messages.PacketType;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
Expand Down
Expand Up @@ -32,7 +32,7 @@
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComMessageNotImplementedException;
import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage;
import org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType;
import org.openhab.binding.rfxcom.internal.messages.PacketType;
import org.openhab.binding.rfxcom.internal.messages.RFXComMessage;
import org.openhab.binding.rfxcom.internal.messages.RFXComMessageFactory;
import org.slf4j.Logger;
Expand Down
Expand Up @@ -70,12 +70,10 @@ public void onDeviceMessageReceived(ThingUID bridge, RFXComMessage message) {
ThingUID thingUID = new ThingUID(uid, bridge, id.replace(RFXComBaseMessage.ID_DELIMITER, "_"));
if (thingUID != null) {
logger.trace("Adding new RFXCOM {} with id '{}' to smarthome inbox", thingUID, id);
String subType = msg.convertSubType(String.valueOf(msg.subType)).toString();
String label = msg.packetType + "-" + id;
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID).withLabel(label)
.withProperty(RFXComBindingConstants.DEVICE_ID, id)
.withProperty(RFXComBindingConstants.SUB_TYPE, subType).withBridge(bridge).build();
thingDiscovered(discoveryResult);
DiscoveryResultBuilder discoveryResultBuilder = DiscoveryResultBuilder.create(thingUID).withBridge(bridge);
msg.addProperties(discoveryResultBuilder);

thingDiscovered(discoveryResultBuilder.build());
}
} catch (Exception e) {
logger.debug("Error occurred during device discovery", e);
Expand Down
@@ -0,0 +1,81 @@
package org.openhab.binding.rfxcom.internal.messages;

import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;

/**
* List of message types
*
* @author Pauli Anttila - Initial contribution
*/
public enum PacketType {
INTERFACE_CONTROL(0),
INTERFACE_MESSAGE(1),
TRANSMITTER_MESSAGE(2),
UNDECODED_RF_MESSAGE(3),
LIGHTING1(16),
LIGHTING2(17),
LIGHTING3(18),
LIGHTING4(19),
LIGHTING5(20),
LIGHTING6(21),
CHIME(22),
FAN(23),
CURTAIN1(24),
BLINDS1(25),
RFY(26),
HOME_CONFORT(27),
EDISIO(28),
SECURITY1(32),
SECURITY2(33),
CAMERA1(40),
REMOTE_CONTROL(48),
THERMOSTAT1(64),
THERMOSTAT2(65),
THERMOSTAT3(66),
THERMOSTAT4(67),
RADIATOR1(72),
BBQ1(78),
TEMPERATURE_RAIN(79),
TEMPERATURE(80),
HUMIDITY(81),
TEMPERATURE_HUMIDITY(82),
BAROMETRIC(83),
TEMPERATURE_HUMIDITY_BAROMETRIC(84),
RAIN(85),
WIND(86),
UV(87),
DATE_TIME(88),
CURRENT(89),
ENERGY(90),
CURRENT_ENERGY(91),
POWER(92),
WEIGHT(93),
GAS(94),
WATER(95),
CARTELECTRONIC(96),
RFXSENSOR(112),
RFXMETER(113),
FS20(114),
IO_LINES(128);

private final int packetType;

PacketType(int packetType) {
this.packetType = packetType;
}

public byte toByte() {
return (byte) packetType;
}

public static PacketType fromByte(int input) throws RFXComUnsupportedValueException {
for (PacketType packetType : PacketType.values()) {
if (packetType.packetType == input) {
return packetType;
}
}

throw new RFXComUnsupportedValueException(PacketType.class, input);
}

}
Expand Up @@ -10,8 +10,9 @@

import javax.xml.bind.DatatypeConverter;

import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder;
import org.openhab.binding.rfxcom.RFXComBindingConstants;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComException;
import org.openhab.binding.rfxcom.internal.exceptions.RFXComUnsupportedValueException;

/**
* Base class for RFXCOM data classes. All other data classes should extend this class.
Expand All @@ -22,79 +23,6 @@ public abstract class RFXComBaseMessage implements RFXComMessage {

public final static String ID_DELIMITER = ".";

public enum PacketType {
INTERFACE_CONTROL(0),
INTERFACE_MESSAGE(1),
TRANSMITTER_MESSAGE(2),
UNDECODED_RF_MESSAGE(3),
LIGHTING1(16),
LIGHTING2(17),
LIGHTING3(18),
LIGHTING4(19),
LIGHTING5(20),
LIGHTING6(21),
CHIME(22),
FAN(23),
CURTAIN1(24),
BLINDS1(25),
RFY(26),
HOME_CONFORT(27),
EDISIO(28),
SECURITY1(32),
SECURITY2(33),
CAMERA1(40),
REMOTE_CONTROL(48),
THERMOSTAT1(64),
THERMOSTAT2(65),
THERMOSTAT3(66),
THERMOSTAT4(67),
RADIATOR1(72),
BBQ1(78),
TEMPERATURE_RAIN(79),
TEMPERATURE(80),
HUMIDITY(81),
TEMPERATURE_HUMIDITY(82),
BAROMETRIC(83),
TEMPERATURE_HUMIDITY_BAROMETRIC(84),
RAIN(85),
WIND(86),
UV(87),
DATE_TIME(88),
CURRENT(89),
ENERGY(90),
CURRENT_ENERGY(91),
POWER(92),
WEIGHT(93),
GAS(94),
WATER(95),
CARTELECTRONIC(96),
RFXSENSOR(112),
RFXMETER(113),
FS20(114),
IO_LINES(128);

private final int packetType;

PacketType(int packetType) {
this.packetType = packetType;
}

public byte toByte() {
return (byte) packetType;
}

public static PacketType fromByte(int input) throws RFXComUnsupportedValueException {
for (PacketType packetType : PacketType.values()) {
if (packetType.packetType == input) {
return packetType;
}
}

throw new RFXComUnsupportedValueException(PacketType.class, input);
}

}

public byte[] rawMessage;
public PacketType packetType;
public byte packetId;
Expand Down Expand Up @@ -147,4 +75,14 @@ public String toString() {
public String getDeviceId() {
return id1 + ID_DELIMITER + id2;
}

public void addProperties(DiscoveryResultBuilder discoveryResultBuilder) throws RFXComException {
String subTypeString = convertSubType(String.valueOf(subType)).toString();
String label = packetType + "-" + getDeviceId();

discoveryResultBuilder
.withLabel(label)
.withProperty(RFXComBindingConstants.DEVICE_ID, getDeviceId())
.withProperty(RFXComBindingConstants.SUB_TYPE, subType);
}
}
Expand Up @@ -164,7 +164,7 @@ public byte[] decodeMessage() {
byte[] data = new byte[10];

data[0] = 0x09;
data[1] = RFXComBaseMessage.PacketType.BLINDS1.toByte();
data[1] = PacketType.BLINDS1.toByte();
data[2] = subType.toByte();
data[3] = seqNbr;

Expand Down
Expand Up @@ -121,7 +121,7 @@ public byte[] decodeMessage() {
byte[] data = new byte[20];

data[0] = (byte) (data.length - 1);
data[1] = RFXComBaseMessage.PacketType.CURRENT_ENERGY.toByte();
data[1] = PacketType.CURRENT_ENERGY.toByte();
data[2] = subType.toByte();
data[3] = seqNbr;

Expand Down
Expand Up @@ -122,7 +122,7 @@ public byte[] decodeMessage() {
byte[] data = new byte[14];

data[0] = (byte) (data.length - 1);
data[1] = RFXComBaseMessage.PacketType.DATE_TIME.toByte();
data[1] = PacketType.DATE_TIME.toByte();
data[2] = subType.toByte();
data[3] = seqNbr;
data[4] = (byte) ((sensorId & 0xFF00) >> 8);
Expand Down
Expand Up @@ -124,7 +124,7 @@ public byte[] decodeMessage() {
byte[] data = new byte[18];

data[0] = 0x11;
data[1] = RFXComBaseMessage.PacketType.ENERGY.toByte();
data[1] = PacketType.ENERGY.toByte();
data[2] = subType.toByte();
data[3] = seqNbr;

Expand Down
Expand Up @@ -135,7 +135,7 @@ public byte[] decodeMessage() {
byte[] data = new byte[9];

data[0] = 0x08;
data[1] = RFXComBaseMessage.PacketType.HUMIDITY.toByte();
data[1] = PacketType.HUMIDITY.toByte();
data[2] = subType.toByte();
data[3] = seqNbr;
data[4] = (byte) ((sensorId & 0xFF00) >> 8);
Expand Down
Expand Up @@ -290,7 +290,7 @@ public byte[] decodeMessage() {
byte[] data = new byte[14];

data[0] = 0x0D;
data[1] = RFXComBaseMessage.PacketType.INTERFACE_MESSAGE.toByte();
data[1] = PacketType.INTERFACE_MESSAGE.toByte();
data[2] = subType.toByte();
data[3] = seqNbr;
data[4] = command.toByte();
Expand Down
Expand Up @@ -8,7 +8,7 @@
*/
package org.openhab.binding.rfxcom.internal.messages;

import static org.openhab.binding.rfxcom.internal.messages.RFXComBaseMessage.PacketType.LIGHTING2;
import static org.openhab.binding.rfxcom.internal.messages.PacketType.LIGHTING2;
import static org.openhab.binding.rfxcom.internal.messages.RFXComLighting2Message.Commands.*;

import java.math.BigDecimal;
Expand Down
Expand Up @@ -155,7 +155,7 @@ public byte[] decodeMessage() {
byte[] data = new byte[11];

data[0] = 0x0A;
data[1] = RFXComBaseMessage.PacketType.LIGHTING4.toByte();
data[1] = PacketType.LIGHTING4.toByte();
data[2] = subType.toByte();
data[3] = seqNbr;

Expand Down
Expand Up @@ -197,7 +197,7 @@ public byte[] decodeMessage() {
byte[] data = new byte[11];

data[0] = 0x0A;
data[1] = RFXComBaseMessage.PacketType.LIGHTING5.toByte();
data[1] = PacketType.LIGHTING5.toByte();
data[2] = subType.toByte();
data[3] = seqNbr;
data[4] = (byte) ((sensorId >> 16) & 0xFF);
Expand Down
Expand Up @@ -138,7 +138,7 @@ public byte[] decodeMessage() {
byte[] data = new byte[12];

data[0] = 0x0B;
data[1] = RFXComBaseMessage.PacketType.LIGHTING6.toByte();
data[1] = PacketType.LIGHTING6.toByte();
data[2] = subType.toByte();
data[3] = seqNbr;
data[4] = (byte) ((sensorId >> 8) & 0xFF);
Expand Down
Expand Up @@ -16,7 +16,6 @@

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;

public class RFXComMessageFactory {

Expand Down
Expand Up @@ -120,7 +120,7 @@ public byte[] decodeMessage() {
byte[] data = new byte[12];

data[0] = 0x0B;
data[1] = RFXComBaseMessage.PacketType.RAIN.toByte();
data[1] = PacketType.RAIN.toByte();
data[2] = subType.toByte();
data[3] = seqNbr;
data[4] = (byte) ((sensorId & 0xFF00) >> 8);
Expand Down
Expand Up @@ -149,7 +149,7 @@ public byte[] decodeMessage() {
final byte[] data = new byte[13];

data[0] = 12;
data[1] = RFXComBaseMessage.PacketType.RFY.toByte();
data[1] = PacketType.RFY.toByte();
data[2] = subType.toByte();
data[3] = seqNbr;
data[4] = (byte) ((unitId >> 16) & 0xFF);
Expand Down
Expand Up @@ -245,7 +245,7 @@ public byte[] decodeMessage() {
byte[] data = new byte[9];

data[0] = 0x08;
data[1] = RFXComBaseMessage.PacketType.SECURITY1.toByte();
data[1] = PacketType.SECURITY1.toByte();
data[2] = subType.toByte();
data[3] = seqNbr;
data[4] = (byte) ((sensorId >> 16) & 0xFF);
Expand Down
Expand Up @@ -180,7 +180,7 @@ public byte[] decodeMessage() {
byte[] data = new byte[14];

data[0] = 0x0D;
data[1] = RFXComBaseMessage.PacketType.TEMPERATURE_HUMIDITY_BAROMETRIC.toByte();
data[1] = PacketType.TEMPERATURE_HUMIDITY_BAROMETRIC.toByte();
data[2] = subType.toByte();
data[3] = seqNbr;
data[4] = (byte) ((sensorId & 0xFF00) >> 8);
Expand Down
Expand Up @@ -156,7 +156,7 @@ public byte[] decodeMessage() {
byte[] data = new byte[11];

data[0] = 0x0A;
data[1] = RFXComBaseMessage.PacketType.TEMPERATURE_HUMIDITY.toByte();
data[1] = PacketType.TEMPERATURE_HUMIDITY.toByte();
data[2] = subType.toByte();
data[3] = seqNbr;
data[4] = (byte) ((sensorId & 0xFF00) >> 8);
Expand Down
Expand Up @@ -116,7 +116,7 @@ public byte[] decodeMessage() {
byte[] data = new byte[9];

data[0] = 0x08;
data[1] = RFXComBaseMessage.PacketType.TEMPERATURE.toByte();
data[1] = PacketType.TEMPERATURE.toByte();
data[2] = subType.toByte();
data[3] = seqNbr;
data[4] = (byte) ((sensorId & 0xFF00) >> 8);
Expand Down
Expand Up @@ -115,7 +115,7 @@ public byte[] decodeMessage() {
byte[] data = new byte[11];

data[0] = (byte) (data.length - 1);
data[1] = RFXComBaseMessage.PacketType.TEMPERATURE_RAIN.toByte();
data[1] = PacketType.TEMPERATURE_RAIN.toByte();
data[2] = subType.toByte();
data[3] = seqNbr;
data[4] = (byte) ((sensorId & 0xFF00) >> 8);
Expand Down
Expand Up @@ -168,7 +168,7 @@ public byte[] decodeMessage() {
byte[] data = new byte[10];

data[0] = 0x09;
data[1] = RFXComBaseMessage.PacketType.THERMOSTAT1.toByte();
data[1] = PacketType.THERMOSTAT1.toByte();
data[2] = subType.toByte();
data[3] = seqNbr;
data[4] = (byte) ((sensorId & 0xFF00) >> 8);
Expand Down

0 comments on commit b0932be

Please sign in to comment.