2 * Copyright (c) 2010-2022 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
14 package org.openhab.binding.nanoleaf.internal.layout;
16 import static org.openhab.binding.nanoleaf.internal.NanoleafBindingConstants.CONFIG_PANEL_ID;
18 import java.util.HashMap;
19 import java.util.List;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.openhab.binding.nanoleaf.internal.handler.NanoleafPanelHandler;
24 import org.openhab.core.library.types.HSBType;
25 import org.openhab.core.thing.Thing;
28 * Stores the state of the panels.
30 * @author Jørgen Austvik - Initial contribution
33 public class PanelState {
35 private final Map<Integer, HSBType> panelStates = new HashMap<>();
37 public PanelState(List<Thing> panels) {
38 for (Thing panel : panels) {
39 Integer panelId = Integer.valueOf(panel.getConfiguration().get(CONFIG_PANEL_ID).toString());
40 NanoleafPanelHandler panelHandler = (NanoleafPanelHandler) panel.getHandler();
41 if (panelHandler != null) {
42 HSBType c = panelHandler.getColor();
43 HSBType color = (c == null) ? HSBType.BLACK : c;
44 panelStates.put(panelId, color);
49 public HSBType getHSBForPanel(Integer panelId) {
50 return panelStates.getOrDefault(panelId, HSBType.BLACK);