2 * Copyright (c) 2010-2021 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.netatmo.internal.station;
15 import static org.openhab.binding.netatmo.internal.ChannelTypeUtils.*;
16 import static org.openhab.binding.netatmo.internal.NetatmoBindingConstants.*;
18 import java.util.Optional;
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;
26 import io.swagger.client.model.NADashboardData;
27 import io.swagger.client.model.NAStationModule;
30 * {@link NAModule2Handler} is the class used to handle the wind module
31 * capable of reporting wind angle and strength
33 * @author Gaƫl L'hopital - Initial contribution
36 public class NAModule2Handler extends NetatmoModuleHandler<NAStationModule> {
38 public NAModule2Handler(Thing thing, final TimeZoneProvider timeZoneProvider) {
39 super(thing, timeZoneProvider);
43 protected void updateProperties(NAStationModule moduleData) {
44 updateProperties(moduleData.getFirmware(), moduleData.getType());
48 protected State getNAThingProperty(String channelId) {
49 NADashboardData dashboardData = getModule().map(m -> m.getDashboardData()).orElse(null);
50 if (dashboardData != null) {
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);
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());
68 return super.getNAThingProperty(channelId);
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;