]> git.basschouten.com Git - openhab-addons.git/commitdiff
[homekit] add BasicFan accessory (#13564)
authorCody Cutrer <cody@cutrer.us>
Fri, 9 Dec 2022 18:17:51 +0000 (11:17 -0700)
committerGitHub <noreply@github.com>
Fri, 9 Dec 2022 18:17:51 +0000 (19:17 +0100)
* [homekit] add BasicFan accessory

This is Fan v1. It's a subset of FanV2, except that Home allows you
to customize the icon to show a ceiling fan.

Signed-off-by: Cody Cutrer <cody@cutrer.us>
bundles/org.openhab.io.homekit/README.md
bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitAccessoryType.java
bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitAccessoryFactory.java
bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitBasicFanImpl.java [new file with mode: 0644]

index 475802dd5492b2e678ddbf779a22e30a966d5594..23bd586a8bf8def933da8ef8a08ddbd6350f1c63 100644 (file)
@@ -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                                                                                                                                                                                                                                                                               |
index f4d03fa4a9938bd7b5410e7e409e61ee492f8b78..1e96648f1b1a917712b60e446c0d49c5915cc9d1 100644 (file)
@@ -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"),
index f0bf4a188a796be5a9b8fce0aac01343fedf19a2..ecdb2f02b68224db7f9806ca1e173f796be54e06 100644 (file)
@@ -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 (file)
index 0000000..3c60e7d
--- /dev/null
@@ -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<HomekitTaggedItem> 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<Boolean> isOn() {
+        return CompletableFuture.completedFuture(onReader.getValue());
+    }
+
+    @Override
+    public CompletableFuture<Void> 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);
+    }
+}