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.mielecloud.internal.webservice.api.json;
15 import java.util.Arrays;
16 import java.util.Collections;
17 import java.util.List;
18 import java.util.stream.Collectors;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
24 * Represents the state of a light on a Miele device.
26 * @author Roland Edelhoff - Initial contribution
27 * @author Björn Lange - Added NOT_SUPPORTED entry
32 * {Light} for unknown states.
40 NOT_SUPPORTED(0, 255);
42 private List<Integer> ids;
45 this.ids = Collections.unmodifiableList(Arrays.stream(ids).boxed().collect(Collectors.toList()));
49 * Gets the {@link Light} state matching the given ID.
52 * @return The matching {@link Light} or {@code UNKNOWN} if no ID matches.
54 public static Light fromId(@Nullable Integer id) {
55 for (Light light : Light.values()) {
56 if (light.ids.contains(id)) {
65 * Formats this instance for interaction with the Miele webservice.
67 public String format() {
71 return Integer.toString(ids.get(0));