]> git.basschouten.com Git - openhab-addons.git/blob
bef052b6cb2683030cd3f21ca704bd1785ac08b5
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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 import static org.openhab.binding.netatmo.internal.utils.WeatherUtils.*;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
22 import org.openhab.binding.netatmo.internal.api.dto.Dashboard;
23 import org.openhab.core.types.State;
24
25 /**
26  * The {@link TemperatureChannelHelper} handles channels of modules measuring temperature
27  *
28  * @author GaĆ«l L'hopital - Initial contribution
29  *
30  */
31 @NonNullByDefault
32 public class TemperatureChannelHelper extends ChannelHelper {
33     /*
34      * TemperatureChannelHelper may be used by indoor or outdoor modules. There is no easy way here to decide what is
35      * the handler owning the channelHelper. The usage of OUTSIDE_TEMPERATURE instead of INSIDE_TEMPERATURE is by design
36      * because OUTSIDE_TEMPERATURE has wide value range than INSIDE_TEMPERATURE.
37      */
38     public TemperatureChannelHelper() {
39         this(GROUP_TEMPERATURE, MeasureClass.OUTSIDE_TEMPERATURE);
40     }
41
42     protected TemperatureChannelHelper(String groupName, MeasureClass measureClass) {
43         super(groupName, measureClass);
44     }
45
46     @Override
47     protected @Nullable State internalGetDashboard(String channelId, Dashboard dashboard) {
48         switch (channelId) {
49             case CHANNEL_VALUE:
50                 return toQuantityType(dashboard.getTemperature(), MeasureClass.OUTSIDE_TEMPERATURE);
51             case CHANNEL_MIN_VALUE:
52                 return toQuantityType(dashboard.getMinTemp(), MeasureClass.OUTSIDE_TEMPERATURE);
53             case CHANNEL_MAX_VALUE:
54                 return toQuantityType(dashboard.getMaxTemp(), MeasureClass.OUTSIDE_TEMPERATURE);
55             case CHANNEL_MIN_TIME:
56                 return toDateTimeType(dashboard.getDateMinTemp());
57             case CHANNEL_MAX_TIME:
58                 return toDateTimeType(dashboard.getDateMaxTemp());
59             case CHANNEL_HEAT_INDEX:
60                 return toQuantityType(heatIndex(dashboard.getTemperature(), dashboard.getHumidity()),
61                         MeasureClass.HEAT_INDEX);
62             case CHANNEL_DEWPOINT:
63                 return toQuantityType(dewPoint(dashboard.getTemperature(), dashboard.getHumidity()),
64                         MeasureClass.OUTSIDE_TEMPERATURE);
65             case CHANNEL_DEWPOINT_DEP:
66                 double dewPoint = dewPoint(dashboard.getTemperature(), dashboard.getHumidity());
67                 return toQuantityType(dewPointDep(dashboard.getTemperature(), dewPoint),
68                         MeasureClass.OUTSIDE_TEMPERATURE);
69         }
70         return null;
71     }
72 }