Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[homekit] add support for air quality sensor #8125

Merged
merged 2 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions bundles/org.openhab.io.homekit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ A full list of supported accessory types can be found in the table *below*.

| Accessory Tag | Mandatory Characteristics | Optional Characteristics | Supported OH items | Description |
|:---------------------|:----------------------------|:-----------------------------|:-------------------------|:-----------------------------------------------------------------|
| AirQualitySensor | | | | Air Quality Sensor which can measure different parameters |
| | AirQuality | | String | Air quality state, possible values (UNKNOWN,EXCELLENT,GOOD,FAIR,INFERIOR,POOR). Custom mapping can be defined at item level, e.g. [EXCELLENT="BEST", POOR="BAD"] |
| | | OzoneDensity | Number | Ozone density in micrograms/m3, max 1000 |
| | | NitrogenDioxideDensity | Number | NO2 density in micrograms/m3, max 1000 |
| | | SulphurDioxideDensity | Number | SO2 density in micrograms/m3, max 1000 |
| | | PM25Density | Number | PM2.5 micrometer particulate density in micrograms/m3, max 1000 |
| | | PM10Density | Number | PM10 micrometer particulate density in micrograms/m3, max 1000 |
| | | VOCDensity | Number | VOC Density in micrograms/m3, max 1000 |
| | | 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 |
| LeakSensor | | | | Leak Sensor |
| | LeakDetectedState | | Switch, Contact | Leak sensor state (ON=Leak Detected, OFF=no leak) |
| | | Name | String | Name of the sensor |
Expand All @@ -138,35 +151,35 @@ A full list of supported accessory types can be found in the table *below*.
| | | 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) |
| | MotionDetectedState | | Switch, 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 | | SwitchItem, Contact Item | Occupancy sensor state (ON=occupied, OFF=not occupied |
| OccupancySensor | | | | Occupancy Sensor |
| | OccupancyDetectedState | | Switch, Contact | 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 | | SwitchItem, Contact Item | Contact sensor state (ON=open, OFF=closed) |
| | ContactSensorState | | Switch, Contact | 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 | | SwitchItem, Contact Item | Smoke sensor state (ON=smoke detected, OFF=no smoke) |
| | SmokeDetectedState | | Switch, Contact | 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 |
| | LightLevel | | Number | Light level in lux |
| | | Name | String | Name of the sensor |
| | | ActiveStatus | Switch, Contact | Working status |
| | | FaultStatus | Switch, Contact | Fault status |
Expand Down Expand Up @@ -402,6 +415,15 @@ Switch contactsensor_active "Contact Sensor Active"
Switch contactsensor_fault "Contact Sensor Fault" (gContactSensor) {homekit="ContactSensor.FaultStatus"}
Switch contactsensor_tampered "Contact Sensor Tampered" (gContactSensor) {homekit="ContactSensor.TamperedStatus"}

Group gAirQualitySensor "Air Quality Sensor" {homekit="AirQualitySensor"}
String airquality "Air Quality" (gAirQualitySensor) {homekit="AirQuality"}
Number ozone "Ozone Density" (gAirQualitySensor) {homekit="OzoneDensity"}
Number voc "VOC Density" (gAirQualitySensor) {homekit="VOCDensity"}
Number nitrogen "Nitrogen Density" (gAirQualitySensor) {homekit="NitrogenDioxideDensity"}
Number sulphur "Sulphur Density" (gAirQualitySensor) {homekit="SulphurDioxideDensity"}
Number pm25 "PM25 Density" (gAirQualitySensor) {homekit="PM25Density"}
Number pm10 "PM10 Density" (gAirQualitySensor) {homekit="PM10Density"}

Group gSecuritySystem "Security System Group" {homekit="SecuritySystem"}
String security_current_state "Security Current State" (gSecuritySystem) {homekit="SecuritySystem.CurrentSecuritySystemState"}
String security_target_state "Security Target State" (gSecuritySystem) {homekit="SecuritySystem.TargetSecuritySystemState"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public enum HomekitAccessoryType {
GARAGE_DOOR_OPENER("GarageDoorOpener"),
HEATER_COOLER("HeaterCooler"),
LIGHT_SENSOR("LightSensor"),
AIR_QUALITY_SENSOR("AirQualitySensor"),
DUMMY("Dummy"),
@Deprecated()
BLINDS("Blinds"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ public enum HomekitCharacteristicType {
COOLING_THRESHOLD_TEMPERATURE("CoolingThresholdTemperature"),
HEATING_THRESHOLD_TEMPERATURE("HeatingThresholdTemperature"),

AIR_QUALITY("AirQuality"),
OZONE_DENSITY("OzoneDensity"),
NITROGEN_DIOXIDE_DENSITY("NitrogenDioxideDensity"),
SULPHUR_DIOXIDE_DENSITY("SulphurDioxideDensity"),
PM25_DENSITY("PM25Density"),
PM10_DENSITY("PM10Density"),
VOC_DENSITY("VOCDensity"),

@Deprecated()
OLD_BATTERY_LEVEL("homekit:BatteryLevel"),
@Deprecated()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class HomekitAccessoryFactory {
put(CONTACT_SENSOR, new HomekitCharacteristicType[] { CONTACT_SENSOR_STATE });
put(SMOKE_SENSOR, new HomekitCharacteristicType[] { SMOKE_DETECTED_STATE });
put(HUMIDITY_SENSOR, new HomekitCharacteristicType[] { RELATIVE_HUMIDITY });
put(AIR_QUALITY_SENSOR, new HomekitCharacteristicType[] { AIR_QUALITY });
put(SWITCH, new HomekitCharacteristicType[] { ON_STATE });
put(CARBON_DIOXIDE_SENSOR, new HomekitCharacteristicType[] { CARBON_DIOXIDE_DETECTED_STATE });
put(CARBON_MONOXIDE_SENSOR, new HomekitCharacteristicType[] { CARBON_MONOXIDE_DETECTED_STATE });
Expand Down Expand Up @@ -111,6 +112,7 @@ public class HomekitAccessoryFactory {
put(CONTACT_SENSOR, HomekitContactSensorImpl.class);
put(SMOKE_SENSOR, HomekitSmokeSensorImpl.class);
put(HUMIDITY_SENSOR, HomekitHumiditySensorImpl.class);
put(AIR_QUALITY_SENSOR, HomekitAirQualitySensorImpl.class);
put(SWITCH, HomekitSwitchImpl.class);
put(CARBON_DIOXIDE_SENSOR, HomekitCarbonDioxideSensorImpl.class);
put(CARBON_MONOXIDE_SENSOR, HomekitCarbonMonoxideSensorImpl.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* 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.AIR_QUALITY;

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.AirQualityAccessory;
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
import io.github.hapjava.characteristics.impl.airquality.AirQualityEnum;
import io.github.hapjava.services.impl.AirQualityService;

/**
* Air Quality sensor accessory.
*
* @author Eugen Freiter - Initial contribution
*/
public class HomekitAirQualitySensorImpl extends AbstractHomekitAccessoryImpl implements AirQualityAccessory {
private final Map<AirQualityEnum, String> qualityStateMapping = new EnumMap<AirQualityEnum, String>(
AirQualityEnum.class) {
{
put(AirQualityEnum.UNKNOWN, "UNKNOWN");
put(AirQualityEnum.EXCELLENT, "EXCELLENT");
put(AirQualityEnum.GOOD, "GOOD");
put(AirQualityEnum.FAIR, "FAIR");
put(AirQualityEnum.INFERIOR, "INFERIOR");
put(AirQualityEnum.POOR, "POOR");
}
};

public HomekitAirQualitySensorImpl(HomekitTaggedItem taggedItem, List<HomekitTaggedItem> mandatoryCharacteristics,
HomekitAccessoryUpdater updater, HomekitSettings settings) throws IncompleteAccessoryException {
super(taggedItem, mandatoryCharacteristics, updater, settings);
updateMapping(AIR_QUALITY, qualityStateMapping);
getServices().add(new AirQualityService(this));
}

@Override
public CompletableFuture<AirQualityEnum> getAirQuality() {
return CompletableFuture
.completedFuture(getKeyFromMapping(AIR_QUALITY, qualityStateMapping, AirQualityEnum.UNKNOWN));
}

@Override
public void subscribeAirQuality(final HomekitCharacteristicChangeCallback callback) {
subscribe(AIR_QUALITY, callback);
}

@Override
public void unsubscribeAirQuality() {
unsubscribe(AIR_QUALITY);
}
}
Loading