-
Notifications
You must be signed in to change notification settings - Fork 84
Add support for FilterMaintenanceAccessory #124
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
Merged
ccutrer
merged 8 commits into
hap-java:master
from
gjvanderheiden:FilterMaintenanceAccessory
Dec 11, 2020
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9de39dd
Add support for FilterMaintenanceAccessory
gjvanderheiden ef70ea9
Add support for FilterMaintenanceAccessory
gjvanderheiden 10a9f43
[#124](https://github.com/hap-java/HAP-Java/pull/124
gjvanderheiden a0e0bda
Add support for FilterMaintenanceAccessory
gjvanderheiden 3c462a5
Add support for FilterMaintenanceAccessory
gjvanderheiden 3858f17
Add support for FilterMaintenanceAccessory
gjvanderheiden 8dda769
Add support for FilterMaintenanceAccessory
gjvanderheiden 4db045b
Add support for FilterMaintenanceAccessory
gjvanderheiden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
42 changes: 42 additions & 0 deletions
42
src/main/java/io/github/hapjava/accessories/FilterMaintenanceAccessory.java
This file contains hidden or 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,42 @@ | ||
| package io.github.hapjava.accessories; | ||
|
|
||
| import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; | ||
| import io.github.hapjava.characteristics.impl.filtermaintenance.FilterChangeIndicationEnum; | ||
| import io.github.hapjava.services.Service; | ||
| import io.github.hapjava.services.impl.FilterMaintenanceService; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
| /** | ||
| * A Filter maintenance with mandatory characteristics. | ||
| * | ||
| * <p>The HomeKit app doesn't support a seperate FilterMaintenance, but as a linked service to | ||
| * AirPurifier. | ||
| * | ||
| * @see AirPurifierAccessory#getFilterMaintenanceAccessory() | ||
| */ | ||
| public interface FilterMaintenanceAccessory extends HomekitAccessory { | ||
|
|
||
| /** | ||
| * The filter change indictaion. It's either yes or no. | ||
| * | ||
| * @return FilterChangeIndicationEnum | ||
| */ | ||
| CompletableFuture<FilterChangeIndicationEnum> getFilterChangeIndication(); | ||
|
|
||
| /** | ||
| * Subscribes to changes in the filter change indication. | ||
| * | ||
| * @param callback the function to call when the state changes. | ||
| */ | ||
| void subscribeFilterChangeIndication(HomekitCharacteristicChangeCallback callback); | ||
|
|
||
| /** Unsubscribes from changes in the filter change indication. */ | ||
| void unsubscribeFilterChangeIndication(); | ||
|
|
||
| @Override | ||
| default Collection<Service> getServices() { | ||
| return Collections.singleton(new FilterMaintenanceService(this)); | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
...va/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithFilterLifeLevel.java
This file contains hidden or 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,25 @@ | ||
| package io.github.hapjava.accessories.optionalcharacteristic; | ||
|
|
||
| import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; | ||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
| /** Accessory with filter level characteristics */ | ||
| public interface AccessoryWithFilterLifeLevel { | ||
|
|
||
| /** | ||
| * what's the filter life level, percentage wise | ||
| * | ||
| * @return filter life level | ||
| */ | ||
| CompletableFuture<Double> getFilterLifeLevel(); | ||
|
|
||
| /** | ||
| * Subscribes to changes in the filter life level. | ||
| * | ||
| * @param callback the function to call when the level changes. | ||
| */ | ||
| void subscribeFilterLifeLevel(HomekitCharacteristicChangeCallback callback); | ||
|
|
||
| /** Unsubscribes from changes in the current filter life level. */ | ||
| void unsubscribeFilterLifeLevel(); | ||
| } |
16 changes: 16 additions & 0 deletions
16
...github/hapjava/accessories/optionalcharacteristic/AccessoryWithResetFilterIndication.java
This file contains hidden or 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,16 @@ | ||
| package io.github.hapjava.accessories.optionalcharacteristic; | ||
|
|
||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
| /** Accessory with filter reset characteristics */ | ||
| public interface AccessoryWithResetFilterIndication { | ||
|
|
||
| /** | ||
| * Request to reset the filter level | ||
| * | ||
| * @param indication always 1, by HomeKit protocol. (to be ignored) | ||
| * @return a future that completes when the change is made | ||
| * @throws Exception when the change cannot be made | ||
| */ | ||
| CompletableFuture<Void> resetFilterIndication(Integer indication) throws Exception; | ||
| } |
This file contains hidden or 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
27 changes: 27 additions & 0 deletions
27
.../hapjava/characteristics/impl/filtermaintenance/FilterChangeIndicationCharacteristic.java
This file contains hidden or 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,27 @@ | ||
| package io.github.hapjava.characteristics.impl.filtermaintenance; | ||
|
|
||
| import io.github.hapjava.characteristics.EventableCharacteristic; | ||
| import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; | ||
| import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.function.Consumer; | ||
| import java.util.function.Supplier; | ||
|
|
||
| public class FilterChangeIndicationCharacteristic | ||
| extends EnumCharacteristic<FilterChangeIndicationEnum> implements EventableCharacteristic { | ||
|
|
||
| public FilterChangeIndicationCharacteristic( | ||
| Supplier<CompletableFuture<FilterChangeIndicationEnum>> getter, | ||
| Consumer<HomekitCharacteristicChangeCallback> subscriber, | ||
| Runnable unsubscriber) { | ||
| super( | ||
| "000000AC-0000-1000-8000-0026BB765291", | ||
| "filter change indication", | ||
| FilterChangeIndicationEnum.values(), | ||
| Optional.of(getter), | ||
| Optional.empty(), | ||
| Optional.of(subscriber), | ||
| Optional.of(unsubscriber)); | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
.../io/github/hapjava/characteristics/impl/filtermaintenance/FilterChangeIndicationEnum.java
This file contains hidden or 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,34 @@ | ||
| package io.github.hapjava.characteristics.impl.filtermaintenance; | ||
|
|
||
| import io.github.hapjava.characteristics.CharacteristicEnum; | ||
| import java.util.Arrays; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public enum FilterChangeIndicationEnum implements CharacteristicEnum { | ||
| NO_CHANGE_NEEDED(0), | ||
| CHANGE_NEEDED(1); | ||
|
|
||
| private static final Map<Integer, FilterChangeIndicationEnum> reverse; | ||
|
|
||
| static { | ||
| reverse = | ||
| Arrays.stream(FilterChangeIndicationEnum.values()) | ||
| .collect(Collectors.toMap(FilterChangeIndicationEnum::getCode, t -> t)); | ||
| } | ||
|
|
||
| public static FilterChangeIndicationEnum fromCode(Integer code) { | ||
| return reverse.get(code); | ||
| } | ||
|
|
||
| private final int code; | ||
|
|
||
| FilterChangeIndicationEnum(int code) { | ||
| this.code = code; | ||
| } | ||
|
|
||
| @Override | ||
| public int getCode() { | ||
| return code; | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
.../github/hapjava/characteristics/impl/filtermaintenance/FilterLifeLevelCharacteristic.java
This file contains hidden or 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,30 @@ | ||
| package io.github.hapjava.characteristics.impl.filtermaintenance; | ||
|
|
||
| import io.github.hapjava.characteristics.EventableCharacteristic; | ||
| import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; | ||
| import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.function.Consumer; | ||
| import java.util.function.Supplier; | ||
|
|
||
| public class FilterLifeLevelCharacteristic extends FloatCharacteristic | ||
| implements EventableCharacteristic { | ||
|
|
||
| public FilterLifeLevelCharacteristic( | ||
| Supplier<CompletableFuture<Double>> getter, | ||
| Consumer<HomekitCharacteristicChangeCallback> subscriber, | ||
| Runnable unsubscriber) { | ||
| super( | ||
| "000000AB-0000-1000-8000-0026BB765291", | ||
| "Filter Life Level", | ||
| 0, | ||
| 100, | ||
| 1, | ||
| "%", | ||
| Optional.of(getter), | ||
| Optional.empty(), | ||
| Optional.of(subscriber), | ||
| Optional.of(unsubscriber)); | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
...b/hapjava/characteristics/impl/filtermaintenance/ResetFilterIndicationCharacteristic.java
This file contains hidden or 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,21 @@ | ||
| package io.github.hapjava.characteristics.impl.filtermaintenance; | ||
|
|
||
| import io.github.hapjava.characteristics.ExceptionalConsumer; | ||
| import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; | ||
| import java.util.Optional; | ||
|
|
||
| public class ResetFilterIndicationCharacteristic extends IntegerCharacteristic { | ||
|
|
||
| public ResetFilterIndicationCharacteristic(ExceptionalConsumer<Integer> setter) { | ||
| super( | ||
| "000000AD-0000-1000-8000-0026BB765291", | ||
| "Reset Filter Indication", | ||
| 1, | ||
| 1, | ||
| null, | ||
| Optional.empty(), | ||
| Optional.of(setter), | ||
| Optional.empty(), | ||
| Optional.empty()); | ||
| } | ||
| } |
This file contains hidden or 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
57 changes: 57 additions & 0 deletions
57
src/main/java/io/github/hapjava/services/impl/FilterMaintenanceService.java
This file contains hidden or 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,57 @@ | ||
| package io.github.hapjava.services.impl; | ||
|
|
||
| import io.github.hapjava.accessories.FilterMaintenanceAccessory; | ||
| import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithFilterLifeLevel; | ||
| import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; | ||
| import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithResetFilterIndication; | ||
| import io.github.hapjava.characteristics.impl.common.NameCharacteristic; | ||
| import io.github.hapjava.characteristics.impl.filtermaintenance.FilterChangeIndicationCharacteristic; | ||
| import io.github.hapjava.characteristics.impl.filtermaintenance.FilterLifeLevelCharacteristic; | ||
| import io.github.hapjava.characteristics.impl.filtermaintenance.ResetFilterIndicationCharacteristic; | ||
|
|
||
| /** This service describes a filter maintenance. */ | ||
| public class FilterMaintenanceService extends AbstractServiceImpl { | ||
|
|
||
| public FilterMaintenanceService(FilterChangeIndicationCharacteristic filerChange) { | ||
| super("000000BA-0000-1000-8000-0026BB765291"); | ||
| addCharacteristic(filerChange); | ||
| } | ||
|
|
||
| public FilterMaintenanceService(FilterMaintenanceAccessory accessory) { | ||
| this( | ||
| new FilterChangeIndicationCharacteristic( | ||
| accessory::getFilterChangeIndication, | ||
| accessory::subscribeFilterChangeIndication, | ||
| accessory::unsubscribeFilterChangeIndication)); | ||
|
|
||
| if (accessory instanceof AccessoryWithName) { | ||
| addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); | ||
| } | ||
|
|
||
| if (accessory instanceof AccessoryWithFilterLifeLevel) { | ||
| addOptionalCharacteristic( | ||
| new FilterLifeLevelCharacteristic( | ||
| ((AccessoryWithFilterLifeLevel) accessory)::getFilterLifeLevel, | ||
| ((AccessoryWithFilterLifeLevel) accessory)::subscribeFilterLifeLevel, | ||
| ((AccessoryWithFilterLifeLevel) accessory)::unsubscribeFilterLifeLevel)); | ||
| } | ||
|
|
||
| if (accessory instanceof AccessoryWithResetFilterIndication) { | ||
| addOptionalCharacteristic( | ||
| new ResetFilterIndicationCharacteristic( | ||
| ((AccessoryWithResetFilterIndication) accessory)::resetFilterIndication)); | ||
| } | ||
| } | ||
|
|
||
| public void addOptionalCharacteristic(NameCharacteristic name) { | ||
| addCharacteristic(name); | ||
| } | ||
|
|
||
| public void addOptionalCharacteristic(FilterLifeLevelCharacteristic filterLifeLevel) { | ||
| addCharacteristic(filterLifeLevel); | ||
| } | ||
|
|
||
| public void addOptionalCharacteristic(ResetFilterIndicationCharacteristic resetFilterIndication) { | ||
| addCharacteristic(resetFilterIndication); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.