2 * Copyright (c) 2010-2023 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.velux.internal.things;
16 import java.util.function.Function;
17 import java.util.stream.Collectors;
18 import java.util.stream.Stream;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.velux.internal.VeluxBindingConstants;
24 * <B>Velux</B> product characteristics: Velocity.
27 * "https://velcdn.azureedge.net/~/media/com/api/klf200/technical%20specification%20for%20klf%20200%20api.pdf#page=45">KLF200
28 * Velocity parameter</a>
30 * Methods in handle this type of information:
32 * <LI>{@link #getVelocity()} to retrieve the value of the characteristic.</LI>
33 * <LI>{@link #get(int)} to convert a value into the characteristic.</LI>
34 * <LI>{@link #getByName(String)} to convert a name into the characteristic.</LI>
35 * <LI>{@link #dump} to retrieve a human-readable description of all values.</LI>
40 * @author Guenther Schreiner - initial contribution.
43 public enum VeluxProductVelocity {
44 DEFAULT((short) 0, "default"),
45 SILENT((short) 1, "silent"),
46 FAST((short) 2, "fast"),
47 VELOCITY_NOT_AVAILABLE((short) 255, ""),
48 UNDEFTYPE((short) 0xffff, VeluxBindingConstants.UNKNOWN);
52 private short velocity;
53 private String velocityName;
55 // Reverse-lookup map for getting a VeluxProductVelocity from a value.
56 private static final Map<Short, VeluxProductVelocity> LOOKUPTYPEID2ENUM = Stream.of(VeluxProductVelocity.values())
57 .collect(Collectors.toMap(VeluxProductVelocity::getVelocity, Function.identity()));
61 private VeluxProductVelocity(short velocity, String velocityName) {
62 this.velocity = velocity;
63 this.velocityName = velocityName;
66 // Class access methods
68 public short getVelocity() {
72 public static VeluxProductVelocity get(short velocity) {
73 return LOOKUPTYPEID2ENUM.getOrDefault(velocity, VeluxProductVelocity.UNDEFTYPE);
76 public static VeluxProductVelocity getByName(String velocityName) {
77 for (VeluxProductVelocity enumItem : VeluxProductVelocity.values()) {
78 if (enumItem.velocityName.equals(velocityName)) {
82 return VeluxProductVelocity.UNDEFTYPE;
85 public static String dump() {
86 StringBuilder sb = new StringBuilder();
87 for (VeluxProductVelocity typeId : VeluxProductVelocity.values()) {
88 sb.append(typeId).append(VeluxBindingConstants.OUTPUT_VALUE_SEPARATOR);
90 if (sb.lastIndexOf(VeluxBindingConstants.OUTPUT_VALUE_SEPARATOR) > 0) {
91 sb.deleteCharAt(sb.lastIndexOf(VeluxBindingConstants.OUTPUT_VALUE_SEPARATOR));