forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[homekit] add support for air quality sensor (openhab#8125)
* add air quality sensor * add example to README Signed-off-by: Eugen Freiter <[email protected]> Signed-off-by: CSchlipp <[email protected]>
- Loading branch information
Showing
6 changed files
with
160 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...rc/main/java/org/openhab/io/homekit/internal/accessories/HomekitAirQualitySensorImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.