2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.lifx.internal.protocol;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.lifx.internal.LifxBindingConstants;
18 import org.openhab.binding.lifx.internal.fields.HSBK;
21 * This class represents LIFX Tile effect
23 * @author Pawel Pieczul - initial contribution
27 public enum EffectType {
34 EffectType(Integer type) {
38 public static EffectType fromValue(Integer value) {
47 throw new IllegalArgumentException("Unknown effect type");
51 public static EffectType fromValue(String value) {
52 if (LifxBindingConstants.CHANNEL_TYPE_EFFECT_OPTION_OFF.equals(value)) {
54 } else if (LifxBindingConstants.CHANNEL_TYPE_EFFECT_OPTION_MORPH.equals(value)) {
56 } else if (LifxBindingConstants.CHANNEL_TYPE_EFFECT_OPTION_FLAME.equals(value)) {
59 throw new IllegalArgumentException("Unknown effect type");
62 public Integer intValue() {
66 public String stringValue() {
69 return LifxBindingConstants.CHANNEL_TYPE_EFFECT_OPTION_MORPH;
71 return LifxBindingConstants.CHANNEL_TYPE_EFFECT_OPTION_FLAME;
73 return LifxBindingConstants.CHANNEL_TYPE_EFFECT_OPTION_OFF;
78 final EffectType type;
83 public EffectType getType() {
87 public Long getSpeed() {
91 public Long getDuration() {
99 public Effect(EffectType type, Long speed, Long duration, HSBK[] palette) {
101 this.palette = palette;
102 this.duration = duration;
106 public Effect(Integer type, Long speed, Long duration, HSBK[] palette) {
107 this(EffectType.fromValue(type), speed, duration, palette);
111 this(EffectType.OFF, 3000L, 0L, new HSBK[0]);
114 public static Effect createDefault(String type, @Nullable Long morphSpeed, @Nullable Long flameSpeed) {
116 EffectType effectType = EffectType.fromValue(type);
117 switch (effectType) {
119 return new Effect(effectType, 0L, 0L, new HSBK[0]);
121 if (morphSpeed == null) {
126 HSBK[] p = { new HSBK(0, 65535, 65535, 3500), new HSBK(7281, 65535, 65535, 3500),
127 new HSBK(10922, 65535, 65535, 3500), new HSBK(22209, 65535, 65535, 3500),
128 new HSBK(43507, 65535, 65535, 3500), new HSBK(49333, 65535, 65535, 3500),
129 new HSBK(53520, 65535, 65535, 3500) };
130 return new Effect(effectType, speed, 0L, p);
132 if (flameSpeed == null) {
137 return new Effect(effectType, speed, 0L, new HSBK[0]);
139 throw new IllegalArgumentException("Unknown effect type");
144 public boolean equals(@Nullable Object o) {
151 if (o.getClass() != getClass()) {
154 Effect n = (Effect) o;
155 return n.getType().equals(this.getType()) && n.duration.equals(this.duration) && n.speed.equals(this.speed)
156 && n.palette == this.palette;
160 public int hashCode() {
163 hash = prime * hash + type.hashCode();
164 hash = prime * hash + duration;
165 hash = prime * hash + speed;
166 hash = prime * hash + palette.hashCode();
167 return hash.intValue();