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;
15 import java.util.List;
17 import java.util.function.Function;
18 import java.util.stream.Collectors;
19 import java.util.stream.Stream;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
24 * An enum that describes the various predefined Status Reply code values and their meanings.
26 * @author Andrew Fiddian-Green - Initial contribution
30 public enum StatusReply {
31 UNKNOWN_STATUS_REPLY(0x00),
32 COMMAND_COMPLETED_OK(0x01),
34 MANUALLY_OPERATED(0x03),
36 WRONG_SYSTEMKEY(0x05),
37 PRIORITY_LEVEL_LOCKED(0x06),
38 REACHED_WRONG_POSITION(0x07),
39 ERROR_DURING_EXECUTION(0x08),
42 POWER_CONSUMPTION_TOO_HIGH(0x0B),
43 POWER_CONSUMPTION_TOO_LOW(0x0C),
44 LOCK_POSITION_OPEN(0x0D),
45 MOTION_TIME_TOO_LONG(0x0E),
46 THERMAL_PROTECTION(0x0F),
47 PRODUCT_NOT_OPERATIONAL(0x10),
48 FILTER_MAINTENANCE_NEEDED(0x11),
50 TARGET_MODIFIED(0x13),
51 MODE_NOT_IMPLEMENTED(0x14),
52 COMMAND_INCOMPATIBLE_TO_MOVEMENT(0x15),
54 DEAD_BOLT_ERROR(0x17),
55 AUTOMATIC_CYCLE_ENGAGED(0x18),
56 WRONG_LOAD_CONNECTED(0x19),
57 COLOUR_NOT_REACHABLE(0x1A),
58 TARGET_NOT_REACHABLE(0x1B),
59 BAD_INDEX_RECEIVED(0x1C),
60 COMMAND_OVERRULED(0x1D),
61 NODE_WAITING_FOR_POWER(0x1E),
62 INFORMATION_CODE(0xDF),
63 PARAMETER_LIMITED(0xE0),
64 LIMITATION_BY_LOCAL_USER(0xE1),
65 LIMITATION_BY_USER(0xE2),
66 LIMITATION_BY_RAIN(0xE3),
67 LIMITATION_BY_TIMER(0xE4),
68 LIMITATION_BY_UPS(0xE6),
69 LIMITATION_BY_UNKNOWN_DEVICE(0xE7),
70 LIMITATION_BY_SAAC(0xEA),
71 LIMITATION_BY_WIND(0xEB),
72 LIMITATION_BY_MYSELF(0xEC),
73 LIMITATION_BY_AUTOMATIC_CYCLE(0xED),
74 LIMITATION_BY_EMERGENCY(0xEE);
76 private final int code;
78 private StatusReply(int code) {
83 * List of critical errors
85 private static final List<StatusReply> CRITICAL_ERRORS = List.of(BLOCKED, POWER_CONSUMPTION_TOO_HIGH,
86 THERMAL_PROTECTION, LOCK_POSITION_OPEN, PRODUCT_NOT_OPERATIONAL, DEAD_BOLT_ERROR, FILTER_MAINTENANCE_NEEDED,
87 BATTERY_LEVEL, NODE_WAITING_FOR_POWER);
89 public int getCode() {
93 private static final Map<Integer, StatusReply> LOOKUP = Stream.of(StatusReply.values())
94 .collect(Collectors.toMap(StatusReply::getCode, Function.identity()));
97 * Get the StatusReply value that corresponds to the given status code.
99 * @param statusReplyCode the status code value
100 * @return the StatusReply value that corresponds to the status code
102 public static StatusReply fromCode(int statusReplyCode) {
103 return LOOKUP.getOrDefault(statusReplyCode, UNKNOWN_STATUS_REPLY);
107 * Check if this Status Reply indicates an error.
109 * @return true if the status code is an error code.
111 public boolean isError() {
112 return this != COMMAND_COMPLETED_OK;
116 * Check if this Status Reply indicates a critical error.
118 * @return true if the status code is a critical error code.
120 public boolean isCriticalError() {
121 return isError() && CRITICAL_ERRORS.contains(this);