Skip to content

Commit

Permalink
Simplify publishing channels
Browse files Browse the repository at this point in the history
  • Loading branch information
pbogut committed Aug 22, 2020
1 parent 1c6a420 commit 9f544b3
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -301,125 +301,81 @@ private void publishChannelIfLinked(ChannelUID channelUID) {
State state = null;
Integer stateValue = null;
if (CHANNEL_POWER.equals(channelID)) {
if (thisDevice.HasStatusValChanged("Pow")) {
logger.trace("Pow value has changed!");
statusChanged = true;
stateValue = thisDevice.GetIntStatusVal("Pow");
if (stateValue.intValue() != 1) {
state = OnOffType.OFF;
} else {
state = OnOffType.ON;
}
stateValue = thisDevice.GetIntStatusValIfChanged("Pow");
if (stateValue != null) {
state = GetOnOffFromInt(stateValue);
}
} else if (CHANNEL_MODE.equals(channelID)) {
if (thisDevice.HasStatusValChanged("Mod")) {
logger.trace("Mod value has changed!");
statusChanged = true;
stateValue = thisDevice.GetIntStatusVal("Mod");
stateValue = thisDevice.GetIntStatusValIfChanged("Mod");
if (stateValue != null) {
state = new DecimalType(stateValue);
}
} else if (CHANNEL_TURBO.equals(channelID)) {
if (thisDevice.HasStatusValChanged("Tur")) {
logger.trace("Mod value has changed!");
statusChanged = true;
stateValue = thisDevice.GetIntStatusVal("Tur");
if (stateValue.intValue() != 1) {
state = OnOffType.OFF;
} else {
state = OnOffType.ON;
}
stateValue = thisDevice.GetIntStatusValIfChanged("Tur");
if (stateValue != null) {
state = GetOnOffFromInt(stateValue);
}
} else if (CHANNEL_LIGHT.equals(channelID)) {
if (thisDevice.HasStatusValChanged("Lig")) {
logger.trace("Lig value has changed!");
statusChanged = true;
stateValue = thisDevice.GetIntStatusVal("Lig");
if (stateValue.intValue() != 1) {
state = OnOffType.OFF;
} else {
state = OnOffType.ON;
}
stateValue = thisDevice.GetIntStatusValIfChanged("Lig");
if (stateValue != null) {
state = GetOnOffFromInt(stateValue);
}
} else if (CHANNEL_TEMP.equals(channelID)) {
if (thisDevice.HasStatusValChanged("SetTem")) {
logger.trace("SetTem value has changed!");
statusChanged = true;
stateValue = thisDevice.GetIntStatusVal("SetTem");
stateValue = thisDevice.GetIntStatusValIfChanged("SetTem");
if (stateValue != null) {
state = new DecimalType(stateValue);
}
} else if (CHANNEL_TEMP_SENSOR.equals(channelID)) {
if (thisDevice.HasStatusValChanged("TemSen")) {
logger.trace("TemSen value has changed!");
statusChanged = true;
stateValue = thisDevice.GetIntStatusVal("TemSen");
stateValue = thisDevice.GetIntStatusValIfChanged("TemSen");
if (stateValue != null) {
state = new DecimalType(stateValue);
}
} else if (CHANNEL_SWING_VERTICAL.equals(channelID)) {
if (thisDevice.HasStatusValChanged("SwUpDn")) {
logger.trace("SwUpDn value has changed!");
statusChanged = true;
stateValue = thisDevice.GetIntStatusVal("SwUpDn");
stateValue = thisDevice.GetIntStatusValIfChanged("SwUpDn");
if (stateValue != null) {
state = new DecimalType(stateValue);
}
} else if (CHANNEL_WIND_SPEED.equals(channelID)) {
if (thisDevice.HasStatusValChanged("WdSpd")) {
logger.trace("WdSpd value has changed!");
statusChanged = true;
stateValue = thisDevice.GetIntStatusVal("WdSpd");
stateValue = thisDevice.GetIntStatusValIfChanged("WdSpd");
if (stateValue != null) {
state = new DecimalType(stateValue);
}
} else if (CHANNEL_AIR.equals(channelID)) {
if (thisDevice.HasStatusValChanged("Air")) {
logger.trace("Air value has changed!");
statusChanged = true;
stateValue = thisDevice.GetIntStatusVal("Air");
if (stateValue.intValue() != 1) {
state = OnOffType.OFF;
} else {
state = OnOffType.ON;
}
stateValue = thisDevice.GetIntStatusValIfChanged("Air");
if (stateValue != null) {
state = GetOnOffFromInt(stateValue);
}
} else if (CHANNEL_DRY.equals(channelID)) {
if (thisDevice.HasStatusValChanged("Blo")) {
logger.trace("Blo value has changed!");
statusChanged = true;
stateValue = thisDevice.GetIntStatusVal("Blo");
if (stateValue.intValue() != 1) {
state = OnOffType.OFF;
} else {
state = OnOffType.ON;
}
stateValue = thisDevice.GetIntStatusValIfChanged("Blo");
if (stateValue != null) {
state = GetOnOffFromInt(stateValue);
}
} else if (CHANNEL_HEALTH.equals(channelID)) {
if (thisDevice.HasStatusValChanged("Health")) {
logger.trace("Health value has changed!");
statusChanged = true;
stateValue = thisDevice.GetIntStatusVal("Health");
if (stateValue.intValue() != 1) {
state = OnOffType.OFF;
} else {
state = OnOffType.ON;
}
stateValue = thisDevice.GetIntStatusValIfChanged("Health");
if (stateValue != null) {
state = GetOnOffFromInt(stateValue);
}
} else if (CHANNEL_POWER_SAVE.equals(channelID)) {
if (thisDevice.HasStatusValChanged("SvSt")) {
logger.trace("SvSt value has changed!");
statusChanged = true;
stateValue = thisDevice.GetIntStatusVal("SvSt");
if (stateValue.intValue() != 1) {
state = OnOffType.OFF;
} else {
state = OnOffType.ON;
}
stateValue = thisDevice.GetIntStatusValIfChanged("SvSt");
if (stateValue != null) {
state = GetOnOffFromInt(stateValue);
}
}
if (state != null && statusChanged == true) {
if (state != null) {
logger.debug("Updating channel state for ChannelID {} : {}", channelID, state);
updateState(channelID, state);
}
}
}

private OnOffType GetOnOffFromInt(Integer stateValue) {
if (stateValue.intValue() == 1) {
return OnOffType.ON;
} else {
return OnOffType.OFF;
}
}

/**
* Shutdown thing, make sure background jobs are canceled
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,27 +507,26 @@ public Integer GetIntStatusVal(String valueName) {
return value;
}

public Boolean HasStatusValChanged(String valueName) {
/**
* Returns Itteger value for state if it changed since the last time this
* command was run for given state.
*/
public Integer GetIntStatusValIfChanged(String valueName) {
// Find the valueName in the Current Status object
String currcolumns[] = statusResponseGson.packJson.cols;
Integer currvalues[] = statusResponseGson.packJson.dat;
List<String> currcolList = new ArrayList<>(Arrays.asList(currcolumns));
List<Integer> currvalList = new ArrayList<>(Arrays.asList(currvalues));
int currvalueArrayposition = currcolList.indexOf(valueName);
if (currvalueArrayposition == -1) {
Integer currvalue = GetIntStatusVal(valueName);
Integer prevvalue = parametersState.get(valueName);

//assign curr value to state
parametersState.put(valueName, currvalue);
if (currvalue == null) {
return null;
}
// Now get the Corresponding value
Integer currvalue = currvalList.get(currvalueArrayposition);

if (parametersState.get(valueName) == null) {
//now previous value so assign the current one
parametersState.put(valueName, currvalue);
return Boolean.TRUE;
if (prevvalue == null || currvalue.intValue() != prevvalue.intValue()) {
logger.trace("EWPESmart: {} value has changed!", valueName);
return currvalue;
} else {
return null;
}

// Finally Compare the stored state
return new Boolean(currvalue.intValue() != parametersState.get(valueName));
}

protected void ExecuteCommand(DatagramSocket clientSocket, HashMap<String, Integer> parameters) throws Exception {
Expand Down

0 comments on commit 9f544b3

Please sign in to comment.