All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.zeroone3010.yahueapi.DimmerSwitchAction Maven / Gradle / Ivy

There is a newer version: 3.0.0-rc
Show newest version
package io.github.zeroone3010.yahueapi;

import java.util.stream.Stream;

public enum DimmerSwitchAction {
  INITIAL_PRESS(0),
  HOLD(1),
  SHORT_RELEASED(2),
  LONG_RELEASED(3);

  private final int eventCode;

  DimmerSwitchAction(final int eventCode) {
    this.eventCode = eventCode;
  }

  public int getEventCode() {
    return eventCode;
  }

  static DimmerSwitchAction parseFromButtonEventCode(final int buttonEvent) {
    final int eventCode = buttonEvent % 10;
    return Stream.of(values())
        .filter(value -> value.getEventCode() == eventCode)
        .findFirst()
        .orElseThrow(() -> new IllegalArgumentException("Cannot parse button event " + buttonEvent));
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy