2 * Copyright (c) 2010-2020 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.core.thing.Thing;
19 import com.google.gson.Gson;
22 * The {@link ProcessorFactory} is responsible for returning the right
23 * processor for handling info update and weather data events.
25 * There is one processor for each supported station type.
26 * To add support for a new station type, this class needs to be modified to
27 * return a processor for the new thing type. In addition, an
28 * AmbientWeatherXXXXXProcessor class needs to be created for the new station.
30 * @author Mark Hilbush - Initial contribution
33 public class ProcessorFactory {
34 // Single Gson instance shared by processors
35 private static final Gson GSON = new Gson();
37 // Supported weather stations
38 private @Nullable static Ws1400ipProcessor WS1400IP_PROCESSOR;
39 private @Nullable static Ws2902aProcessor WS2902A_PROCESSOR;
40 private @Nullable static Ws8482Processor WS8482_PROCESSOR;
41 private @Nullable static Ws0900ipProcessor WS0900IP_PROCESSOR;
42 private @Nullable static Ws0265Processor WS0265_PROCESSOR;
45 * Individual weather station processors use this one Gson instance,
46 * rather than create their own.
48 * @return instance of a Gson object
50 public static Gson getGson() {
55 * Get a processor for a specific weather station type.
58 * @return instance of a weather station processor
59 * @throws ProcessorNotFoundException
61 public static AbstractProcessor getProcessor(Thing thing) throws ProcessorNotFoundException {
62 // Return the processor for this thing type
63 String thingType = thing.getThingTypeUID().getAsString().toLowerCase();
65 case "ambientweather:ws1400ip": {
66 Ws1400ipProcessor processor = WS1400IP_PROCESSOR;
67 if (processor == null) {
68 processor = new Ws1400ipProcessor();
69 WS1400IP_PROCESSOR = processor;
73 case "ambientweather:ws2902a": {
74 Ws2902aProcessor processor = WS2902A_PROCESSOR;
75 if (processor == null) {
76 processor = new Ws2902aProcessor();
77 WS2902A_PROCESSOR = processor;
81 case "ambientweather:ws8482": {
82 Ws8482Processor processor = WS8482_PROCESSOR;
83 if (processor == null) {
84 processor = new Ws8482Processor();
85 WS8482_PROCESSOR = processor;
89 case "ambientweather:ws0900ip": {
90 Ws0900ipProcessor processor = WS0900IP_PROCESSOR;
91 if (processor == null) {
92 processor = new Ws0900ipProcessor();
93 WS0900IP_PROCESSOR = processor;
97 case "ambientweather:ws0265": {
98 Ws0265Processor processor = WS0265_PROCESSOR;
99 if (processor == null) {
100 processor = new Ws0265Processor();
101 WS0265_PROCESSOR = processor;
106 throw new ProcessorNotFoundException("No processor for thing type " + thingType);