io.github.zeroone3010.yahueapi.DimmerSwitchButton Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yetanotherhueapi Show documentation
Show all versions of yetanotherhueapi Show documentation
A library for controlling Philips Hue lights.
package io.github.zeroone3010.yahueapi;
import java.util.stream.Stream;
public enum DimmerSwitchButton {
ON(1),
DIM_UP(2),
DIM_DOWN(3),
OFF(4);
private final int buttonNumber;
DimmerSwitchButton(final int buttonNumber) {
this.buttonNumber = buttonNumber;
}
public int getButtonNumber() {
return buttonNumber;
}
static DimmerSwitchButton parseFromButtonEventCode(final int buttonEvent) {
final int buttonNumber = buttonEvent / 1000;
return Stream.of(values())
.filter(value -> value.getButtonNumber() == buttonNumber)
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Cannot parse button event " + buttonEvent));
}
}