]> git.basschouten.com Git - openhab-addons.git/blob
1eb9ad301cd5acfe7fbc7d12be78c7bb7bdae5c2
[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.fineoffsetweatherstation.internal.domain;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetGatewayConfiguration;
18 import org.openhab.binding.fineoffsetweatherstation.internal.handler.ThingStatusListener;
19 import org.openhab.binding.fineoffsetweatherstation.internal.service.ELVGatewayQueryService;
20 import org.openhab.binding.fineoffsetweatherstation.internal.service.FineOffsetGatewayQueryService;
21 import org.openhab.binding.fineoffsetweatherstation.internal.service.GatewayQueryService;
22
23 /**
24  * The protocol defining the way the data is parsed
25  *
26  * @author Andreas Berger - Initial contribution
27  */
28 @NonNullByDefault
29 public enum Protocol {
30     DEFAULT(FineOffsetGatewayQueryService::new, null),
31     ELV(ELVGatewayQueryService::new, Measurand.ParserCustomizationType.ELV);
32
33     private final GatewayQueryServiceFactory queryServiceFactory;
34     private final Measurand.@Nullable ParserCustomizationType parserCustomizationType;
35
36     Protocol(GatewayQueryServiceFactory queryServiceFactory,
37             Measurand.@Nullable ParserCustomizationType parserCustomizationType) {
38         this.queryServiceFactory = queryServiceFactory;
39         this.parserCustomizationType = parserCustomizationType;
40     }
41
42     public Measurand.@Nullable ParserCustomizationType getParserCustomizationType() {
43         return parserCustomizationType;
44     }
45
46     public GatewayQueryService getGatewayQueryService(FineOffsetGatewayConfiguration config,
47             @Nullable ThingStatusListener thingStatusListener, ConversionContext conversionContext) {
48         return queryServiceFactory.newInstance(config, thingStatusListener, conversionContext);
49     }
50
51     private interface GatewayQueryServiceFactory {
52         GatewayQueryService newInstance(FineOffsetGatewayConfiguration config,
53                 @Nullable ThingStatusListener thingStatusListener, ConversionContext conversionContext);
54     }
55 }