Skip to content

Commit

Permalink
Fix dimmer calculations. Fixes souliss#16
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarolobato committed Apr 12, 2020
1 parent 3abe6b1 commit 9bd7c0a
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ public void handleCommand(ChannelUID channelUID, Command command) {
if (command instanceof RefreshType) {
switch (channelUID.getId()) {
case SoulissBindingConstants.ONOFF_CHANNEL:
logger.debug("T19, updateState refresh ONOFF to {} raw {}", getOHState_OnOff_FromSoulissVal(T1nRawState_byte0),T1nRawState_byte0);
updateState(channelUID, getOHState_OnOff_FromSoulissVal(T1nRawState_byte0));
break;
case SoulissBindingConstants.DIMMER_BRIGHTNESS_CHANNEL:
logger.debug("T19, updateState refresh BIGHTNESS to {} absolute {} raw {}", PercentType.valueOf(String.valueOf((T1nRawStateBrigthness_byte1 / 255) * 100)), String.valueOf((T1nRawStateBrigthness_byte1 / 255) * 100),T1nRawStateBrigthness_byte1);
updateState(SoulissBindingConstants.DIMMER_BRIGHTNESS_CHANNEL,
PercentType.valueOf(String.valueOf((T1nRawStateBrigthness_byte1 / 255) * 100)));
break;
Expand All @@ -65,27 +67,33 @@ public void handleCommand(ChannelUID channelUID, Command command) {
case SoulissBindingConstants.ONOFF_CHANNEL:
if (command instanceof OnOffType) {
if (command.equals(OnOffType.ON)) {
logger.debug("T19, commandSend ONOFF -> ON");
commandSEND(SoulissBindingProtocolConstants.Souliss_T1n_OnCmd);

} else if (command.equals(OnOffType.OFF)) {
logger.debug("T19, commandSend ONOFF -> OFF");
commandSEND(SoulissBindingProtocolConstants.Souliss_T1n_OffCmd);
}
}
break;

case SoulissBindingConstants.DIMMER_BRIGHTNESS_CHANNEL:
if (command instanceof PercentType) {
logger.debug("T19, updateState BIGHTNESS to {} ", command);
updateState(SoulissBindingConstants.DIMMER_BRIGHTNESS_CHANNEL, (PercentType) command);
// updateState(SoulissBindingConstants.DIMMER_BRIGHTNESS_CHANNEL,
/// PercentType.valueOf(hsbState.getBrightness().toString()));
logger.debug("T19, commandSend BIGHTNESS to {} short value {} raw command {} ", (byte) (((PercentType) command).shortValue() * 255.00 / 100.00) ,((PercentType) command).shortValue(),command);
commandSEND(SoulissBindingProtocolConstants.Souliss_T1n_Set,
(byte) (((PercentType) command).shortValue() * 255.00 / 100.00));
// Short.parseShort(String.valueOf(Math.round((dimmerValue / 255.00) * 100)))
} else if (command instanceof OnOffType) {
if (command.equals(OnOffType.ON)) {
logger.debug("T19, commandSend 2 ONOFF -> ON");
commandSEND(SoulissBindingProtocolConstants.Souliss_T1n_OnCmd);

} else if (command.equals(OnOffType.OFF)) {
logger.debug("T19, commandSend 2 ONOFF -> OFF");
commandSEND(SoulissBindingProtocolConstants.Souliss_T1n_OffCmd);
}
}
Expand All @@ -94,20 +102,22 @@ public void handleCommand(ChannelUID channelUID, Command command) {
case SoulissBindingConstants.ROLLER_BRIGHTNESS_CHANNEL:
if (command instanceof UpDownType) {
if (command.equals(UpDownType.UP)) {
logger.debug("T19, commandSend 2 ROLLER -> UP");
commandSEND(SoulissBindingProtocolConstants.Souliss_T1n_BrightUp);
} else if (command.equals(UpDownType.DOWN)) {
logger.debug("T19, commandSend 2 ROLLER -> DOWN");
commandSEND(SoulissBindingProtocolConstants.Souliss_T1n_BrightDown);
}
}
break;
case SoulissBindingConstants.SLEEP_CHANNEL:
if (command instanceof OnOffType) {
logger.debug("T19, commandSend 2 SLEEP sleepTime: {}",xSleepTime);
commandSEND((byte) (SoulissBindingProtocolConstants.Souliss_T1n_Timed + xSleepTime));
}
break;
}
}

}

@Override
Expand All @@ -117,15 +127,18 @@ public void initialize() {
gwConfigurationMap = thing.getConfiguration();
if (gwConfigurationMap.get(SoulissBindingConstants.SLEEP_CHANNEL) != null) {
xSleepTime = ((BigDecimal) gwConfigurationMap.get(SoulissBindingConstants.SLEEP_CHANNEL)).byteValue();
logger.debug("T19, initialize sleepTime: {}", xSleepTime);
}
if (gwConfigurationMap.get(SoulissBindingConstants.CONFIG_SECURE_SEND) != null) {
bSecureSend = ((Boolean) gwConfigurationMap.get(SoulissBindingConstants.CONFIG_SECURE_SEND)).booleanValue();
logger.debug("T19, initialize SecureSend: {}", bSecureSend);
}
}

public void setState(PrimitiveType _state) {
super.setLastStatusStored();
if (_state != null) {
logger.debug("T19, setState, updateState sleepChannel OFF");
updateState(SoulissBindingConstants.SLEEP_CHANNEL, OnOffType.OFF);
logger.debug("T19, setting state to {}", _state.toFullString());
this.updateState(SoulissBindingConstants.ONOFF_CHANNEL, (OnOffType) _state);
Expand All @@ -134,16 +147,17 @@ public void setState(PrimitiveType _state) {

public void setRawStateDimmerValue(byte _dimmerValue) {
try {

if (_dimmerValue != T1nRawState_byte0) {
logger.debug("T19, setting dimmer to {}", _dimmerValue);
logger.debug("T19 -- setting dimmer to dimmerValue {},short {}, T1nRawState_byte0 {}, calculated: {}, calculated no round: {}", _dimmerValue, _dimmerValue & 0xFF, T1nRawState_byte0,String.valueOf(Math.round(((_dimmerValue& 0xFF) * 100.0) / 255.0)),((_dimmerValue& 0xFF) * 100.0) / 255.0);
updateState(SoulissBindingConstants.DIMMER_BRIGHTNESS_CHANNEL,
PercentType.valueOf(String.valueOf(Math.round((T1nRawState_byte0 / 255) * 100))));
PercentType.valueOf(String.valueOf(Math.round(((_dimmerValue& 0xFF)*100.0) / 255.0))));

}
} catch (IllegalStateException ex) {
logger.debug("UUID: " + this.getThing().getUID().getAsString()
+ " - Update state error (in setDimmerValue): " + ex.getMessage());
} catch (java.lang.IllegalArgumentException ex) {
logger.warn("T19 Error setting state",ex);
}
}

Expand All @@ -154,6 +168,7 @@ public void setRawState(byte _rawState) {
super.setLastStatusStored();
// update item state only if it is different from previous
if (T1nRawState_byte0 != _rawState) {
logger.debug("T19, setRawState {} to OH state {}", _rawState, getOHState_OnOff_FromSoulissVal(_rawState));
this.setState(getOHState_OnOff_FromSoulissVal(_rawState));
}
T1nRawState_byte0 = _rawState;
Expand Down

0 comments on commit 9bd7c0a

Please sign in to comment.