]> git.basschouten.com Git - openhab-addons.git/blob
82f8ffe3083e97cae8d4ac75eedfde4b11a670f6
[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.station;
14
15 import static org.openhab.binding.netatmo.internal.ChannelTypeUtils.*;
16 import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
17
18 import java.util.Optional;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.netatmo.internal.handler.NetatmoModuleHandler;
22 import org.openhab.core.i18n.TimeZoneProvider;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.types.State;
25
26 import io.swagger.client.model.NADashboardData;
27 import io.swagger.client.model.NAStationModule;
28
29 /**
30  * {@link NAModule2Handler} is the class used to handle the wind module
31  * capable of reporting wind angle and strength
32  *
33  * @author GaĆ«l L'hopital - Initial contribution
34  */
35 @NonNullByDefault
36 public class NAModule2Handler extends NetatmoModuleHandler<NAStationModule> {
37
38     public NAModule2Handler(Thing thing, final TimeZoneProvider timeZoneProvider) {
39         super(thing, timeZoneProvider);
40     }
41
42     @Override
43     protected void updateProperties(NAStationModule moduleData) {
44         updateProperties(moduleData.getFirmware(), moduleData.getType());
45     }
46
47     @Override
48     protected State getNAThingProperty(String channelId) {
49         NADashboardData dashboardData = getModule().map(m -> m.getDashboardData()).orElse(null);
50         if (dashboardData != null) {
51             switch (channelId) {
52                 case CHANNEL_WIND_ANGLE:
53                     return toQuantityType(dashboardData.getWindAngle(), API_WIND_DIRECTION_UNIT);
54                 case CHANNEL_WIND_STRENGTH:
55                     return toQuantityType(dashboardData.getWindStrength(), API_WIND_SPEED_UNIT);
56                 case CHANNEL_GUST_ANGLE:
57                     return toQuantityType(dashboardData.getGustAngle(), API_WIND_DIRECTION_UNIT);
58                 case CHANNEL_GUST_STRENGTH:
59                     return toQuantityType(dashboardData.getGustStrength(), API_WIND_SPEED_UNIT);
60                 case CHANNEL_TIMEUTC:
61                     return toDateTimeType(dashboardData.getTimeUtc(), timeZoneProvider.getTimeZone());
62                 case CHANNEL_MAX_WIND_STRENGTH:
63                     return toQuantityType(dashboardData.getMaxWindStr(), API_WIND_SPEED_UNIT);
64                 case CHANNEL_DATE_MAX_WIND_STRENGTH:
65                     return toDateTimeType(dashboardData.getDateMaxWindStr(), timeZoneProvider.getTimeZone());
66             }
67         }
68         return super.getNAThingProperty(channelId);
69     }
70
71     @Override
72     protected boolean isReachable() {
73         boolean result = false;
74         Optional<NAStationModule> module = getModule();
75         if (module.isPresent()) {
76             Boolean reachable = module.get().isReachable();
77             result = reachable != null ? reachable.booleanValue() : false;
78         }
79         return result;
80     }
81 }