Skip to content

Commit

Permalink
Merge pull request openhab#42 from boc-tothefuture/channel_id
Browse files Browse the repository at this point in the history
Channel ID instead of string parsing
  • Loading branch information
craigham authored Jun 24, 2017
2 parents 1885d9b + 39f0f82 commit 1d63b07
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class OmnilinkBindingConstants {
public final static String CHANNEL_ROOM_SCENEB = "sceneb";
public final static String CHANNEL_ROOM_SCENEC = "scenec";
public final static String CHANNEL_ROOM_SCENED = "scened";
public final static String CHANNEL_ROOM_STATE = "state";
public final static String CHANNEL_ROOM_STATE = "room_state";

public final static String CHANNEL_FLAGSWITCH = "switch";
public final static String CHANNEL_BUTTON_PRESS = "press";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.UID;
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.RefreshType;
import org.openhab.binding.omnilink.OmnilinkBindingConstants;
Expand All @@ -23,12 +22,11 @@ public ButtonHandler(Thing thing) {

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
String[] channelParts = channelUID.getAsString().split(UID.SEPARATOR);
logger.debug("must handle command for button. channel: {}, command: {}", channelUID, command);
if (!(command instanceof RefreshType)) {
try {
getOmnilinkBridgeHander().sendOmnilinkCommand(CommandMessage.CMD_BUTTON, 0,
Integer.parseInt(channelParts[channelParts.length - 2]));
int buttonNumber = getThingID();
getOmnilinkBridgeHander().sendOmnilinkCommand(CommandMessage.CMD_BUTTON, 0, buttonNumber);
} catch (NumberFormatException | OmniInvalidResponseException | OmniUnknownMessageTypeException
| BridgeOfflineException e) {
logger.debug("Could not send command to omnilink: {}", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void handleUpdate(ChannelUID channelUID, State newState) {
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
logger.debug("handleCommand called for channel:{}, command:{}", channelUID, command);
// final String[] channelParts = channelUID.getAsString().split(UID.SEPARATOR);

int flagID = getThingID();
if (command instanceof DecimalType) {
logger.debug("updating omnilink flag change: {}, command: {}", channelUID, command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.UID;
import org.eclipse.smarthome.core.types.Command;
import org.openhab.binding.omnilink.OmnilinkBindingConstants;
import org.slf4j.Logger;
Expand All @@ -27,15 +26,16 @@ public RoomHandler(Thing thing) {
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
logger.debug("handleCommand, channel id: {}, command: {}", channelUID, command);
String[] channelParts = channelUID.getAsString().split(UID.SEPARATOR);

String channelID = channelUID.getId();

int unitNum = getThingID();

if (channelParts[3].startsWith("scene") && OnOffType.ON.equals(command)) {
if (channelID.startsWith("scene") && OnOffType.ON.equals(command)) {

int param1 = 0;
int linkNum = -1;
switch (channelParts[3]) {
switch (channelID) {
case "scenea":
linkNum = 0;
break;
Expand All @@ -61,7 +61,7 @@ public void handleCommand(ChannelUID channelUID, Command command) {
logger.debug("Could not send command to omnilink: {}", e);
}
}
} else if (OmnilinkBindingConstants.CHANNEL_ROOM_SWITCH.equals(channelParts[3])) {
} else if (OmnilinkBindingConstants.CHANNEL_ROOM_SWITCH.equals(channelID)) {
int cmd;
if (OnOffType.ON.equals(command)) {
cmd = OmniLinkCmd.CMD_UNIT_ON.getNumber();
Expand All @@ -73,20 +73,20 @@ public void handleCommand(ChannelUID channelUID, Command command) {
} catch (OmniInvalidResponseException | OmniUnknownMessageTypeException | BridgeOfflineException e) {
logger.debug("Could not send command to omnilink: {}", e);
}
} else if (OmnilinkBindingConstants.CHANNEL_ROOM_ON.equals(channelParts[3]) && OnOffType.ON.equals(command)) {
} else if (OmnilinkBindingConstants.CHANNEL_ROOM_ON.equals(channelID) && OnOffType.ON.equals(command)) {
int cmd = OmniLinkCmd.CMD_UNIT_ON.getNumber();
try {
getOmnilinkBridgeHander().sendOmnilinkCommand(cmd, 0, unitNum);
} catch (OmniInvalidResponseException | OmniUnknownMessageTypeException | BridgeOfflineException e) {
logger.debug("Could not send command to omnilink: {}", e);
}
} else if (OmnilinkBindingConstants.CHANNEL_ROOM_OFF.equals(channelParts[3]) && OnOffType.ON.equals(command)) {
} else if (OmnilinkBindingConstants.CHANNEL_ROOM_OFF.equals(channelID) && OnOffType.ON.equals(command)) {
try {
getOmnilinkBridgeHander().sendOmnilinkCommand(OmniLinkCmd.CMD_UNIT_OFF.getNumber(), 0, unitNum);
} catch (OmniInvalidResponseException | OmniUnknownMessageTypeException | BridgeOfflineException e) {
logger.debug("Could not send command to omnilink: {}", e);
}
} else if (OmnilinkBindingConstants.CHANNEL_ROOM_STATE.equals(channelParts[3])) {
} else if (OmnilinkBindingConstants.CHANNEL_ROOM_STATE.equals(channelID)) {
int cmd = -1;
int param2 = -1;
if (command instanceof DecimalType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.eclipse.smarthome.core.library.types.OpenClosedType;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.UID;
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.State;
import org.openhab.binding.omnilink.OmnilinkBindingConstants;
Expand Down Expand Up @@ -44,10 +43,9 @@ public ThermostatHandler(Thing thing) {

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
String[] channelParts = channelUID.getAsString().split(UID.SEPARATOR);
logger.debug("Channel Parts {}", (Object[]) channelParts);

int thermostatID = getThingID();
String channelID = channelParts[3];
String channelID = channelUID.getId();

try {
switch (channelID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.eclipse.smarthome.core.library.types.PercentType;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.thing.UID;
import org.eclipse.smarthome.core.types.Command;
import org.eclipse.smarthome.core.types.State;
import org.eclipse.smarthome.core.types.Type;
Expand Down Expand Up @@ -42,10 +41,9 @@ public UpbUnitHandler(Thing thing) {
@Override
public void handleCommand(ChannelUID channelUID, Command command) {

String[] channelParts = channelUID.getAsString().split(UID.SEPARATOR);
logger.debug("handleCommand called");
OmniLinkCmd omniCmd;
int unitId = Integer.parseInt(channelParts[channelParts.length - 2]);
int unitId = getThingID();

if (command instanceof PercentType) {
int lightLevel = ((PercentType) command).intValue();
Expand Down

0 comments on commit 1d63b07

Please sign in to comment.