2 * Copyright (c) 2010-2023 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.ambientweather.internal.processor;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.ambientweather.internal.model.EventDataJson;
18 import org.openhab.binding.ambientweather.internal.util.PressureTrend;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 import com.google.gson.JsonSyntaxException;
25 * The {@link AbstractProcessor} is the generic/error processor
26 * for info and weather updates from weather stations that are currently
27 * not supported by this binding.
29 * @author Mark Hilbush - Initial contribution
32 public abstract class AbstractProcessor implements ProcessorInterface {
34 private static final String[] UV_INDEX = {
54 private static final String[] WIND_DIRECTIONS = new String[] { "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE",
55 "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW" };
57 protected static final String NOT_APPLICABLE = "N/A";
59 protected final Logger logger = LoggerFactory.getLogger(getClass());
61 // Used to calculate barometric pressure trend
62 protected PressureTrend pressureTrend = new PressureTrend();
65 * The channel group Id for this processor
67 protected String channelGroupId = "";
70 * Used to extract remote sensor data from the data event Json
72 protected RemoteSensor remoteSensor = new RemoteSensor();
75 * Parse the event data json string
77 protected @Nullable EventDataJson parseEventData(String station, String jsonData) {
78 EventDataJson data = null;
80 logger.debug("Station {}: Parsing weather data event json", station);
81 data = ProcessorFactory.getGson().fromJson(jsonData, EventDataJson.class);
82 } catch (JsonSyntaxException e) {
83 logger.info("Station {}: Data event cannot be parsed: {}", station, e.getMessage());
89 * Convert the UV Index integer value to a string representation
91 protected String convertUVIndexToString(int uvIndex) {
92 if (uvIndex < 0 || uvIndex >= UV_INDEX.length) {
95 return UV_INDEX[uvIndex];
99 * Convert the wind directions in degrees to a string representation
101 protected String convertWindDirectionToString(double windDirectionDegrees) {
102 double step = 360.0 / WIND_DIRECTIONS.length;
103 double b = Math.floor((windDirectionDegrees + (step / 2.0)) / step);
104 return WIND_DIRECTIONS[(int) (b % WIND_DIRECTIONS.length)];