]> git.basschouten.com Git - openhab-addons.git/blob
7d180146ed3f4db758471c65c99ff690d6178245
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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 package org.openhab.binding.netatmo.internal.handler.channelhelper;
14
15 import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
16 import static org.openhab.binding.netatmo.internal.utils.ChannelTypeUtils.*;
17
18 import java.util.Set;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
23 import org.openhab.binding.netatmo.internal.api.dto.NAObject;
24 import org.openhab.binding.netatmo.internal.api.dto.Room;
25 import org.openhab.core.types.State;
26 import org.openhab.core.types.UnDefType;
27
28 /**
29  * The {@link SetpointChannelHelper} handles channels for a room capable of managing a thermostat
30  *
31  * @author GaĆ«l L'hopital - Initial contribution
32  *
33  */
34 @NonNullByDefault
35 public class SetpointChannelHelper extends ChannelHelper {
36
37     public SetpointChannelHelper(Set<String> providedGroups) {
38         super(providedGroups);
39     }
40
41     @Override
42     protected @Nullable State internalGetObject(String channelId, NAObject naObject) {
43         if (naObject instanceof Room room) {
44             switch (channelId) {
45                 case CHANNEL_SETPOINT_MODE:
46                     return toStringType(room.getSetpointMode().name());
47                 case CHANNEL_SETPOINT_START_TIME:
48                     return toDateTimeType(room.getSetpointBegin());
49                 case CHANNEL_SETPOINT_END_TIME:
50                     return toDateTimeType(room.getSetpointEnd());
51                 case CHANNEL_VALUE:
52                     switch (room.getSetpointMode()) {
53                         case OFF:
54                         case MAX:
55                             return UnDefType.UNDEF;
56                         case AWAY:
57                         case HOME:
58                         case MANUAL:
59                         case SCHEDULE:
60                         case FROST_GUARD:
61                         case PROGRAM:
62                             return toQuantityType(room.getSetpointTemp(), MeasureClass.INSIDE_TEMPERATURE);
63                         case UNKNOWN:
64                             return UnDefType.NULL;
65                     }
66             }
67         }
68         return null;
69     }
70 }