-
Notifications
You must be signed in to change notification settings - Fork 84
We can now specify service name #17
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d6bd09b
Log IOExceptions using DEBUG level
gdombiak 310c8d9
It is now possible to specify service name.
gdombiak 5a69d28
Added logging when removing accessory.
gdombiak 7fbdf84
Added light sensor that measures luminance in LUX.
gdombiak 2233dbe
Fixed NPE when accessory was removed from registry
gdombiak 367fe2a
Added back deprecated constructor.
gdombiak 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
42 changes: 42 additions & 0 deletions
42
src/main/java/com/beowulfe/hap/accessories/LightSensor.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 com.beowulfe.hap.accessories; | ||
|
|
||
| import com.beowulfe.hap.HomekitAccessory; | ||
| import com.beowulfe.hap.HomekitCharacteristicChangeCallback; | ||
| import com.beowulfe.hap.Service; | ||
| import com.beowulfe.hap.impl.services.LightSensorService; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
| /** | ||
| * A light sensor that reports current ambient light level. | ||
| * | ||
| * @author Gaston Dombiak | ||
| */ | ||
| public interface LightSensor extends HomekitAccessory { | ||
|
|
||
| /** | ||
| * Retrieves the current ambient light level. | ||
| * | ||
| * @return a future that will contain the luminance level expressed in LUX. | ||
| */ | ||
| CompletableFuture<Double> getCurrentAmbientLightLevel(); | ||
|
|
||
| @Override | ||
| default Collection<Service> getServices() { | ||
| return Collections.singleton(new LightSensorService(this)); | ||
| } | ||
|
|
||
| /** | ||
| * Subscribes to changes in the current ambient light level. | ||
| * | ||
| * @param callback the function to call when the state changes. | ||
| */ | ||
| void subscribeCurrentAmbientLightLevel(HomekitCharacteristicChangeCallback callback); | ||
|
|
||
| /** | ||
| * Unsubscribes from changes in the current ambient light level. | ||
| */ | ||
| void unsubscribeCurrentAmbientLightLevel(); | ||
| } |
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
5 changes: 2 additions & 3 deletions
5
src/main/java/com/beowulfe/hap/impl/characteristics/common/Name.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 |
|---|---|---|
| @@ -1,13 +1,12 @@ | ||
| package com.beowulfe.hap.impl.characteristics.common; | ||
|
|
||
| import com.beowulfe.hap.HomekitAccessory; | ||
| import com.beowulfe.hap.characteristics.StaticStringCharacteristic; | ||
|
|
||
| public class Name extends StaticStringCharacteristic { | ||
|
|
||
| public Name(HomekitAccessory accessory) { | ||
| public Name(String label) { | ||
| super("00000023-0000-1000-8000-0026BB765291", | ||
| "Name of the accessory", | ||
| accessory.getLabel()); | ||
| label); | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
...ain/java/com/beowulfe/hap/impl/characteristics/light/AmbientLightLevelCharacteristic.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,39 @@ | ||
| package com.beowulfe.hap.impl.characteristics.light; | ||
|
|
||
| import com.beowulfe.hap.HomekitCharacteristicChangeCallback; | ||
| import com.beowulfe.hap.accessories.LightSensor; | ||
| import com.beowulfe.hap.characteristics.EventableCharacteristic; | ||
| import com.beowulfe.hap.characteristics.FloatCharacteristic; | ||
|
|
||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
| public class AmbientLightLevelCharacteristic extends FloatCharacteristic implements EventableCharacteristic { | ||
|
|
||
| private final LightSensor lightSensor; | ||
|
|
||
| public AmbientLightLevelCharacteristic(LightSensor lightSensor) { | ||
| super("0000006B-0000-1000-8000-0026BB765291", false, true, "Current ambient light level", 0.0001, 100000, | ||
| 0.0001, "lux"); | ||
| this.lightSensor = lightSensor; | ||
| } | ||
|
|
||
| @Override | ||
| protected void setValue(Double value) throws Exception { | ||
| //Read Only | ||
| } | ||
|
|
||
| @Override | ||
| public void subscribe(HomekitCharacteristicChangeCallback callback) { | ||
| lightSensor.subscribeCurrentAmbientLightLevel(callback); | ||
| } | ||
|
|
||
| @Override | ||
| public void unsubscribe() { | ||
| lightSensor.unsubscribeCurrentAmbientLightLevel(); | ||
| } | ||
|
|
||
| @Override | ||
| protected CompletableFuture<Double> getDoubleValue() { | ||
| return lightSensor.getCurrentAmbientLightLevel(); | ||
| } | ||
| } |
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
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
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
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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/beowulfe/hap/impl/services/LightSensorService.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 com.beowulfe.hap.impl.services; | ||
|
|
||
| import com.beowulfe.hap.accessories.LightSensor; | ||
| import com.beowulfe.hap.impl.characteristics.light.AmbientLightLevelCharacteristic; | ||
|
|
||
| public class LightSensorService extends AbstractServiceImpl { | ||
|
|
||
| public LightSensorService(LightSensor lightSensor) { | ||
| this(lightSensor, lightSensor.getLabel()); | ||
| } | ||
|
|
||
| public LightSensorService(LightSensor lightSensor, String serviceName) { | ||
| super("00000084-0000-1000-8000-0026BB765291", lightSensor, serviceName); | ||
| addCharacteristic(new AmbientLightLevelCharacteristic(lightSensor)); | ||
| } | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should leave the old constructor. Not necessarily for API compatibility, but because I think most use cases would probably just use the accessory name. The old constructor can just call the new one with accessory.getLabel()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which, granted, wouldn't be called in any of the framework provided services - what you did with the constructors there makes sense. But still, people implementing their own services would likely find it convenient.