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.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 Ws2902bProcessor WS2902B_PROCESSOR;
41 private @Nullable static Ws8482Processor WS8482_PROCESSOR;
42 private @Nullable static Ws0900ipProcessor WS0900IP_PROCESSOR;
43 private @Nullable static Ws0265Processor WS0265_PROCESSOR;
46 * Individual weather station processors use this one Gson instance,
47 * rather than create their own.
49 * @return instance of a Gson object
51 public static Gson getGson() {
56 * Get a processor for a specific weather station type.
59 * @return instance of a weather station processor
60 * @throws ProcessorNotFoundException
62 public static AbstractProcessor getProcessor(Thing thing) throws ProcessorNotFoundException {
63 // Return the processor for this thing type
64 String thingType = thing.getThingTypeUID().getAsString().toLowerCase();
66 case "ambientweather:ws1400ip": {
67 Ws1400ipProcessor processor = WS1400IP_PROCESSOR;
68 if (processor == null) {
69 processor = new Ws1400ipProcessor();
70 WS1400IP_PROCESSOR = processor;
74 case "ambientweather:ws2902a": {
75 Ws2902aProcessor processor = WS2902A_PROCESSOR;
76 if (processor == null) {
77 processor = new Ws2902aProcessor();
78 WS2902A_PROCESSOR = processor;
82 case "ambientweather:ws2902b": {
83 Ws2902bProcessor processor = WS2902B_PROCESSOR;
84 if (processor == null) {
85 processor = new Ws2902bProcessor();
86 WS2902B_PROCESSOR = processor;
90 case "ambientweather:ws8482": {
91 Ws8482Processor processor = WS8482_PROCESSOR;
92 if (processor == null) {
93 processor = new Ws8482Processor();
94 WS8482_PROCESSOR = processor;
98 case "ambientweather:ws0900ip": {
99 Ws0900ipProcessor processor = WS0900IP_PROCESSOR;
100 if (processor == null) {
101 processor = new Ws0900ipProcessor();
102 WS0900IP_PROCESSOR = processor;
106 case "ambientweather:ws0265": {
107 Ws0265Processor processor = WS0265_PROCESSOR;
108 if (processor == null) {
109 processor = new Ws0265Processor();
110 WS0265_PROCESSOR = processor;
115 throw new ProcessorNotFoundException("No processor for thing type " + thingType);