Skip to content

Commit

Permalink
#4 Support inverted logic when finding state
Browse files Browse the repository at this point in the history
  • Loading branch information
magx2 committed Apr 10, 2019
1 parent 39b5a35 commit 266bbf4
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.math.BigDecimal;
import java.util.Optional;

import static java.util.Optional.empty;
import static java.util.Optional.of;
import static org.eclipse.smarthome.core.library.types.OnOffType.OFF;
import static org.eclipse.smarthome.core.library.types.OnOffType.ON;
Expand Down Expand Up @@ -202,11 +201,11 @@ public Optional<State> onDefault(Channel channel) {
}

private Optional<State> hiType(Channel channel) {
boolean param2Present = channel.getParam2() != null && channel.getParam2() > 0;
if (param2Present || !channel.getType().isOutput()) {
return of(channel).map(Channel::getState).map(ChannelState::getHi).map(hi -> hi ? ON : OFF);
} else {
return empty();
}
boolean invertedLogic = channel.getParam3() != null && channel.getParam3() > 1;
return of(channel)
.map(Channel::getState)
.map(ChannelState::getHi)
.map(hi -> invertedLogic ? !hi : hi)
.map(hi -> hi ? ON : OFF);
}
}

0 comments on commit 266bbf4

Please sign in to comment.