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.io.imperihome.internal.model.device;
16 import java.util.stream.Collectors;
18 import org.openhab.core.items.Item;
19 import org.openhab.core.library.types.DecimalType;
20 import org.openhab.core.types.State;
21 import org.openhab.io.imperihome.internal.model.param.DeviceParam;
22 import org.openhab.io.imperihome.internal.model.param.ParamType;
25 * MultiSwitch device, mimics behavior of an OH Switch with a mapping.
27 * @author Pepijn de Geus - Initial contribution
29 public class MultiSwitchDevice extends AbstractDevice {
31 private String itemValue = "";
33 public MultiSwitchDevice(Item item) {
34 super(DeviceType.MULTI_SWITCH, item);
38 public void updateParams() {
41 Map<String, String> mapping = getMapping();
42 if (mapping == null || mapping.isEmpty()) {
43 logger.error("MultiSwitch device {} contains no mapping", this);
47 DeviceParam choicesParam = new DeviceParam(ParamType.CHOICES,
48 mapping.values().stream().collect(Collectors.joining(",")));
49 addParam(choicesParam);
51 // Find current value text
52 String currentValue = "";
53 if (mapping.containsKey(itemValue)) {
54 currentValue = mapping.get(itemValue);
57 DeviceParam valueParam = new DeviceParam(ParamType.MULTISWITCH_VALUE, currentValue);
62 public void stateUpdated(Item item, State newState) {
63 super.stateUpdated(item, newState);
65 State state = item.getStateAs(DecimalType.class);
66 if (state instanceof DecimalType) {
67 itemValue = String.valueOf(((DecimalType) state).intValue());