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.miele.internal.handler;
15 import static org.openhab.binding.miele.internal.MieleBindingConstants.*;
17 import java.lang.reflect.Method;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.miele.internal.DeviceUtil;
22 import org.openhab.binding.miele.internal.MieleTranslationProvider;
23 import org.openhab.binding.miele.internal.api.dto.DeviceMetaData;
24 import org.openhab.core.library.types.DecimalType;
25 import org.openhab.core.library.types.OnOffType;
26 import org.openhab.core.library.types.StringType;
27 import org.openhab.core.types.State;
28 import org.openhab.core.types.Type;
29 import org.openhab.core.types.UnDefType;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 * The {@link ApplianceChannelSelector} for ventilation hoods
36 * @author Karel Goderis - Initial contribution
37 * @author Jacob Laursen - Added raw channels
40 public enum HoodChannelSelector implements ApplianceChannelSelector {
42 PRODUCT_TYPE("productTypeId", "productType", StringType.class, true),
43 DEVICE_TYPE("mieleDeviceType", "deviceType", StringType.class, true),
44 STATE_TEXT(STATE_PROPERTY_NAME, STATE_TEXT_CHANNEL_ID, StringType.class, false) {
46 public State getState(String s, @Nullable DeviceMetaData dmd, MieleTranslationProvider translationProvider) {
47 return DeviceUtil.getStateTextState(s, dmd, translationProvider);
50 STATE("", STATE_CHANNEL_ID, DecimalType.class, false),
51 VENTILATION("ventilationPower", "ventilation", DecimalType.class, false),
52 LIGHT("lightingStatus", "light", OnOffType.class, false) {
55 public State getState(String s, @Nullable DeviceMetaData dmd, MieleTranslationProvider translationProvider) {
56 if ("true".equals(s)) {
57 return getState("ON");
60 if ("false".equals(s)) {
61 return getState("OFF");
64 return UnDefType.UNDEF;
67 STOP("", "stop", OnOffType.class, false);
69 private final Logger logger = LoggerFactory.getLogger(HoodChannelSelector.class);
71 private final String mieleID;
72 private final String channelID;
73 private final Class<? extends Type> typeClass;
74 private final boolean isProperty;
76 HoodChannelSelector(String propertyID, String channelID, Class<? extends Type> typeClass, boolean isProperty) {
77 this.mieleID = propertyID;
78 this.channelID = channelID;
79 this.typeClass = typeClass;
80 this.isProperty = isProperty;
84 public String toString() {
89 public String getMieleID() {
94 public String getChannelID() {
99 public boolean isProperty() {
104 public boolean isExtendedState() {
109 public State getState(String s, @Nullable DeviceMetaData dmd, MieleTranslationProvider translationProvider) {
110 return this.getState(s, dmd);
114 public State getState(String s, @Nullable DeviceMetaData dmd) {
116 String localizedValue = dmd.getMieleEnum(s);
117 if (localizedValue == null) {
118 localizedValue = dmd.LocalizedValue;
120 if (localizedValue == null) {
124 return getState(localizedValue);
130 public State getState(String s) {
132 Method valueOf = typeClass.getMethod("valueOf", String.class);
133 State state = (State) valueOf.invoke(typeClass, s);
137 } catch (Exception e) {
138 logger.warn("An exception occurred while converting '{}' into a State", s);
141 return UnDefType.UNDEF;