[homekit] fix BooleanItemReader to work with DimmerItems (#13507)

* [homekit] fix BooleanItemReader to work with DimmerItems

DimmerItems have a PercentType state, which is easily convertible
to OnOffType, but is not inherited from it. So take that into account.

i.e. a variable speed fan can use a single DimmerItem for both
ActiveStatus and RotationSpeed.

* [homekit] Document that Dimmer is a possible item type for several booleans

Signed-off-by: Cody Cutrer <cody@cutrer.us>
This commit is contained in:
Cody Cutrer
2022-10-10 05:36:23 -06:00
committed by GitHub
parent d83c32cd24
commit 507e714dd0
2 changed files with 30 additions and 25 deletions

View File

@@ -25,6 +25,7 @@ import org.openhab.core.library.items.SwitchItem;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.OpenClosedType;
import org.openhab.core.library.types.PercentType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.types.State;
@@ -87,8 +88,11 @@ public class BooleanItemReader {
}
boolean getValue() {
final State state = item.getState();
State state = item.getState();
final BigDecimal localTrueThresheold = trueThreshold;
if (state instanceof PercentType) {
state = state.as(OnOffType.class);
}
if (state instanceof OnOffType) {
return state.equals(trueOnOffValue);
} else if (state instanceof OpenClosedType) {
@@ -104,7 +108,8 @@ public class BooleanItemReader {
return result ^ invertThreshold;
}
}
logger.debug("Unexpected item state, returning false. Item {}, State {}", item.getName(), state);
logger.debug("Unexpected item state, returning false. Item {}, State {} ({})", item.getName(), state,
state.getClass().getSimpleName());
return false;
}