]> git.basschouten.com Git - openhab-addons.git/blob
fba1804fe85defe54e43d12bc289cb84f2a2949b
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13
14 package org.openhab.binding.nanoleaf.internal.layout;
15
16 import static org.openhab.binding.nanoleaf.internal.NanoleafBindingConstants.CONFIG_PANEL_ID;
17
18 import java.util.HashMap;
19 import java.util.List;
20 import java.util.Map;
21
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;
26
27 /**
28  * Stores the state of the panels.
29  *
30  * @author Jørgen Austvik - Initial contribution
31  */
32 @NonNullByDefault
33 public class PanelState {
34
35     private final Map<Integer, HSBType> panelStates = new HashMap<>();
36
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);
45             }
46         }
47     }
48
49     public HSBType getHSBForPanel(Integer panelId) {
50         return panelStates.getOrDefault(panelId, HSBType.BLACK);
51     }
52 }