Skip to content

Commit

Permalink
[homekit] allow configuring min/max light level (openhab#14034)
Browse files Browse the repository at this point in the history
since the default is weirdly 0.0001, yet my sensors can report a
straight 0.

Signed-off-by: Cody Cutrer <cody@cutrer.us>
  • Loading branch information
ccutrer authored Dec 21, 2022
1 parent 462dca8 commit a079603
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bundles/org.openhab.io.homekit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ Support for this is planned for the future release of openHAB HomeKit binding.
| | | TamperedStatus | Switch, Contact | Tampered status |
| | | BatteryLowStatus | Switch, Contact, Number | Battery status |
| LightSensor | | | | Light sensor |
| | LightLevel | | Number | Light level in lux |
| | LightLevel | | Number | Light level in lux. supported configuration: minValue, maxValue. |
| | | Name | String | Name of the sensor |
| | | ActiveStatus | Switch, Contact | Working status |
| | | FaultStatus | Switch, Contact | Fault status |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,19 @@ public HomekitLightSensorImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedIt
public CompletableFuture<Double> getCurrentAmbientLightLevel() {
final @Nullable DecimalType state = getStateAs(LIGHT_LEVEL, DecimalType.class);
return CompletableFuture
.completedFuture(state != null ? state.doubleValue()
: getAccessoryConfiguration(HomekitCharacteristicType.LIGHT_LEVEL, HomekitTaggedItem.MIN_VALUE,
BigDecimal.valueOf(CurrentAmbientLightLevelCharacteristic.DEFAULT_MIN_VALUE))
.doubleValue());
.completedFuture(state != null ? state.doubleValue() : getMinCurrentAmbientLightLevel());
}

@Override
public double getMinCurrentAmbientLightLevel() {
return getAccessoryConfiguration(HomekitCharacteristicType.LIGHT_LEVEL, HomekitTaggedItem.MIN_VALUE,
BigDecimal.valueOf(CurrentAmbientLightLevelCharacteristic.DEFAULT_MIN_VALUE)).doubleValue();
}

@Override
public double getMaxCurrentAmbientLightLevel() {
return getAccessoryConfiguration(HomekitCharacteristicType.LIGHT_LEVEL, HomekitTaggedItem.MAX_VALUE,
BigDecimal.valueOf(CurrentAmbientLightLevelCharacteristic.DEFAULT_MAX_VALUE)).doubleValue();
}

@Override
Expand Down

0 comments on commit a079603

Please sign in to comment.