mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[homekit] add support for additional homekit accessories (#12536)
Signed-off-by: Eugen Freiter <freiter@gmx.de>
This commit is contained in:
parent
d584daf334
commit
f310cf7ca0
@ -21,7 +21,12 @@ HomeKit integration supports following accessory types:
|
||||
- Motorized Door
|
||||
- Motorized Window
|
||||
- Window Covering/Blinds
|
||||
- Slat
|
||||
- Valve
|
||||
- Faucet / Shower
|
||||
- Speaker
|
||||
- SmartSpeaker
|
||||
- Microphone
|
||||
- Air Quality Sensor
|
||||
- Contact Sensor
|
||||
- Leak Sensor
|
||||
@ -33,6 +38,8 @@ HomeKit integration supports following accessory types:
|
||||
- Light Sensor
|
||||
- Carbon Dioxide Sensor
|
||||
- Carbon Monoxide Sensor
|
||||
- Battery
|
||||
- Filter Maintenance
|
||||
|
||||
## Quick start
|
||||
|
||||
@ -632,7 +639,7 @@ Support for this is planned for the future release of openHAB HomeKit binding.
|
||||
| WindowCovering | | | | Window covering / blinds. One Rollershutter item covers all mandatory characteristics. see examples below. |
|
||||
| | CurrentPosition | | Rollershutter, Dimmer, Number | Current position of window covering |
|
||||
| | TargetPosition | | Rollershutter, Dimmer, Number | Target position of window covering |
|
||||
| | PositionState | | Rollershutter, String | current only "STOPPED" is supported. |
|
||||
| | PositionState | | Rollershutter, String | Currently only "STOPPED" is supported. |
|
||||
| | | Name | String | Name of the windows covering |
|
||||
| | | HoldPosition | Switch | Window covering should stop at its current position. A value of ON must hold the state of the accessory. A value of OFF should be ignored. |
|
||||
| | | ObstructionStatus | Switch, Contact | Current status of obstruction sensor. ON-obstruction detected, OFF - no obstruction |
|
||||
@ -640,6 +647,12 @@ Support for this is planned for the future release of openHAB HomeKit binding.
|
||||
| | | TargetHorizontalTiltAngle | Number, Dimmer | Number Item = target angle of horizontal slats (-90 to +90). Dimmer Item = the percentage of openness (0%-100%) |
|
||||
| | | CurrentVerticalTiltAngle | Number, Dimmer | Number Item = current angle of vertical slats (-90 to +90) . Dimmer Item = the percentage of openness (0%-100%) |
|
||||
| | | TargetVerticalTiltAngle | Number, Dimmer | Number Item = target angle of vertical slats. Dimmer Item = the percentage of openness (0%-100%) |
|
||||
| Slat | | | | Slat which tilts on a vertical or a horizontal axis. Configuration "type:horizontal" or "type:vertical" |
|
||||
| | CurrentSlatState | | String | Current slat state. possible values (FIXED,SWINGING,JAMMED). Custom mapping can be defined at item level, e.g. [JAMMED="JAM", FIXED="FIX"] |
|
||||
| | | Name | String | Name of the slat |
|
||||
| | | SwingMode | Number, Switch | Swing mode. values: 0/OFF=SWING DISABLED, 1/ON=SWING ENABLED |
|
||||
| | | CurrentTiltAngle | Number, Dimmer | Number Item = current angle of slats. values -90 to 90. A value of 0 indicates that the slats are rotated to a fully open position. Dimmer Item = the percentage of openness (0%-100%) |
|
||||
| | | TargetTiltAngle | Number, Dimmer | Number Item = target angle of slats (-90 to +90). Dimmer Item = the percentage of openness (0%-100%) |
|
||||
| Switchable | | | | An accessory that can be turned off and on. While similar to a lightbulb, this will be presented differently in the Siri grammar and iOS apps |
|
||||
| | OnState | | Switch | State of the switch - ON/OFF |
|
||||
| | | Name | String | Name of the switch |
|
||||
@ -655,43 +668,47 @@ Support for this is planned for the future release of openHAB HomeKit binding.
|
||||
| | | Brightness | Dimmer, Color | Brightness in % (1-100). See "Usage of dimmer modes" for configuration details. |
|
||||
| | | ColorTemperature | Number | Color temperature represented in reciprocal megaKelvin. The default value range is from 50 to 400. Color temperature should not be used in combination with hue, saturation and brightness. It supports following configuration parameters: minValue, maxValue |
|
||||
| Fan | | | | Fan |
|
||||
| | ActiveStatus | | Switch | accessory current working status. A value of "ON"/"OPEN" indicates that the accessory is active and is functioning without any errors. |
|
||||
| | | CurrentFanState | Number | current fan state. values: 0=INACTIVE, 1=IDLE, 2=BLOWING AIR |
|
||||
| | | TargetFanState | Number | target fan state. values: 0=MANUAL, 1=AUTO |
|
||||
| | | RotationDirection | Number, Switch | rotation direction. values: 0/OFF=CLOCKWISE, 1/ON=COUNTER CLOCKWISE |
|
||||
| | | RotationSpeed | Number, Dimmer | fan rotation speed in % (1-100) |
|
||||
| | | SwingMode | Number, Switch | swing mode. values: 0/OFF=SWING DISABLED, 1/ON=SWING ENABLED |
|
||||
| | | LockControl | Number, Switch | status of physical control lock. values: 0/OFF=CONTROL LOCK DISABLED, 1/ON=CONTROL LOCK ENABLED |
|
||||
| | ActiveStatus | | Switch | Accessory current working status. A value of "ON"/"OPEN" indicates that the accessory is active and is functioning without any errors. |
|
||||
| | | CurrentFanState | Number | Current fan state. values: 0=INACTIVE, 1=IDLE, 2=BLOWING AIR |
|
||||
| | | TargetFanState | Number | Target fan state. values: 0=MANUAL, 1=AUTO |
|
||||
| | | RotationDirection | Number, Switch | Rotation direction. values: 0/OFF=CLOCKWISE, 1/ON=COUNTER CLOCKWISE |
|
||||
| | | RotationSpeed | Number, Dimmer | Fan rotation speed in % (1-100) |
|
||||
| | | SwingMode | Number, Switch | Swing mode. values: 0/OFF=SWING DISABLED, 1/ON=SWING ENABLED |
|
||||
| | | LockControl | Number, Switch | Status of physical control lock. values: 0/OFF=CONTROL LOCK DISABLED, 1/ON=CONTROL LOCK ENABLED |
|
||||
| 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 |
|
||||
| | CurrentTemperature | | Number | Current temperature. supported configuration: minValue, maxValue, step |
|
||||
| | TargetTemperature | | Number | Target temperature. supported configuration: minValue, maxValue, step |
|
||||
| | CurrentHeatingCoolingMode | | String | Current heating cooling mode (OFF, AUTO, HEAT, COOL). for mapping see homekit settings above. |
|
||||
| | TargetHeatingCoolingMode | | String | Target heating cooling mode (OFF, AUTO, HEAT, COOL). for mapping see homekit settings above. |
|
||||
| | | Name | String | Name of the thermostat |
|
||||
| | | CoolingThresholdTemperature | Number | maximum temperature that must be reached before cooling is turned on. min/max/step can configured at item level, e.g. minValue=10.5, maxValue=50, step=2] |
|
||||
| | | HeatingThresholdTemperature | Number | minimum temperature that must be reached before heating is turned on. min/max/step can configured at item level, e.g. minValue=10.5, maxValue=50, step=2] |
|
||||
| | | CoolingThresholdTemperature | Number | Maximum temperature that must be reached before cooling is turned on. min/max/step can configured at item level, e.g. minValue=10.5, maxValue=50, step=2] |
|
||||
| | | HeatingThresholdTemperature | Number | Minimum temperature that must be reached before heating is turned on. min/max/step can configured at item level, e.g. minValue=10.5, maxValue=50, step=2] |
|
||||
| HeaterCooler | | | | Heater or/and cooler device |
|
||||
| | ActiveStatus | | Switch | accessory current working status. A value of "ON"/"OPEN" indicates that the accessory is active and is functioning without any errors. |
|
||||
| | CurrentTemperature | | Number | current temperature. supported configuration: minValue, maxValue, step |
|
||||
| | CurrentHeaterCoolerState | | String | current heater/cooler mode (INACTIVE, IDLE, HEATING, COOLING). Mapping can be redefined at item level, e.g. [HEATING="HEAT", COOLING="COOL"] |
|
||||
| | TargetHeaterCoolerState | | String | target heater/cooler mode (AUTO, HEAT, COOL). Mapping can be redefined at item level, e.g. [AUTO="AUTOMATIC"] |
|
||||
| | ActiveStatus | | Switch | Accessory current working status. A value of "ON"/"OPEN" indicates that the accessory is active and is functioning without any errors. |
|
||||
| | CurrentTemperature | | Number | Current temperature. supported configuration: minValue, maxValue, step |
|
||||
| | CurrentHeaterCoolerState | | String | Current heater/cooler mode (INACTIVE, IDLE, HEATING, COOLING). Mapping can be redefined at item level, e.g. [HEATING="HEAT", COOLING="COOL"] |
|
||||
| | TargetHeaterCoolerState | | String | Target heater/cooler mode (AUTO, HEAT, COOL). Mapping can be redefined at item level, e.g. [AUTO="AUTOMATIC"] |
|
||||
| | | Name | String | Name of the heater/cooler |
|
||||
| | | RotationSpeed | Number | fan rotation speed in % (1-100) |
|
||||
| | | SwingMode | Number, Switch | swing mode. values: 0/OFF=SWING DISABLED, 1/ON=SWING ENABLED |
|
||||
| | | LockControl | Number, Switch | status of physical control lock. values: 0/OFF=CONTROL LOCK DISABLED, 1/ON=CONTROL LOCK ENABLED |
|
||||
| | | CoolingThresholdTemperature | Number | maximum temperature that must be reached before cooling is turned on. min/max/step can configured at item level, e.g. minValue=10.5, maxValue=50, step=2] |
|
||||
| | | HeatingThresholdTemperature | Number | minimum temperature that must be reached before heating is turned on. min/max/step can configured at item level, e.g. minValue=10.5, maxValue=50, step=2] |
|
||||
| | | RotationSpeed | Number | Fan rotation speed in % (1-100) |
|
||||
| | | SwingMode | Number, Switch | Swing mode. values: 0/OFF=SWING DISABLED, 1/ON=SWING ENABLED |
|
||||
| | | LockControl | Number, Switch | Status of physical control lock. values: 0/OFF=CONTROL LOCK DISABLED, 1/ON=CONTROL LOCK ENABLED |
|
||||
| | | CoolingThresholdTemperature | Number | Maximum temperature that must be reached before cooling is turned on. min/max/step can configured at item level, e.g. minValue=10.5, maxValue=50, step=2] |
|
||||
| | | HeatingThresholdTemperature | Number | Minimum temperature that must be reached before heating is turned on. min/max/step can configured at item level, e.g. minValue=10.5, maxValue=50, step=2] |
|
||||
| Lock | | | | A Lock Mechanism. with flag [inverted="true"] the default mapping to switch ON/OFF can be inverted. |
|
||||
| | LockCurrentState | | Switch, Number | current state of lock mechanism (1/ON=SECURED, 0/OFF=UNSECURED, 2=JAMMED, 3=UNKNOWN) |
|
||||
| | LockTargetState | | Switch | target state of lock mechanism (ON=SECURED, OFF=UNSECURED) |
|
||||
| | LockCurrentState | | Switch, Number | Current state of lock mechanism (1/ON=SECURED, 0/OFF=UNSECURED, 2=JAMMED, 3=UNKNOWN) |
|
||||
| | LockTargetState | | Switch | Target state of lock mechanism (ON=SECURED, OFF=UNSECURED) |
|
||||
| | | Name | String | Name of the lock |
|
||||
| Valve | | | | Valve. additional configuration: homekitValveType = ["Generic", "Irrigation", "Shower", "Faucet"] |
|
||||
| | ActiveStatus | | Switch | accessory current working status. A value of "ON"/"OPEN" indicates that the accessory is active and is functioning without any errors. |
|
||||
| | InUseStatus | | Switch | indicates whether fluid flowing through the valve. A value of "ON"/"OPEN" indicates that fluid is flowing. |
|
||||
| | | Duration | Number | defines how long a valve should be set to ʼIn Useʼ in second. You can define the default duration via configuration homekitDefaultDuration = <default duration in seconds> |
|
||||
| | | RemainingDuration | Number | describes the remaining duration on the accessory. the remaining duration increases/decreases from the accessoryʼs usual countdown. i.e. changes from 90 to 80 in a second. |
|
||||
| | | Name | String | Name of the lock |
|
||||
| | | FaultStatus | Switch, Contact | accessory fault status. "ON"/"OPEN" value indicates that the accessory has experienced a fault that may be interfering with its intended functionality. A value of "OFF"/"CLOSED" indicates that there is no fault. |
|
||||
| | ActiveStatus | | Switch | Accessory current working status. A value of "ON"/"OPEN" indicates that the accessory is active and is functioning without any errors. |
|
||||
| | InUseStatus | | Switch | Indicates whether fluid flowing through the valve. A value of "ON"/"OPEN" indicates that fluid is flowing. |
|
||||
| | | Duration | Number | Defines how long a valve should be set to ʼIn Useʼ in second. You can define the default duration via configuration homekitDefaultDuration = <default duration in seconds> |
|
||||
| | | RemainingDuration | Number | Describes the remaining duration on the accessory. the remaining duration increases/decreases from the accessoryʼs usual countdown. i.e. changes from 90 to 80 in a second. |
|
||||
| | | Name | String | Name of the valve |
|
||||
| | | FaultStatus | Switch, Contact | Accessory fault status. "ON"/"OPEN" value indicates that the accessory has experienced a fault that may be interfering with its intended functionality. A value of "OFF"/"CLOSED" indicates that there is no fault. |
|
||||
| Faucet | | | | Faucet or shower. It should be used in combination with Valve or/and HeaterCooler. |
|
||||
| | Active | | Switch | Accessory current working status. A value of "ON"/"OPEN" indicates faucet/shower is open. |
|
||||
| | | Name | String | Name of the Faucet |
|
||||
| | | FaultStatus | Switch, Contact | Accessory fault status. "ON"/"OPEN" value indicates that the accessory has experienced a fault that may be interfering with its intended functionality. A value of "OFF"/"CLOSED" indicates that there is no fault. |
|
||||
| SecuritySystem | | | | Security system. |
|
||||
| | CurrentSecuritySystemState | | String | Current state of the security system. STAY_ARM / AWAY_ARM / NIGHT_ARM / DISARMED / TRIGGERED. Mapping can be redefined at item level, e.g. [AWAY_ARM="AWAY", NIGHT_ARM="NIGHT" ] |
|
||||
| | TargetSecuritySystemState | | String | Requested state of the security system. STAY_ARM / AWAY_ARM / NIGHT_ARM / DISARM. While the requested state is not DISARM, and the current state is DISARMED, HomeKit will display "Arming...", for example during an exit delay. Mapping can be redefined at item level, e.g. [AWAY_ARM="AWAY", NIGHT_ARM="NIGHT" ] |
|
||||
@ -705,6 +722,32 @@ Support for this is planned for the future release of openHAB HomeKit binding.
|
||||
| | | Name | String | Name of the garage door |
|
||||
| | | LockCurrentState | Switch | current states of lock mechanism (OFF=SECURED, ON=UNSECURED) |
|
||||
| | | LockTargetState | Switch | target states of lock mechanism (OFF=SECURED, ON=UNSECURED) |
|
||||
| Battery | | | | Accessory with battery. Battery can be chargeable (configuration chargeable:true) and non-chargeable (configuration chargeable:false) |
|
||||
| | BatteryLevel | | Number | Battery level 0% to 100% |
|
||||
| | BatteryLowStatus | | Switch, Contact | Battery low indicator. ON/OPEN = battery level is low. |
|
||||
| | BatteryChargingState | | Switch, Contact | Mandatory only for chargeable battery. ON/OPEN = battery is charging |
|
||||
| | | Name | String | Name of the battery accessory |
|
||||
| Filter | | | | Accessory with filter maintenance indicator |
|
||||
| | FilterChangeIndication | | Switch, Contact | Filter change indicator. ON/OPEN = filter change is required. |
|
||||
| | | FilterLifeLevel | Number | Current filter life level. 0% to 100% |
|
||||
| | | FilterResetIndication | Switch | Send "filter reset" action triggered by user in iOS home app to openHAB ("ON" = reset requested by user). |
|
||||
| | | Name | String | Name of the filter accessory |
|
||||
| Microphone | | | | Microphone accessory |
|
||||
| | Mute | | Switch, Contact | Mute indication. ON/OPEN = microphone is muted |
|
||||
| | | Name | String | Name of the microphone accessory |
|
||||
| | | Volume | Number | Microphone volume from 0% to 100% |
|
||||
| Speaker | | | | Speaker accessory |
|
||||
| | Mute | | Switch, Contact | Mute indication. ON/OPEN = speaker is muted |
|
||||
| | | Name | String | Name of the speaker accessory |
|
||||
| | | Volume | Number | Speaker volume from 0% to 100% |
|
||||
| | | Active | Switch, Contact | Working status |
|
||||
| SmartSpeaker | | | | Smart speaker accessory with Play/Stop/Pause control |
|
||||
| | CurrentMediaState | | String | Current smart speaker state. possible values (STOP,PLAY,PAUSE,UNKNOWN). Custom mapping can be defined at item level, e.g. [STOP="STOPPED", PLAY="PLAYING"] |
|
||||
| | TargetMediaState | | String | Target smart speaker state. possible values (STOP,PLAY,PAUSE). Custom mapping can be defined at item level, e.g. [STOP="STOPPED", PLAY="PLAYING"] |
|
||||
| | | Mute | Switch, Contact | Mute indication. ON/OPEN = speaker is muted |
|
||||
| | | Name | String | Name of the speaker accessory |
|
||||
| | | ConfiguredName | String | Name of the speaker accessory configured in iOS home app. User can rename speaker in iOS home app and this characteristic can be used to reflect change in openHAB and sync name changes from openHAB to home app. |
|
||||
| | | Volume | Number | Speaker volume from 0% to 100% |
|
||||
|
||||
### Examples
|
||||
|
||||
|
@ -44,10 +44,16 @@ public enum HomekitAccessoryType {
|
||||
SECURITY_SYSTEM("SecuritySystem"),
|
||||
OUTLET("Outlet"),
|
||||
SPEAKER("Speaker"),
|
||||
SMART_SPEAKER("SmartSpeaker"),
|
||||
GARAGE_DOOR_OPENER("GarageDoorOpener"),
|
||||
HEATER_COOLER("HeaterCooler"),
|
||||
LIGHT_SENSOR("LightSensor"),
|
||||
AIR_QUALITY_SENSOR("AirQualitySensor"),
|
||||
BATTERY("Battery"),
|
||||
FILTER_MAINTENANCE("Filter"),
|
||||
FAUCET("Faucet"),
|
||||
MICROPHONE("Microphone"),
|
||||
SLAT("Slat"),
|
||||
DUMMY("Dummy");
|
||||
|
||||
private static final Map<String, HomekitAccessoryType> TAG_MAP = new HashMap<>();
|
||||
|
@ -62,6 +62,8 @@ public enum HomekitCharacteristicType {
|
||||
CURRENT_VERTICAL_TILT_ANGLE("CurrentVerticalTiltAngle"),
|
||||
TARGET_HORIZONTAL_TILT_ANGLE("TargetHorizontalTiltAngle"),
|
||||
TARGET_VERTICAL_TILT_ANGLE("TargetVerticalTiltAngle"),
|
||||
CURRENT_TILT_ANGLE("CurrentTiltAngle"),
|
||||
TARGET_TILT_ANGLE("TargetTiltAngle"),
|
||||
|
||||
HUE("Hue"),
|
||||
BRIGHTNESS("Brightness"),
|
||||
@ -107,7 +109,22 @@ public enum HomekitCharacteristicType {
|
||||
SULPHUR_DIOXIDE_DENSITY("SulphurDioxideDensity"),
|
||||
PM25_DENSITY("PM25Density"),
|
||||
PM10_DENSITY("PM10Density"),
|
||||
VOC_DENSITY("VOCDensity");
|
||||
VOC_DENSITY("VOCDensity"),
|
||||
|
||||
BATTERY_LEVEL("BatteryLevel"),
|
||||
BATTERY_CHARGING_STATE("BatteryChargingState"),
|
||||
|
||||
CURRENT_SLAT_STATE("CurrentSlatState"),
|
||||
|
||||
CURRENT_MEDIA_STATE("CurrentMediaState"),
|
||||
TARGET_MEDIA_STATE("TargetMediaState"),
|
||||
CONFIGURED_NAME("ConfiguredName"),
|
||||
|
||||
ACTIVE("Active"),
|
||||
|
||||
FILTER_CHANGE_INDICATION("FilterChangeIndication"),
|
||||
FILTER_LIFE_LEVEL("FilterLifeLevel"),
|
||||
FILTER_RESET_INDICATION("FilterResetIndication");
|
||||
|
||||
private static final Map<String, HomekitCharacteristicType> TAG_MAP = new HashMap<>();
|
||||
|
||||
|
@ -89,12 +89,18 @@ public class HomekitAccessoryFactory {
|
||||
new HomekitCharacteristicType[] { SECURITY_SYSTEM_CURRENT_STATE, SECURITY_SYSTEM_TARGET_STATE });
|
||||
put(OUTLET, new HomekitCharacteristicType[] { ON_STATE, INUSE_STATUS });
|
||||
put(SPEAKER, new HomekitCharacteristicType[] { MUTE });
|
||||
put(SMART_SPEAKER, new HomekitCharacteristicType[] { CURRENT_MEDIA_STATE, TARGET_MEDIA_STATE });
|
||||
put(GARAGE_DOOR_OPENER,
|
||||
new HomekitCharacteristicType[] { CURRENT_DOOR_STATE, TARGET_DOOR_STATE, OBSTRUCTION_STATUS });
|
||||
put(HEATER_COOLER, new HomekitCharacteristicType[] { ACTIVE_STATUS, CURRENT_HEATER_COOLER_STATE,
|
||||
TARGET_HEATER_COOLER_STATE, CURRENT_TEMPERATURE });
|
||||
put(WINDOW, new HomekitCharacteristicType[] { CURRENT_POSITION, TARGET_POSITION, POSITION_STATE });
|
||||
put(DOOR, new HomekitCharacteristicType[] { CURRENT_POSITION, TARGET_POSITION, POSITION_STATE });
|
||||
put(BATTERY, new HomekitCharacteristicType[] { BATTERY_LEVEL, BATTERY_LOW_STATUS });
|
||||
put(FILTER_MAINTENANCE, new HomekitCharacteristicType[] { FILTER_CHANGE_INDICATION });
|
||||
put(SLAT, new HomekitCharacteristicType[] { CURRENT_SLAT_STATE });
|
||||
put(FAUCET, new HomekitCharacteristicType[] { ACTIVE_STATUS });
|
||||
put(MICROPHONE, new HomekitCharacteristicType[] { MUTE });
|
||||
}
|
||||
};
|
||||
|
||||
@ -122,10 +128,16 @@ public class HomekitAccessoryFactory {
|
||||
put(SECURITY_SYSTEM, HomekitSecuritySystemImpl.class);
|
||||
put(OUTLET, HomekitOutletImpl.class);
|
||||
put(SPEAKER, HomekitSpeakerImpl.class);
|
||||
put(SMART_SPEAKER, HomekitSmartSpeakerImpl.class);
|
||||
put(GARAGE_DOOR_OPENER, HomekitGarageDoorOpenerImpl.class);
|
||||
put(DOOR, HomekitDoorImpl.class);
|
||||
put(WINDOW, HomekitWindowImpl.class);
|
||||
put(HEATER_COOLER, HomekitHeaterCoolerImpl.class);
|
||||
put(BATTERY, HomekitBatteryImpl.class);
|
||||
put(FILTER_MAINTENANCE, HomekitFilterMaintenanceImpl.class);
|
||||
put(SLAT, HomekitSlatImpl.class);
|
||||
put(FAUCET, HomekitFaucetImpl.class);
|
||||
put(MICROPHONE, HomekitMicrophoneImpl.class);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -0,0 +1,107 @@
|
||||
/**
|
||||
* 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.BATTERY_CHARGING_STATE;
|
||||
import static org.openhab.io.homekit.internal.HomekitCharacteristicType.BATTERY_LEVEL;
|
||||
import static org.openhab.io.homekit.internal.HomekitCharacteristicType.BATTERY_LOW_STATUS;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
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.BatteryAccessory;
|
||||
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
|
||||
import io.github.hapjava.characteristics.impl.battery.ChargingStateEnum;
|
||||
import io.github.hapjava.characteristics.impl.battery.StatusLowBatteryEnum;
|
||||
import io.github.hapjava.services.impl.BatteryService;
|
||||
|
||||
/**
|
||||
* Implements battery services for chargeable and non-chargeable batteries
|
||||
*
|
||||
* @author Eugen Freiter - Initial contribution
|
||||
*/
|
||||
public class HomekitBatteryImpl extends AbstractHomekitAccessoryImpl implements BatteryAccessory {
|
||||
private static final String BATTERY_TYPE = "chargeable";
|
||||
|
||||
private final BooleanItemReader lowBatteryReader;
|
||||
private BooleanItemReader chargingBatteryReader;
|
||||
private final boolean isChargeable;
|
||||
|
||||
public HomekitBatteryImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
|
||||
HomekitAccessoryUpdater updater, HomekitSettings settings) throws IncompleteAccessoryException {
|
||||
super(taggedItem, mandatoryCharacteristics, updater, settings);
|
||||
lowBatteryReader = createBooleanReader(BATTERY_LOW_STATUS);
|
||||
final String batteryTypeConfig = getAccessoryConfiguration(BATTERY_TYPE, "false");
|
||||
isChargeable = "true".equalsIgnoreCase(batteryTypeConfig) || "yes".equalsIgnoreCase(batteryTypeConfig);
|
||||
if (isChargeable) {
|
||||
chargingBatteryReader = createBooleanReader(BATTERY_CHARGING_STATE);
|
||||
}
|
||||
getServices().add(new BatteryService(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Integer> getBatteryLevel() {
|
||||
final @Nullable DecimalType state = getStateAs(BATTERY_LEVEL, DecimalType.class);
|
||||
return CompletableFuture.completedFuture(state != null ? state.intValue() : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<StatusLowBatteryEnum> getLowBatteryState() {
|
||||
return CompletableFuture
|
||||
.completedFuture(lowBatteryReader.getValue() ? StatusLowBatteryEnum.LOW : StatusLowBatteryEnum.NORMAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ChargingStateEnum> getChargingState() {
|
||||
return CompletableFuture.completedFuture(isChargeable
|
||||
? chargingBatteryReader.getValue() ? ChargingStateEnum.CHARGING : ChargingStateEnum.NOT_CHARGING
|
||||
: ChargingStateEnum.NOT_CHARABLE); // the mapping to NOT_CHARABLE is correct, there is a typo in java
|
||||
// HAP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribeBatteryLevel(final HomekitCharacteristicChangeCallback callback) {
|
||||
subscribe(BATTERY_LEVEL, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribeLowBatteryState(final HomekitCharacteristicChangeCallback callback) {
|
||||
subscribe(BATTERY_LOW_STATUS, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribeBatteryChargingState(final HomekitCharacteristicChangeCallback callback) {
|
||||
subscribe(BATTERY_CHARGING_STATE, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribeBatteryLevel() {
|
||||
unsubscribe(BATTERY_LEVEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribeLowBatteryState() {
|
||||
unsubscribe(BATTERY_LOW_STATUS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribeBatteryChargingState() {
|
||||
unsubscribe(BATTERY_CHARGING_STATE);
|
||||
}
|
||||
}
|
@ -33,6 +33,7 @@ import org.openhab.core.items.Item;
|
||||
import org.openhab.core.library.items.ColorItem;
|
||||
import org.openhab.core.library.items.DimmerItem;
|
||||
import org.openhab.core.library.items.NumberItem;
|
||||
import org.openhab.core.library.items.StringItem;
|
||||
import org.openhab.core.library.items.SwitchItem;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.library.types.HSBType;
|
||||
@ -40,6 +41,7 @@ import org.openhab.core.library.types.OnOffType;
|
||||
import org.openhab.core.library.types.OpenClosedType;
|
||||
import org.openhab.core.library.types.PercentType;
|
||||
import org.openhab.core.library.types.QuantityType;
|
||||
import org.openhab.core.library.types.StringType;
|
||||
import org.openhab.core.library.unit.ImperialUnits;
|
||||
import org.openhab.core.library.unit.SIUnits;
|
||||
import org.openhab.core.types.State;
|
||||
@ -72,6 +74,9 @@ import io.github.hapjava.characteristics.impl.carbondioxidesensor.CarbonDioxideL
|
||||
import io.github.hapjava.characteristics.impl.carbondioxidesensor.CarbonDioxidePeakLevelCharacteristic;
|
||||
import io.github.hapjava.characteristics.impl.carbonmonoxidesensor.CarbonMonoxideLevelCharacteristic;
|
||||
import io.github.hapjava.characteristics.impl.carbonmonoxidesensor.CarbonMonoxidePeakLevelCharacteristic;
|
||||
import io.github.hapjava.characteristics.impl.common.ActiveCharacteristic;
|
||||
import io.github.hapjava.characteristics.impl.common.ActiveEnum;
|
||||
import io.github.hapjava.characteristics.impl.common.ConfiguredNameCharacteristic;
|
||||
import io.github.hapjava.characteristics.impl.common.NameCharacteristic;
|
||||
import io.github.hapjava.characteristics.impl.common.ObstructionDetectedCharacteristic;
|
||||
import io.github.hapjava.characteristics.impl.common.StatusActiveCharacteristic;
|
||||
@ -90,10 +95,14 @@ import io.github.hapjava.characteristics.impl.fan.SwingModeCharacteristic;
|
||||
import io.github.hapjava.characteristics.impl.fan.SwingModeEnum;
|
||||
import io.github.hapjava.characteristics.impl.fan.TargetFanStateCharacteristic;
|
||||
import io.github.hapjava.characteristics.impl.fan.TargetFanStateEnum;
|
||||
import io.github.hapjava.characteristics.impl.filtermaintenance.FilterLifeLevelCharacteristic;
|
||||
import io.github.hapjava.characteristics.impl.filtermaintenance.ResetFilterIndicationCharacteristic;
|
||||
import io.github.hapjava.characteristics.impl.lightbulb.BrightnessCharacteristic;
|
||||
import io.github.hapjava.characteristics.impl.lightbulb.ColorTemperatureCharacteristic;
|
||||
import io.github.hapjava.characteristics.impl.lightbulb.HueCharacteristic;
|
||||
import io.github.hapjava.characteristics.impl.lightbulb.SaturationCharacteristic;
|
||||
import io.github.hapjava.characteristics.impl.slat.CurrentTiltAngleCharacteristic;
|
||||
import io.github.hapjava.characteristics.impl.slat.TargetTiltAngleCharacteristic;
|
||||
import io.github.hapjava.characteristics.impl.thermostat.CoolingThresholdTemperatureCharacteristic;
|
||||
import io.github.hapjava.characteristics.impl.thermostat.HeatingThresholdTemperatureCharacteristic;
|
||||
import io.github.hapjava.characteristics.impl.valve.RemainingDurationCharacteristic;
|
||||
@ -135,6 +144,8 @@ public class HomekitCharacteristicFactory {
|
||||
put(TARGET_HORIZONTAL_TILT_ANGLE,
|
||||
HomekitCharacteristicFactory::createTargetHorizontalTiltAngleCharacteristic);
|
||||
put(TARGET_VERTICAL_TILT_ANGLE, HomekitCharacteristicFactory::createTargetVerticalTiltAngleCharacteristic);
|
||||
put(CURRENT_TILT_ANGLE, HomekitCharacteristicFactory::createCurrentTiltAngleCharacteristic);
|
||||
put(TARGET_TILT_ANGLE, HomekitCharacteristicFactory::createTargetTiltAngleCharacteristic);
|
||||
put(HUE, HomekitCharacteristicFactory::createHueCharacteristic);
|
||||
put(BRIGHTNESS, HomekitCharacteristicFactory::createBrightnessCharacteristic);
|
||||
put(SATURATION, HomekitCharacteristicFactory::createSaturationCharacteristic);
|
||||
@ -156,6 +167,10 @@ public class HomekitCharacteristicFactory {
|
||||
put(PM25_DENSITY, HomekitCharacteristicFactory::createPM25DensityCharacteristic);
|
||||
put(PM10_DENSITY, HomekitCharacteristicFactory::createPM10DensityCharacteristic);
|
||||
put(VOC_DENSITY, HomekitCharacteristicFactory::createVOCDensityCharacteristic);
|
||||
put(FILTER_LIFE_LEVEL, HomekitCharacteristicFactory::createFilterLifeLevelCharacteristic);
|
||||
put(FILTER_RESET_INDICATION, HomekitCharacteristicFactory::createFilterResetCharacteristic);
|
||||
put(ACTIVE, HomekitCharacteristicFactory::createActiveCharacteristic);
|
||||
put(CONFIGURED_NAME, HomekitCharacteristicFactory::createConfiguredNameCharacteristic);
|
||||
}
|
||||
};
|
||||
|
||||
@ -512,6 +527,20 @@ public class HomekitCharacteristicFactory {
|
||||
getUnsubscriber(taggedItem, TARGET_HORIZONTAL_TILT_ANGLE, updater));
|
||||
}
|
||||
|
||||
private static CurrentTiltAngleCharacteristic createCurrentTiltAngleCharacteristic(HomekitTaggedItem taggedItem,
|
||||
HomekitAccessoryUpdater updater) {
|
||||
return new CurrentTiltAngleCharacteristic(getAngleSupplier(taggedItem, 0),
|
||||
getSubscriber(taggedItem, CURRENT_TILT_ANGLE, updater),
|
||||
getUnsubscriber(taggedItem, CURRENT_TILT_ANGLE, updater));
|
||||
}
|
||||
|
||||
private static TargetTiltAngleCharacteristic createTargetTiltAngleCharacteristic(HomekitTaggedItem taggedItem,
|
||||
HomekitAccessoryUpdater updater) {
|
||||
return new TargetTiltAngleCharacteristic(getAngleSupplier(taggedItem, 0), setAngleConsumer(taggedItem),
|
||||
getSubscriber(taggedItem, TARGET_TILT_ANGLE, updater),
|
||||
getUnsubscriber(taggedItem, TARGET_TILT_ANGLE, updater));
|
||||
}
|
||||
|
||||
private static HueCharacteristic createHueCharacteristic(HomekitTaggedItem taggedItem,
|
||||
HomekitAccessoryUpdater updater) {
|
||||
return new HueCharacteristic(() -> {
|
||||
@ -783,4 +812,36 @@ public class HomekitCharacteristicFactory {
|
||||
VOCDensityCharacteristic.DEFAULT_MIN_VALUE)),
|
||||
getSubscriber(taggedItem, VOC_DENSITY, updater), getUnsubscriber(taggedItem, VOC_DENSITY, updater));
|
||||
}
|
||||
|
||||
private static FilterLifeLevelCharacteristic createFilterLifeLevelCharacteristic(HomekitTaggedItem taggedItem,
|
||||
HomekitAccessoryUpdater updater) {
|
||||
return new FilterLifeLevelCharacteristic(getDoubleSupplier(taggedItem, 0),
|
||||
getSubscriber(taggedItem, FILTER_LIFE_LEVEL, updater),
|
||||
getUnsubscriber(taggedItem, FILTER_LIFE_LEVEL, updater));
|
||||
}
|
||||
|
||||
private static ResetFilterIndicationCharacteristic createFilterResetCharacteristic(HomekitTaggedItem taggedItem,
|
||||
HomekitAccessoryUpdater updater) {
|
||||
return new ResetFilterIndicationCharacteristic(
|
||||
(value) -> ((SwitchItem) taggedItem.getItem()).send(OnOffType.ON));
|
||||
}
|
||||
|
||||
private static ActiveCharacteristic createActiveCharacteristic(HomekitTaggedItem taggedItem,
|
||||
HomekitAccessoryUpdater updater) {
|
||||
return new ActiveCharacteristic(
|
||||
() -> getEnumFromItem(taggedItem, ActiveEnum.ACTIVE, ActiveEnum.INACTIVE, ActiveEnum.INACTIVE),
|
||||
(value) -> setValueFromEnum(taggedItem, value, ActiveEnum.ACTIVE, ActiveEnum.INACTIVE),
|
||||
getSubscriber(taggedItem, ACTIVE, updater), getUnsubscriber(taggedItem, ACTIVE, updater));
|
||||
}
|
||||
|
||||
private static ConfiguredNameCharacteristic createConfiguredNameCharacteristic(HomekitTaggedItem taggedItem,
|
||||
HomekitAccessoryUpdater updater) {
|
||||
return new ConfiguredNameCharacteristic(() -> {
|
||||
final State state = taggedItem.getItem().getState();
|
||||
return CompletableFuture
|
||||
.completedFuture(state instanceof UnDefType ? taggedItem.getName() : state.toString());
|
||||
}, (value) -> ((StringItem) taggedItem.getItem()).send(new StringType(value)),
|
||||
getSubscriber(taggedItem, CONFIGURED_NAME, updater),
|
||||
getUnsubscriber(taggedItem, CONFIGURED_NAME, updater));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,63 @@
|
||||
/**
|
||||
* 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.ACTIVE;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
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.FaucetAccessory;
|
||||
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
|
||||
import io.github.hapjava.services.impl.FaucetService;
|
||||
|
||||
/**
|
||||
* Implements Faucet using an Item that provides an On/Off state
|
||||
*
|
||||
* @author Eugen Freiter - Initial contribution
|
||||
*/
|
||||
class HomekitFaucetImpl extends AbstractHomekitAccessoryImpl implements FaucetAccessory {
|
||||
private final BooleanItemReader activeReader;
|
||||
|
||||
public HomekitFaucetImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
|
||||
HomekitAccessoryUpdater updater, HomekitSettings settings) throws IncompleteAccessoryException {
|
||||
super(taggedItem, mandatoryCharacteristics, updater, settings);
|
||||
activeReader = createBooleanReader(ACTIVE);
|
||||
this.getServices().add(new FaucetService(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> isActive() {
|
||||
return CompletableFuture.completedFuture(activeReader.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> setActive(boolean state) {
|
||||
activeReader.setValue(state);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribeActive(HomekitCharacteristicChangeCallback callback) {
|
||||
subscribe(ACTIVE, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribeActive() {
|
||||
unsubscribe(ACTIVE);
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/**
|
||||
* 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.FILTER_CHANGE_INDICATION;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
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.FilterMaintenanceAccessory;
|
||||
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
|
||||
import io.github.hapjava.characteristics.impl.filtermaintenance.FilterChangeIndicationEnum;
|
||||
import io.github.hapjava.services.impl.FilterMaintenanceService;
|
||||
|
||||
/**
|
||||
* Implements filter maintenance indicator
|
||||
*
|
||||
* @author Eugen Freiter - Initial contribution
|
||||
*/
|
||||
public class HomekitFilterMaintenanceImpl extends AbstractHomekitAccessoryImpl implements FilterMaintenanceAccessory {
|
||||
private BooleanItemReader filterChangeIndication;
|
||||
|
||||
public HomekitFilterMaintenanceImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
|
||||
HomekitAccessoryUpdater updater, HomekitSettings settings) throws IncompleteAccessoryException {
|
||||
super(taggedItem, mandatoryCharacteristics, updater, settings);
|
||||
filterChangeIndication = createBooleanReader(FILTER_CHANGE_INDICATION);
|
||||
getServices().add(new FilterMaintenanceService(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<FilterChangeIndicationEnum> getFilterChangeIndication() {
|
||||
return CompletableFuture
|
||||
.completedFuture(filterChangeIndication.getValue() ? FilterChangeIndicationEnum.CHANGE_NEEDED
|
||||
: FilterChangeIndicationEnum.NO_CHANGE_NEEDED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribeFilterChangeIndication(final HomekitCharacteristicChangeCallback callback) {
|
||||
subscribe(FILTER_CHANGE_INDICATION, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribeFilterChangeIndication() {
|
||||
unsubscribe(FILTER_CHANGE_INDICATION);
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
/**
|
||||
* 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 java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.openhab.io.homekit.internal.HomekitAccessoryUpdater;
|
||||
import org.openhab.io.homekit.internal.HomekitCharacteristicType;
|
||||
import org.openhab.io.homekit.internal.HomekitSettings;
|
||||
import org.openhab.io.homekit.internal.HomekitTaggedItem;
|
||||
|
||||
import io.github.hapjava.accessories.MicrophoneAccessory;
|
||||
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
|
||||
import io.github.hapjava.services.impl.MicrophoneService;
|
||||
|
||||
/**
|
||||
* Implements microphone using an item that provides an On/Off state for Mute.
|
||||
*
|
||||
* @author Eugen Freiter - Initial contribution
|
||||
*/
|
||||
public class HomekitMicrophoneImpl extends AbstractHomekitAccessoryImpl implements MicrophoneAccessory {
|
||||
private final BooleanItemReader muteReader;
|
||||
|
||||
public HomekitMicrophoneImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
|
||||
HomekitAccessoryUpdater updater, HomekitSettings settings) throws IncompleteAccessoryException {
|
||||
super(taggedItem, mandatoryCharacteristics, updater, settings);
|
||||
muteReader = createBooleanReader(HomekitCharacteristicType.MUTE);
|
||||
getServices().add(new MicrophoneService(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Boolean> isMuted() {
|
||||
return CompletableFuture.completedFuture(muteReader.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> setMute(boolean state) {
|
||||
muteReader.setValue(state);
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribeMuteState(HomekitCharacteristicChangeCallback callback) {
|
||||
subscribe(HomekitCharacteristicType.MUTE, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribeMuteState() {
|
||||
unsubscribe(HomekitCharacteristicType.MUTE);
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
/**
|
||||
* 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.CURRENT_SLAT_STATE;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
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.SlatAccessory;
|
||||
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
|
||||
import io.github.hapjava.characteristics.impl.slat.CurrentSlatStateEnum;
|
||||
import io.github.hapjava.characteristics.impl.slat.SlatTypeEnum;
|
||||
import io.github.hapjava.services.impl.SlatService;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Eugen Freiter - Initial contribution
|
||||
*/
|
||||
public class HomekitSlatImpl extends AbstractHomekitAccessoryImpl implements SlatAccessory {
|
||||
private static final String CONFIG_TYPE = "type";
|
||||
private final Map<CurrentSlatStateEnum, String> currentSlatStateMapping;
|
||||
private final SlatTypeEnum slatType;
|
||||
|
||||
public HomekitSlatImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
|
||||
HomekitAccessoryUpdater updater, HomekitSettings settings) {
|
||||
super(taggedItem, mandatoryCharacteristics, updater, settings);
|
||||
final String slatTypeConfig = getAccessoryConfiguration(CONFIG_TYPE, "horizontal");
|
||||
slatType = "horizontal".equalsIgnoreCase(slatTypeConfig) ? SlatTypeEnum.HORIZONTAL : SlatTypeEnum.VERTICAL;
|
||||
currentSlatStateMapping = new EnumMap<>(CurrentSlatStateEnum.class);
|
||||
currentSlatStateMapping.put(CurrentSlatStateEnum.FIXED, "FIXED");
|
||||
currentSlatStateMapping.put(CurrentSlatStateEnum.SWINGING, "SWINGING");
|
||||
currentSlatStateMapping.put(CurrentSlatStateEnum.JAMMED, "JAMMED");
|
||||
updateMapping(CURRENT_SLAT_STATE, currentSlatStateMapping);
|
||||
getServices().add(new SlatService(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CurrentSlatStateEnum> getSlatState() {
|
||||
return CompletableFuture.completedFuture(
|
||||
getKeyFromMapping(CURRENT_SLAT_STATE, currentSlatStateMapping, CurrentSlatStateEnum.FIXED));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribeSlatState(final HomekitCharacteristicChangeCallback callback) {
|
||||
subscribe(CURRENT_SLAT_STATE, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribeSlatState() {
|
||||
unsubscribe(CURRENT_SLAT_STATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<SlatTypeEnum> getSlatType() {
|
||||
return CompletableFuture.completedFuture(slatType);
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
/**
|
||||
* 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.CURRENT_MEDIA_STATE;
|
||||
import static org.openhab.io.homekit.internal.HomekitCharacteristicType.TARGET_MEDIA_STATE;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.openhab.core.library.items.StringItem;
|
||||
import org.openhab.core.library.types.StringType;
|
||||
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.SmartSpeakerAccessory;
|
||||
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
|
||||
import io.github.hapjava.characteristics.impl.television.CurrentMediaStateEnum;
|
||||
import io.github.hapjava.characteristics.impl.television.TargetMediaStateEnum;
|
||||
import io.github.hapjava.services.impl.SmartSpeakerService;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Eugen Freiter - Initial contribution
|
||||
*/
|
||||
public class HomekitSmartSpeakerImpl extends AbstractHomekitAccessoryImpl implements SmartSpeakerAccessory {
|
||||
private final Map<CurrentMediaStateEnum, String> currentMediaState;
|
||||
private final Map<TargetMediaStateEnum, String> targetMediaState;
|
||||
|
||||
public HomekitSmartSpeakerImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
|
||||
HomekitAccessoryUpdater updater, HomekitSettings settings) {
|
||||
super(taggedItem, mandatoryCharacteristics, updater, settings);
|
||||
currentMediaState = new EnumMap<>(CurrentMediaStateEnum.class);
|
||||
currentMediaState.put(CurrentMediaStateEnum.STOP, "STOP");
|
||||
currentMediaState.put(CurrentMediaStateEnum.PLAY, "PLAY");
|
||||
currentMediaState.put(CurrentMediaStateEnum.PAUSE, "PAUSE");
|
||||
currentMediaState.put(CurrentMediaStateEnum.UNKNOWN, "UNKNOWN");
|
||||
updateMapping(CURRENT_MEDIA_STATE, currentMediaState);
|
||||
|
||||
targetMediaState = new EnumMap<>(TargetMediaStateEnum.class);
|
||||
targetMediaState.put(TargetMediaStateEnum.STOP, "STOP");
|
||||
targetMediaState.put(TargetMediaStateEnum.PLAY, "PLAY");
|
||||
targetMediaState.put(TargetMediaStateEnum.PAUSE, "PAUSE");
|
||||
updateMapping(TARGET_MEDIA_STATE, targetMediaState);
|
||||
getServices().add(new SmartSpeakerService(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<CurrentMediaStateEnum> getCurrentMediaState() {
|
||||
return CompletableFuture.completedFuture(
|
||||
getKeyFromMapping(CURRENT_MEDIA_STATE, currentMediaState, CurrentMediaStateEnum.UNKNOWN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribeCurrentMediaState(final HomekitCharacteristicChangeCallback callback) {
|
||||
subscribe(CURRENT_MEDIA_STATE, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribeCurrentMediaState() {
|
||||
unsubscribe(CURRENT_MEDIA_STATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<TargetMediaStateEnum> getTargetMediaState() {
|
||||
return CompletableFuture
|
||||
.completedFuture(getKeyFromMapping(TARGET_MEDIA_STATE, targetMediaState, TargetMediaStateEnum.STOP));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> setTargetMediaState(final TargetMediaStateEnum targetState) {
|
||||
getItem(TARGET_MEDIA_STATE, StringItem.class)
|
||||
.ifPresent(item -> item.send(new StringType(targetMediaState.get(targetState))));
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subscribeTargetMediaState(final HomekitCharacteristicChangeCallback callback) {
|
||||
subscribe(TARGET_MEDIA_STATE, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsubscribeTargetMediaState() {
|
||||
unsubscribe(TARGET_MEDIA_STATE);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user