diff --git a/bundles/org.openhab.io.homekit/README.md b/bundles/org.openhab.io.homekit/README.md index 475802dd5..23bd586a8 100644 --- a/bundles/org.openhab.io.homekit/README.md +++ b/bundles/org.openhab.io.homekit/README.md @@ -747,6 +747,10 @@ Support for this is planned for the future release of openHAB HomeKit binding. | | | RotationSpeed | Number, Dimmer | Fan rotation speed in % (1-100) | | | | SwingMode | Number, Switch | Swing mode. values: 0/OFF=SWING DISABLED, 1/ON=SWING ENABLED. Flag [inverted=true] swaps the default mapping | | | | LockControl | Number, Switch | Status of physical control lock. values: 0/OFF=CONTROL LOCK DISABLED, 1/ON=CONTROL LOCK ENABLED.Flag [inverted=true] swaps the default mapping | +| BasicFan | | | | Fan. A BasicFan is a subset of Fan, but the Home app allows you to customize the icon of the accessory to show a ceiling fan. | +| | OnState | | Switch, Dimmer | Accessory current working status. A value of "ON"/"OPEN" indicates that the accessory is active and is functioning without any errors. | +| | | RotationDirection | Number, Switch | Rotation direction. values: 0/OFF=CLOCKWISE, 1/ON=COUNTER CLOCKWISE. Flag [inverted=true] swaps the default mapping | +| | | RotationSpeed | Number, Dimmer | Fan rotation speed in % (1-100) | | Thermostat | | | | A thermostat requires all mandatory characteristics defined below | | | CurrentTemperature | | Number | Current temperature. supported configuration: minValue, maxValue, step | | | TargetTemperature | | Number | Target temperature. supported configuration: minValue, maxValue, step | diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitAccessoryType.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitAccessoryType.java index f4d03fa4a..1e96648f1 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitAccessoryType.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitAccessoryType.java @@ -39,6 +39,7 @@ public enum HomekitAccessoryType { SMOKE_SENSOR("SmokeSensor"), CARBON_MONOXIDE_SENSOR("CarbonMonoxideSensor"), CARBON_DIOXIDE_SENSOR("CarbonDioxideSensor"), + BASIC_FAN("BasicFan"), FAN("Fan"), LOCK("Lock"), SECURITY_SYSTEM("SecuritySystem"), diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java index f0bf4a188..ecdb2f02b 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java @@ -78,6 +78,7 @@ public class HomekitAccessoryFactory { put(CARBON_MONOXIDE_SENSOR, new HomekitCharacteristicType[] { CARBON_MONOXIDE_DETECTED_STATE }); put(WINDOW_COVERING, new HomekitCharacteristicType[] { TARGET_POSITION, CURRENT_POSITION, POSITION_STATE }); put(LIGHTBULB, new HomekitCharacteristicType[] { ON_STATE }); + put(BASIC_FAN, new HomekitCharacteristicType[] { ON_STATE }); put(FAN, new HomekitCharacteristicType[] { ACTIVE_STATUS }); put(LIGHT_SENSOR, new HomekitCharacteristicType[] { LIGHT_LEVEL }); put(TEMPERATURE_SENSOR, new HomekitCharacteristicType[] { CURRENT_TEMPERATURE }); @@ -119,6 +120,7 @@ public class HomekitAccessoryFactory { put(CARBON_MONOXIDE_SENSOR, HomekitCarbonMonoxideSensorImpl.class); put(WINDOW_COVERING, HomekitWindowCoveringImpl.class); put(LIGHTBULB, HomekitLightbulbImpl.class); + put(BASIC_FAN, HomekitBasicFanImpl.class); put(FAN, HomekitFanImpl.class); put(LIGHT_SENSOR, HomekitLightSensorImpl.class); put(TEMPERATURE_SENSOR, HomekitTemperatureSensorImpl.class); diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitBasicFanImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitBasicFanImpl.java new file mode 100644 index 000000000..3c60e7d0a --- /dev/null +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitBasicFanImpl.java @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2010-2022 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.io.homekit.internal.accessories; + +import static org.openhab.io.homekit.internal.HomekitCharacteristicType.ON_STATE; + +import java.util.List; +import java.util.concurrent.CompletableFuture; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.openhab.io.homekit.internal.HomekitAccessoryUpdater; +import org.openhab.io.homekit.internal.HomekitSettings; +import org.openhab.io.homekit.internal.HomekitTaggedItem; + +import io.github.hapjava.accessories.BasicFanAccessory; +import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; +import io.github.hapjava.services.impl.BasicFanService; + +/** + * Implements Fan using an Item that provides an On/Off state + * + * @author Cody Cutrer - Initial contribution + */ +@NonNullByDefault({}) +class HomekitBasicFanImpl extends AbstractHomekitAccessoryImpl implements BasicFanAccessory { + private final BooleanItemReader onReader; + + public HomekitBasicFanImpl(HomekitTaggedItem taggedItem, List mandatoryCharacteristics, + HomekitAccessoryUpdater updater, HomekitSettings settings) throws IncompleteAccessoryException { + super(taggedItem, mandatoryCharacteristics, updater, settings); + onReader = createBooleanReader(ON_STATE); + this.getServices().add(new BasicFanService(this)); + } + + @Override + public CompletableFuture isOn() { + return CompletableFuture.completedFuture(onReader.getValue()); + } + + @Override + public CompletableFuture setOn(boolean state) { + onReader.setValue(state); + return CompletableFuture.completedFuture(null); + } + + @Override + public void subscribeOn(HomekitCharacteristicChangeCallback callback) { + subscribe(ON_STATE, callback); + } + + @Override + public void unsubscribeOn() { + unsubscribe(ON_STATE); + } +}