-
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.
Detect scenes being activated and temporarily disable turn-on events (#…
…12) For affected lights and groups.
- Loading branch information
1 parent
2702aeb
commit 44f0579
Showing
23 changed files
with
966 additions
and
68 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package at.sv.hue.api; | ||
|
||
public interface SceneEventListener { | ||
void onSceneActivated(String id); | ||
|
||
boolean wasRecentlyAffectedByAScene(String id); | ||
} |
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,41 @@ | ||
package at.sv.hue.api; | ||
|
||
import com.github.benmanes.caffeine.cache.Cache; | ||
import com.github.benmanes.caffeine.cache.Caffeine; | ||
import com.github.benmanes.caffeine.cache.Ticker; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.slf4j.MDC; | ||
|
||
import java.time.Duration; | ||
import java.util.List; | ||
|
||
@Slf4j | ||
public final class SceneEventListenerImpl implements SceneEventListener { | ||
|
||
private final HueApi hueApi; | ||
private final Cache<String, String> recentlyAffectedIds; | ||
|
||
public SceneEventListenerImpl(HueApi hueApi, Ticker ticker, int ignoreWindowInSeconds) { | ||
this.hueApi = hueApi; | ||
recentlyAffectedIds = Caffeine.newBuilder() | ||
.ticker(ticker) | ||
.expireAfterWrite(Duration.ofSeconds(ignoreWindowInSeconds)) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public void onSceneActivated(String id) { | ||
MDC.put("context", "on-event " + id); | ||
List<String> sceneLights = hueApi.getAffectedIdsByScene(id); | ||
sceneLights.forEach(lightId -> recentlyAffectedIds.put(lightId, lightId)); | ||
sceneLights.stream() | ||
.flatMap(light -> hueApi.getAssignedGroups(light).stream()) | ||
.distinct() | ||
.forEach(groupId -> recentlyAffectedIds.put(groupId, groupId)); | ||
} | ||
|
||
@Override | ||
public boolean wasRecentlyAffectedByAScene(String id) { | ||
return recentlyAffectedIds.getIfPresent(id) != null; | ||
} | ||
} |
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
Oops, something went wrong.