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
13 package org.openhab.binding.miele.internal.handler;
15 import static org.openhab.binding.miele.internal.MieleBindingConstants.*;
17 import java.lang.reflect.Method;
19 import org.openhab.binding.miele.internal.DeviceMetaData;
20 import org.openhab.binding.miele.internal.DeviceUtil;
21 import org.openhab.binding.miele.internal.MieleTranslationProvider;
22 import org.openhab.core.library.types.DecimalType;
23 import org.openhab.core.library.types.OnOffType;
24 import org.openhab.core.library.types.StringType;
25 import org.openhab.core.types.State;
26 import org.openhab.core.types.Type;
27 import org.openhab.core.types.UnDefType;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * The {@link ApplianceChannelSelector} for ventilation hoods
34 * @author Karel Goderis - Initial contribution
35 * @author Jacob Laursen - Added raw channels
37 public enum HoodChannelSelector implements ApplianceChannelSelector {
39 PRODUCT_TYPE("productTypeId", "productType", StringType.class, true),
40 DEVICE_TYPE("mieleDeviceType", "deviceType", StringType.class, true),
41 STATE_TEXT(STATE_PROPERTY_NAME, STATE_TEXT_CHANNEL_ID, StringType.class, false) {
43 public State getState(String s, DeviceMetaData dmd, MieleTranslationProvider translationProvider) {
44 State state = DeviceUtil.getStateTextState(s, dmd, translationProvider);
48 return super.getState(s, dmd, translationProvider);
51 STATE(null, STATE_CHANNEL_ID, DecimalType.class, false),
52 VENTILATION("ventilationPower", "ventilation", DecimalType.class, false),
53 LIGHT("lightingStatus", "light", OnOffType.class, false) {
56 public State getState(String s, DeviceMetaData dmd, MieleTranslationProvider translationProvider) {
57 if ("true".equals(s)) {
58 return getState("ON");
61 if ("false".equals(s)) {
62 return getState("OFF");
65 return UnDefType.UNDEF;
68 STOP(null, "stop", OnOffType.class, false);
70 private final Logger logger = LoggerFactory.getLogger(HoodChannelSelector.class);
72 private final String mieleID;
73 private final String channelID;
74 private final Class<? extends Type> typeClass;
75 private final boolean isProperty;
77 HoodChannelSelector(String propertyID, String channelID, Class<? extends Type> typeClass, boolean isProperty) {
78 this.mieleID = propertyID;
79 this.channelID = channelID;
80 this.typeClass = typeClass;
81 this.isProperty = isProperty;
85 public String toString() {
90 public String getMieleID() {
95 public String getChannelID() {
100 public boolean isProperty() {
105 public boolean isExtendedState() {
110 public State getState(String s, DeviceMetaData dmd, MieleTranslationProvider translationProvider) {
111 return this.getState(s, dmd);
115 public State getState(String s, DeviceMetaData dmd) {
117 String localizedValue = dmd.getMieleEnum(s);
118 if (localizedValue == null) {
119 localizedValue = dmd.LocalizedValue;
121 if (localizedValue == null) {
125 return getState(localizedValue);
131 public State getState(String s) {
133 Method valueOf = typeClass.getMethod("valueOf", String.class);
134 State state = (State) valueOf.invoke(typeClass, s);
138 } catch (Exception e) {
139 logger.error("An exception occurred while converting '{}' into a State", s);