]> git.basschouten.com Git - openhab-addons.git/blob
37b05ace3fa35a58734c7fcb1a2e5bd579308189
[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) {
44             Room room = (Room) naObject;
45             switch (channelId) {
46                 case CHANNEL_SETPOINT_MODE:
47                     return toStringType(room.getSetpointMode().name());
48                 case CHANNEL_SETPOINT_START_TIME:
49                     return toDateTimeType(room.getSetpointBegin());
50                 case CHANNEL_SETPOINT_END_TIME:
51                     return toDateTimeType(room.getSetpointEnd());
52                 case CHANNEL_VALUE:
53                     switch (room.getSetpointMode()) {
54                         case OFF:
55                         case MAX:
56                             return UnDefType.UNDEF;
57                         case AWAY:
58                         case HOME:
59                         case MANUAL:
60                         case SCHEDULE:
61                         case FROST_GUARD:
62                         case PROGRAM:
63                             return toQuantityType(room.getSetpointTemp(), MeasureClass.INSIDE_TEMPERATURE);
64                         case UNKNOWN:
65                             return UnDefType.NULL;
66                     }
67             }
68         }
69         return null;
70     }
71 }