[homekit] add BasicFan accessory (#13564)
* [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>
This commit is contained in:
@@ -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"),
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user