From df365dc9a85b808a65ec242fe2fcea2ac7bf08e5 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Mon, 28 Oct 2024 14:44:53 -0600 Subject: [PATCH] [homekit] Add (partial) Doorbell Service (#17130) * [homekit] add Doorbell Service this is _not_ sufficient for HomeKit to present a doorbell. it just shows as an unsupported accessory with the house icon, Signed-off-by: Cody Cutrer --- bundles/org.openhab.io.homekit/README.md | 4 ++ .../internal/HomekitAccessoryType.java | 1 + .../accessories/HomekitAccessoryFactory.java | 2 + .../accessories/HomekitDoorbellImpl.java | 48 +++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitDoorbellImpl.java diff --git a/bundles/org.openhab.io.homekit/README.md b/bundles/org.openhab.io.homekit/README.md index 7d1c1b95f0240..20323057a80f2 100644 --- a/bundles/org.openhab.io.homekit/README.md +++ b/bundles/org.openhab.io.homekit/README.md @@ -811,6 +811,10 @@ All accessories also support the following optional characteristic that can be l | | TargetPosition | | Dimmer, Number, Rollershutter | Target position of motorized door | | | | | | HoldPosition | Rollershutter, Switch | Motorized door should stop at its current position. ON is sent to Switch items. STOP is sent to Rollershutter items. Only supported by 3rd party Home apps (such as Elgato Eve) | | | | | | ObstructionStatus | Contact, Dimmer, Switch | Current status of obstruction sensor. ON-obstruction detected, OFF - no obstruction | | | +| Doorbell | | | | Doorbell. This accessory must also have a Speaker, Microphone, and Camera RTP Stream Management service in the same group in order to be usable by the Home App. The latter is not yet implemented in openHAB. | | | +| | ProgrammableSwitchEvent | | Contact, Number, String, Switch | The button press event. Note that the event will be forwarded to Home for every _update_ of the item, not just on change. | inverted (false) | SINGLE_PRESS (0, ON, OPEN), DOUBLE_PRESS (1), LONG_PRESS (2) [*](#customizable-enum) | +| | | Brightness | Dimmer | Brightness in % (1-100). | | | +| | | Volume | Number | Speaker volume from 0% to 100% | | | | Fan | | | | Fan | | | | | ActiveStatus | | Dimmer, Switch | Accessory current working status. A value of "ON"/"OPEN" indicates that the accessory is active and is functioning without any errors. | | | | | | CurrentFanState | Number, String | Current fan state. | | INACTIVE (0), IDLE (1), BLOWING_AIR (2) | 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 497e7dde40a8d..27b1e5564fa21 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 @@ -33,6 +33,7 @@ public enum HomekitAccessoryType { CARBON_MONOXIDE_SENSOR("CarbonMonoxideSensor"), CONTACT_SENSOR("ContactSensor"), DOOR("Door"), + DOORBELL("Doorbell"), FAN("Fan"), FAUCET("Faucet"), FILTER_MAINTENANCE("Filter"), 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 74462e7adeb5a..5c6cc73d2ac6a 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 @@ -76,6 +76,7 @@ public class HomekitAccessoryFactory { put(CARBON_MONOXIDE_SENSOR, new HomekitCharacteristicType[] { CARBON_MONOXIDE_DETECTED_STATE }); put(CONTACT_SENSOR, new HomekitCharacteristicType[] { CONTACT_SENSOR_STATE }); put(DOOR, new HomekitCharacteristicType[] { CURRENT_POSITION, TARGET_POSITION, POSITION_STATE }); + put(DOORBELL, new HomekitCharacteristicType[] { PROGRAMMABLE_SWITCH_EVENT }); put(FAN, new HomekitCharacteristicType[] { ACTIVE_STATUS }); put(FAUCET, new HomekitCharacteristicType[] { ACTIVE_STATUS }); put(FILTER_MAINTENANCE, new HomekitCharacteristicType[] { FILTER_CHANGE_INDICATION }); @@ -123,6 +124,7 @@ public class HomekitAccessoryFactory { put(CARBON_MONOXIDE_SENSOR, HomekitCarbonMonoxideSensorImpl.class); put(CONTACT_SENSOR, HomekitContactSensorImpl.class); put(DOOR, HomekitDoorImpl.class); + put(DOORBELL, HomekitDoorbellImpl.class); put(FAN, HomekitFanImpl.class); put(FAUCET, HomekitFaucetImpl.class); put(FILTER_MAINTENANCE, HomekitFilterMaintenanceImpl.class); diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitDoorbellImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitDoorbellImpl.java new file mode 100644 index 0000000000000..de96331c33b90 --- /dev/null +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitDoorbellImpl.java @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2010-2024 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 java.util.List; + +import org.openhab.io.homekit.internal.HomekitAccessoryUpdater; +import org.openhab.io.homekit.internal.HomekitException; +import org.openhab.io.homekit.internal.HomekitSettings; +import org.openhab.io.homekit.internal.HomekitTaggedItem; + +import io.github.hapjava.characteristics.Characteristic; +import io.github.hapjava.characteristics.impl.common.ProgrammableSwitchEventCharacteristic; +import io.github.hapjava.services.impl.DoorbellService; + +/** + * Implements a HomeKit Doorbell + * + * This is only the primary service. To implement the entire video doorbell + * profile, you also need to add a Camera RTP Stream Management service, + * a Speaker service, and Microphone service. + * + * @author Cody Cutrer - Initial contribution + */ +class HomekitDoorbellImpl extends AbstractHomekitAccessoryImpl { + + public HomekitDoorbellImpl(HomekitTaggedItem taggedItem, List mandatoryCharacteristics, + List mandatoryRawCharacteristics, HomekitAccessoryUpdater updater, + HomekitSettings settings) { + super(taggedItem, mandatoryCharacteristics, mandatoryRawCharacteristics, updater, settings); + } + + @Override + public void init() throws HomekitException { + super.init(); + addService(new DoorbellService(getCharacteristic(ProgrammableSwitchEventCharacteristic.class).get())); + } +}