diff --git a/bundles/org.openhab.io.homekit/README.md b/bundles/org.openhab.io.homekit/README.md index 6788ebbfd784c..00b7ffb9b0222 100644 --- a/bundles/org.openhab.io.homekit/README.md +++ b/bundles/org.openhab.io.homekit/README.md @@ -124,77 +124,86 @@ Switch leaksensor "Leak Sensor" Switch leaksensor_battery "Leak Sensor Battery" (gLeakSensor) {homekit="LeakSensor.BatteryLowStatus"} ``` +### Supported Accessories + A full list of supported accessory types can be found in the table *below*. -| Accessory Tag | Mandatory Characteristics | Optional Characteristics | Supported OH items | Description | -|:---------------------|:----------------------------|:-----------------------------|:-------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| LeakSensor | | | | Leak Sensor | -| | LeakDetectedState | | Switch, Contact | Leak sensor state (ON=Leak Detected, OFF=no leak | -| | | Name | String | Name of the sensor | -| | | ActiveStatus | Switch, Contact | accessory current working status. A value of "ON"/"OPEN" indicate that the accessory is active and is functioning without any errors. | -| | | 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. | -| | | TamperedStatus | Switch, Contact | accessory tampered status. A status of "ON"/"OPEN" indicates that the accessory has been tampered with. Value should return to "OFF"/"CLOSED" when the accessory has been reset to a non-tampered state. | -| | | BatteryLowStatus | Switch, Contact | accessory battery status. A value of "ON"/"OPEN" indicate that the battery level of the accessory is low. Value should return to "OFF"/"CLOSED" when the battery charges to a level thats above the low threshold. | -| MotionSensor | | | | Motion Sensor | -| | MotionDetectedState | | Switch, Contact | Motion sensor state (ON=motion detected, OFF=no motion | -| | | Name | String | Name of the sensor | -| | | ActiveStatus | Switch, Contact | accessory current working status. A value of "ON"/"OPEN" indicate that the accessory is active and is functioning without any errors. | -| | | 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. | -| | | TamperedStatus | Switch, Contact | accessory tampered status. A status of "ON"/"OPEN" indicates that the accessory has been tampered with. Value should return to "OFF"/"CLOSED" when the accessory has been reset to a non-tampered state. | -| | | BatteryLowStatus | Switch, Contact | accessory battery status. A value of "ON"/"OPEN" indicate that the battery level of the accessory is low. Value should return to "OFF"/"CLOSED" when the battery charges to a level thats above the low threshold. | +| Accessory Tag | Mandatory Characteristics | Optional Characteristics | Supported OH items | Description | +|:---------------------|:----------------------------|:-----------------------------|:-------------------------|:-----------------------------------------------------------------| +| LeakSensor | | | | Leak Sensor | +| | LeakDetectedState | | Switch, Contact | Leak sensor state (ON=Leak Detected, OFF=no leak) | +| | | Name | String | Name of the sensor | +| | | ActiveStatus | Switch, Contact | Working status | +| | | FaultStatus | Switch, Contact | Fault status | +| | | TamperedStatus | Switch, Contact | Tampered status | +| | | BatteryLowStatus | Switch, Contact | Battery status | +| MotionSensor | | | | Motion Sensor | +| | MotionDetectedState | | Switc, Contact | Motion sensor state (ON=motion detected, OFF=no motion) | +| | | Name | String | Name of the sensor | +| | | ActiveStatus | Switch, Contact | Working status | +| | | FaultStatus | Switch, Contact | Fault status | +| | | TamperedStatus | Switch, Contact | Tampered status | +| | | BatteryLowStatus | Switch, Contact | Battery status | | OccupancySensor | | | | Occupancy Sensor | -| | OccupancyDetectedState | | Switch, Contact | Occupancy sensor state (ON=occupied, OFF=not occupied | -| | | Name | String | Name of the sensor | -| | | ActiveStatus | Switch, Contact | accessory current working status. A value of "ON"/"OPEN" indicate that the accessory is active and is functioning without any errors. | -| | | 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. | -| | | TamperedStatus | Switch, Contact | accessory tampered status. A status of "ON"/"OPEN" indicates that the accessory has been tampered with. Value should return to "OFF"/"CLOSED" when the accessory has been reset to a non-tampered state. | -| | | BatteryLowStatus | Switch, Contact | accessory battery status. A value of "ON"/"OPEN" indicate that the battery level of the accessory is low. Value should return to "OFF"/"CLOSED" when the battery charges to a level thats above the low threshold. | +| | OccupancyDetectedState | | SwitchItem, Contact Item | Occupancy sensor state (ON=occupied, OFF=not occupied | +| | | Name | String | Name of the sensor | +| | | ActiveStatus | Switch, Contact | Working status | +| | | FaultStatus | Switch, Contact | Fault status | +| | | TamperedStatus | Switch, Contact | Tampered status | +| | | BatteryLowStatus | Switch, Contact | Battery status | | ContactSensor | | | | Contact Sensor,An accessory with on/off state that can be viewed in HomeKit but not changed such as a contact sensor for a door or window | -| | ContactSensorState | | Switch, Contact | Contact sensor state (ON=open, OFF=closed) | -| | | Name | String | Name of the sensor | -| | | ActiveStatus | Switch, Contact | accessory current working status. A value of "ON"/"OPEN" indicate that the accessory is active and is functioning without any errors. | -| | | 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. | -| | | TamperedStatus | Switch, Contact | accessory tampered status. A status of "ON"/"OPEN" indicates that the accessory has been tampered with. Value should return to "OFF"/"CLOSED" when the accessory has been reset to a non-tampered state. | -| | | BatteryLowStatus | Switch, Contact | accessory battery status. A value of "ON"/"OPEN" indicate that the battery level of the accessory is low. Value should return to "OFF"/"CLOSED" when the battery charges to a level thats above the low threshold. | +| | ContactSensorState | | SwitchItem, Contact Item | Contact sensor state (ON=open, OFF=closed) | +| | | Name | String | Name of the sensor | +| | | ActiveStatus | Switch, Contact | Working status | +| | | FaultStatus | Switch, Contact | Fault status | +| | | TamperedStatus | Switch, Contact | Tampered status | +| | | BatteryLowStatus | Switch, Contact | Battery status | | SmokeSensor | | | | Smoke Sensor | -| | SmokeDetectedState | | Switch, Contact | Smoke sensor state (ON=smoke detected, OFF=no smoke) | -| | | Name | String | Name of the sensor | -| | | ActiveStatus | Switch, Contact | accessory current working status. A value of "ON"/"OPEN" indicate that the accessory is active and is functioning without any errors. | -| | | 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. | -| | | TamperedStatus | Switch, Contact | accessory tampered status. A status of "ON"/"OPEN" indicates that the accessory has been tampered with. Value should return to "OFF"/"CLOSED" when the accessory has been reset to a non-tampered state. | -| | | BatteryLowStatus | Switch, Contact | accessory battery status. A value of "ON"/"OPEN" indicate that the battery level of the accessory is low. Value should return to "OFF"/"CLOSED" when the battery charges to a level thats above the low threshold. | -| HumiditySensor | | | | Relative Humidity Sensor providing read-only values | -| | RelativeHumidity | | Number | relative humidity in % between 0 and 100. additional configuration homekitMultiplicator = . | -| | | Name | String | Name of the sensor | -| | | ActiveStatus | Switch, Contact | accessory current working status. A value of "ON"/"OPEN" indicate that the accessory is active and is functioning without any errors. | -| | | 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. | -| | | TamperedStatus | Switch, Contact | accessory tampered status. A status of "ON"/"OPEN" indicates that the accessory has been tampered with. Value should return to "OFF"/"CLOSED" when the accessory has been reset to a non-tampered state. | -| | | BatteryLowStatus | Switch, Contact | accessory battery status. A value of "ON"/"OPEN" indicate that the battery level of the accessory is low. Value should return to "OFF"/"CLOSED" when the battery charges to a level thats above the low threshold. | -| TemperatureSensor | | | | Temperature sensor | +| | SmokeDetectedState | | SwitchItem, Contact Item | Smoke sensor state (ON=smoke detected, OFF=no smoke) | +| | | Name | String | Name of the sensor | +| | | ActiveStatus | Switch, Contact | Working status | +| | | FaultStatus | Switch, Contact | Fault status | +| | | TamperedStatus | Switch, Contact | Tampered status | +| | | BatteryLowStatus | Switch, Contact | Battery status | +| LightSensor | | | | Light sensor | +| | LightLevel | | Number | Light level in lux | +| | | Name | String | Name of the sensor | +| | | ActiveStatus | Switch, Contact | Working status | +| | | FaultStatus | Switch, Contact | Fault status | +| | | TamperedStatus | Switch, Contact | Tampered status | +| | | BatteryLowStatus | Switch, Contact | Battery status | +| HumiditySensor | | | | Relative Humidity Sensor providing read-only values | +| | RelativeHumidity | | Number | Relative humidity in % between 0 and 100. additional configuration homekitMultiplicator = . | +| | | Name | String | Name of the sensor | +| | | ActiveStatus | Switch, Contact | Working status | +| | | FaultStatus | Switch, Contact | Fault status | +| | | TamperedStatus | Switch, Contact | Tampered status | +| | | BatteryLowStatus | Switch, Contact | Battery status | +| TemperatureSensor | | | | Temperature sensor | | | CurrentTemperature | | Number | current temperature. supported configuration: minValue, maxValue, step. | -| | | Name | String | Name of the sensor | -| | | ActiveStatus | Switch, Contact | accessory current working status. A value of "ON"/"OPEN" indicate that the accessory is active and is functioning without any errors. | -| | | 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. | -| | | TamperedStatus | Switch, Contact | accessory tampered status. A status of "ON"/"OPEN" indicates that the accessory has been tampered with. Value should return to "OFF"/"CLOSED" when the accessory has been reset to a non-tampered state. | -| | | BatteryLowStatus | Switch, Contact | accessory battery status. A value of "ON"/"OPEN" indicate that the battery level of the accessory is low. Value should return to "OFF"/"CLOSED" when the battery charges to a level thats above the low threshold. | +| | | Name | String | Name of the sensor | +| | | ActiveStatus | Switch, Contact | Working status | +| | | FaultStatus | Switch, Contact | Fault status | +| | | TamperedStatus | Switch, Contact | Tampered status | +| | | BatteryLowStatus | Switch, Contact | Battery status | | CarbonDioxideSensor | | | | Carbon Dioxide Sensor | | | CarbonDioxideDetectedState | | Switch, Contact | carbon dioxide sensor state (ON- abnormal level of carbon dioxide detected, OFF - level is normal) | | | | CarbonDioxideLevel | Number | Carbon dioxide level in ppm, max 100000 | | | | CarbonDioxidePeakLevel | Number | highest detected level (ppm) of carbon dioxide detected by a sensor, max 100000 | -| | | Name | String | Name of the sensor | -| | | ActiveStatus | Switch, Contact | accessory current working status. A value of "ON"/"OPEN" indicate that the accessory is active and is functioning without any errors. | -| | | 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. | -| | | TamperedStatus | Switch, Contact | accessory tampered status. A status of "ON"/"OPEN" indicates that the accessory has been tampered with. Value should return to "OFF"/"CLOSED" when the accessory has been reset to a non-tampered state. | -| | | BatteryLowStatus | Switch, Contact | accessory battery status. A value of "ON"/"OPEN" indicate that the battery level of the accessory is low. Value should return to "OFF"/"CLOSED" when the battery charges to a level thats above the low threshold. | +| | | Name | String | Name of the sensor | +| | | ActiveStatus | Switch, Contact | Working status | +| | | FaultStatus | Switch, Contact | Fault status | +| | | TamperedStatus | Switch, Contact | Tampered status | +| | | BatteryLowStatus | Switch, Contact | Battery status | | CarbonMonoxideSensor | | | | Carbon monoxide Sensor | | | CarbonMonoxideDetectedState | | Switch, Contact | Carbon monoxide sensor state (ON- abnormal level of carbon monoxide detected, OFF - level is normal) | | | | CarbonMonoxideLevel | Number | Carbon monoxide level in ppm, max 100 | | | | CarbonMonoxidePeakLevel | Number | highest detected level (ppm) of carbon monoxide detected by a sensor, max 100 | -| | | Name | String | Name of the sensor | -| | | ActiveStatus | Switch, Contact | accessory current working status. A value of "ON"/"OPEN" indicate that the accessory is active and is functioning without any errors. | -| | | 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. | -| | | TamperedStatus | Switch, Contact | accessory tampered status. A status of "ON"/"OPEN" indicates that the accessory has been tampered with. Value should return to "OFF"/"CLOSED" when the accessory has been reset to a non-tampered state. | -| | | BatteryLowStatus | Switch, Contact | accessory battery status. A value of "ON"/"OPEN" indicate that the battery level of the accessory is low. Value should return to "OFF"/"CLOSED" when the battery charges to a level thats above the low threshold. | +| | | Name | String | Name of the sensor | +| | | ActiveStatus | Switch, Contact | Working status | +| | | FaultStatus | Switch, Contact | Fault status | +| | | TamperedStatus | Switch, Contact | Tampered status | +| | | BatteryLowStatus | Switch, Contact | Battery status | | WindowCovering | | | | Window covering / blinds. One Rollershutter item covers all mandatory characteristics. see examples below. | | | CurrentPosition | | Rollershutter | Current position of window covering | | | TargetPosition | | Rollershutter | Target position of window covering | @@ -211,7 +220,7 @@ A full list of supported accessory types can be found in the table *below*. | | | Name | String | Name of the switch | | Outlet | | | | 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 outlet - ON/OFF | -| | InUseStatus | | Switch | indicated whether current flowing through the outlet | +| | InUseStatus | | Switch | indicates whether current flowing through the outlet | | | | Name | String | Name of the switch | | Lighting | | | | A lightbulb, can have further optional parameters for brightness, hue, etc | | | OnState | | Switch | State of the light - ON/OFF | @@ -221,7 +230,7 @@ A full list of supported accessory types can be found in the table *below*. | | | Brightness | Dimmer, Color | Brightness in % (1-100). See "Usage of dimmer modes" for configuration details. | | | | ColorTemperature | Number | Color temperature which is represented in reciprocal megaKelvin, values - 50 to 400. should not be used in combination with hue, saturation and brightness | | Fan | | | | Fan | -| | ActiveStatus | | Switch | accessory current working status. A value of "ON"/"OPEN" indicate that the accessory is active and is functioning without any errors. | +| | 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 | @@ -237,7 +246,7 @@ A full list of supported accessory types can be found in the table *below*. | | | 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" indicate that the accessory is active and is functioning without any errors. | +| | 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"] | @@ -252,8 +261,8 @@ A full list of supported accessory types can be found in the table *below*. | | 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" indicate that the accessory is active and is functioning without any errors. | -| | InUseStatus | | Switch | indicated whether fluid flowing through the valve. A value of "ON"/"OPEN" indicate that fluid is flowing. | +| | 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 = | | | | 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 | @@ -350,7 +359,8 @@ Switch leaksensor_single "Leak Sensor single" Switch lock "Lock single" {homekit="Lock"} Switch valve_single "Valve single" {homekit="Valve" [homekitValveType="Shower"]} -Number temperature_sensor "Temperature Sensor [%.1f C]" {homekit="TemperatureSensor" [minValue=10.5, maxValue=27] } +Number temperature_sensor "Temperature Sensor [%.1f C]" {homekit="TemperatureSensor" [minValue=10.5, maxValue=27] } +Number light_sensor "Light Sensor" {homekit="LightSensor"} Group gValve "Valve Group" {homekit="Valve" [homekitValveType="Irrigation"]} Switch valve_active "Valve active" (gValve) {homekit="Valve.ActiveStatus, Valve.InUseStatus"} @@ -512,6 +522,48 @@ Switch valve_active "Valve active" (gValve) {homekit = "Valve.Acti Number valve_duration "Valve duration" (gValve) {homekit = "Valve.Duration" [homekitDefaultDuration = 1800]} ``` +### Sensors +Sensors have typically one mandatory characteristic, e.g. temperature or lead trigger, and several optional characteristics which are typically used for battery powered sensors and/or wireless sensors. +Following table summarizes the optional characteristics supported by sensors. + +| Characteristics | Supported openHAB items | Description | +|:-----------------------------|:-------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| Name | String | Name of the sensor. This characteristic is interesting only for very specific cases in which the name of accessory is dynamic. if you not sure then you don't need it. | +| ActiveStatus | Switch, Contact | Accessory current working status. "ON"/"OPEN" indicates that the accessory is active and is functioning without any errors. | +| 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. | +| TamperedStatus | Switch, Contact | Accessory tampered status. "ON"/"OPEN" indicates that the accessory has been tampered. Value should return to "OFF"/"CLOSED" when the accessory has been reset to a non-tampered state. | +| BatteryLowStatus | Switch, Contact | Accessory battery status. "ON"/"OPEN" indicates that the battery level of the accessory is low. Value should return to "OFF"/"CLOSED" when the battery charges to a level thats above the low threshold. | + +Examples of sensor definitions. +Sensors without optional characteristics: + +```xtend +Switch leaksensor_single "Leak Sensor" {homekit="LeakSensor"} +Number light_sensor "Light Sensor" {homekit="LightSensor"} +Number temperature_sensor "Temperature Sensor [%.1f C]" {homekit="TemperatureSensor"} +Contact contact_sensor "Contact Sensor" {homekit="ContactSensor"} +Switch occupancy_sensor "Occupancy Sensor" {homekit="OccupancyDetectedState"} +Switch motion_sensor "Motion Sensor" {homekit="MotionSensor"} +Number humidity_sensor "Humidity Sensor" {homekit="HumiditySensor"} +``` + +Sensors with optional characteristics: + +```xtend +Group gLeakSensor "Leak Sensor" {homekit="LeakSensor"} +Switch leaksensor "Leak Sensor State" (gLeakSensor) {homekit="LeakDetectedState"} +Switch leaksensor_bat "Leak Sensor Battery" (gLeakSensor) {homekit="BatteryLowStatus"} +Switch leaksensor_active "Leak Sensor Active" (gLeakSensor) {homekit="ActiveStatus"} +Switch leaksensor_fault "Leak Sensor Fault" (gLeakSensor) {homekit="FaultStatus"} +Switch leaksensor_tampered "Leak Sensor Tampered" (gLeakSensor) {homekit="TamperedStatus"} + +Group gMotionSensor "Motion Sensor" {homekit="MotionSensor"} +Switch motionsensor "Motion Sensor State" (gMotionSensor) {homekit="MotionDetectedState"} +Switch motionsensor_bat "Motion Sensor Battery" (gMotionSensor) {homekit="BatteryLowStatus"} +Switch motionsensor_active "Motion Sensor Active" (gMotionSensor) {homekit="ActiveStatus"} +Switch motionsensor_fault "Motion Sensor Fault" (gMotionSensor) {homekit="FaultStatus"} +Switch motionsensor_tampered "Motion Sensor Tampered" (gMotionSensor) {homekit="TamperedStatus"} +``` ## Common Problems 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 2bff38198737b..23afdb93abe2e 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 @@ -44,6 +44,7 @@ public enum HomekitAccessoryType { SPEAKER("Speaker"), GARAGE_DOOR_OPENER("GarageDoorOpener"), HEATER_COOLER("HeaterCooler"), + LIGHT_SENSOR("LightSensor"), DUMMY("Dummy"), @Deprecated() BLINDS("Blinds"), diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitCharacteristicType.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitCharacteristicType.java index 7fab099184d01..4bb33e7bee1e5 100644 --- a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitCharacteristicType.java +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitCharacteristicType.java @@ -92,6 +92,7 @@ public enum HomekitCharacteristicType { VOLUME("Volume"), MUTE("Mute"), + LIGHT_LEVEL("LightLevel"), CURRENT_DOOR_STATE("CurrentDoorState"), TARGET_DOOR_STATE("TargetDoorState"), 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 2d30d8d3fb794..3741c6a3dea0e 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 @@ -80,6 +80,7 @@ public class HomekitAccessoryFactory { put(WINDOW_COVERING, new HomekitCharacteristicType[] { TARGET_POSITION, CURRENT_POSITION, POSITION_STATE }); put(LIGHTBULB, new HomekitCharacteristicType[] { ON_STATE }); put(FAN, new HomekitCharacteristicType[] { ACTIVE_STATUS }); + put(LIGHT_SENSOR, new HomekitCharacteristicType[] { LIGHT_LEVEL }); put(TEMPERATURE_SENSOR, new HomekitCharacteristicType[] { CURRENT_TEMPERATURE }); put(THERMOSTAT, new HomekitCharacteristicType[] { CURRENT_HEATING_COOLING_STATE, TARGET_HEATING_COOLING_STATE, CURRENT_TEMPERATURE, TARGET_TEMPERATURE }); @@ -116,6 +117,7 @@ public class HomekitAccessoryFactory { put(WINDOW_COVERING, HomekitWindowCoveringImpl.class); put(LIGHTBULB, HomekitLightbulbImpl.class); put(FAN, HomekitFanImpl.class); + put(LIGHT_SENSOR, HomekitLightSensorImpl.class); put(TEMPERATURE_SENSOR, HomekitTemperatureSensorImpl.class); put(THERMOSTAT, HomekitThermostatImpl.class); put(LOCK, HomekitLockImpl.class); diff --git a/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLightSensorImpl.java b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLightSensorImpl.java new file mode 100644 index 0000000000000..0e721ca97ee20 --- /dev/null +++ b/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/accessories/HomekitLightSensorImpl.java @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2010-2020 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.LIGHT_LEVEL; + +import java.util.List; +import java.util.concurrent.CompletableFuture; + +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.smarthome.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.LightSensorAccessory; +import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; +import io.github.hapjava.services.impl.LightSensorService; + +/** + * HomeKit light sensor implementation. + * + * @author Eugen Freiter - Initial contribution + */ +public class HomekitLightSensorImpl extends AbstractHomekitAccessoryImpl implements LightSensorAccessory { + + public HomekitLightSensorImpl(HomekitTaggedItem taggedItem, List mandatoryCharacteristics, + HomekitAccessoryUpdater updater, HomekitSettings settings) { + super(taggedItem, mandatoryCharacteristics, updater, settings); + getServices().add(new LightSensorService(this)); + } + + @Override + public CompletableFuture getCurrentAmbientLightLevel() { + final @Nullable DecimalType state = getStateAs(LIGHT_LEVEL, DecimalType.class); + return CompletableFuture.completedFuture(state != null ? state.doubleValue() : 0.0); + } + + @Override + public void subscribeCurrentAmbientLightLevel(HomekitCharacteristicChangeCallback callback) { + subscribe(LIGHT_LEVEL, callback); + } + + @Override + public void unsubscribeCurrentAmbientLightLevel() { + unsubscribe(LIGHT_LEVEL); + } +}