]> git.basschouten.com Git - openhab-addons.git/blob
913b5ad13cd0da23e7a7d38b383f7c1ea6ba4636
[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 java.util.Set;
20
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.MeasureClass;
24 import org.openhab.binding.netatmo.internal.api.dto.Dashboard;
25 import org.openhab.core.types.State;
26
27 /**
28  * The {@link TemperatureChannelHelper} handles channels of modules measuring temperature
29  *
30  * @author GaĆ«l L'hopital - Initial contribution
31  *
32  */
33 @NonNullByDefault
34 public class TemperatureChannelHelper extends ChannelHelper {
35
36     public TemperatureChannelHelper(Set<String> providedGroups) {
37         super(providedGroups);
38     }
39
40     @Override
41     protected @Nullable State internalGetDashboard(String channelId, Dashboard dashboard) {
42         switch (channelId) {
43             case CHANNEL_VALUE:
44                 return toQuantityType(dashboard.getTemperature(), MeasureClass.OUTSIDE_TEMPERATURE);
45             case CHANNEL_MIN_VALUE:
46                 return toQuantityType(dashboard.getMinTemp(), MeasureClass.OUTSIDE_TEMPERATURE);
47             case CHANNEL_MAX_VALUE:
48                 return toQuantityType(dashboard.getMaxTemp(), MeasureClass.OUTSIDE_TEMPERATURE);
49             case CHANNEL_MIN_TIME:
50                 return toDateTimeType(dashboard.getDateMinTemp());
51             case CHANNEL_MAX_TIME:
52                 return toDateTimeType(dashboard.getDateMaxTemp());
53             case CHANNEL_HEAT_INDEX:
54                 return toQuantityType(heatIndex(dashboard.getTemperature(), dashboard.getHumidity()),
55                         MeasureClass.HEAT_INDEX);
56             case CHANNEL_DEWPOINT:
57                 return toQuantityType(dewPoint(dashboard.getTemperature(), dashboard.getHumidity()),
58                         MeasureClass.OUTSIDE_TEMPERATURE);
59             case CHANNEL_DEWPOINT_DEP:
60                 double dewPoint = dewPoint(dashboard.getTemperature(), dashboard.getHumidity());
61                 return toQuantityType(dewPointDep(dashboard.getTemperature(), dewPoint),
62                         MeasureClass.OUTSIDE_TEMPERATURE);
63             case CHANNEL_TREND:
64                 return toStringType(dashboard.getTempTrend());
65         }
66         return null;
67     }
68 }