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.internal.kostal.inverter;
15 import static org.openhab.binding.internal.kostal.inverter.thirdgeneration.ThirdGenerationBindingConstants.*;
17 import java.util.HashMap;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.eclipse.jetty.client.HttpClient;
23 import org.openhab.binding.internal.kostal.inverter.firstgeneration.WebscrapeHandler;
24 import org.openhab.binding.internal.kostal.inverter.thirdgeneration.ThirdGenerationHandler;
25 import org.openhab.binding.internal.kostal.inverter.thirdgeneration.ThirdGenerationInverterTypes;
26 import org.openhab.core.io.net.http.HttpClientFactory;
27 import org.openhab.core.thing.Thing;
28 import org.openhab.core.thing.ThingTypeUID;
29 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
30 import org.openhab.core.thing.binding.ThingHandler;
31 import org.openhab.core.thing.binding.ThingHandlerFactory;
32 import org.osgi.service.component.annotations.Activate;
33 import org.osgi.service.component.annotations.Component;
34 import org.osgi.service.component.annotations.Reference;
37 * @author Christian Schneider - Initial contribution (as WebscrapeHandlerFactory.java)
38 * @author René Stakemeier - extension for the third generation of KOSTAL inverters
40 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.kostalinverter")
42 public class KostalInverterFactory extends BaseThingHandlerFactory {
44 private static final Map<ThingTypeUID, ThirdGenerationInverterTypes> SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS = new HashMap<>();
46 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PIKOIQ42, ThirdGenerationInverterTypes.PIKOIQ_42);
47 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PIKOIQ55, ThirdGenerationInverterTypes.PIKOIQ_55);
48 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PIKOIQ70, ThirdGenerationInverterTypes.PIKOIQ_70);
49 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PIKOIQ85, ThirdGenerationInverterTypes.PIKOIQ_85);
50 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PIKOIQ100, ThirdGenerationInverterTypes.PIKOIQ_100);
51 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS42WITHBATTERY,
52 ThirdGenerationInverterTypes.PLENTICORE_PLUS_42_WITH_BATTERY);
53 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS55WITHBATTERY,
54 ThirdGenerationInverterTypes.PLENTICORE_PLUS_55_WITH_BATTERY);
55 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS70WITHBATTERY,
56 ThirdGenerationInverterTypes.PLENTICORE_PLUS_70_WITH_BATTERY);
57 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS85WITHBATTERY,
58 ThirdGenerationInverterTypes.PLENTICORE_PLUS_85_WITH_BATTERY);
59 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS100WITHBATTERY,
60 ThirdGenerationInverterTypes.PLENTICORE_PLUS_100_WITH_BATTERY);
61 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS42WITHOUTBATTERY,
62 ThirdGenerationInverterTypes.PLENTICORE_PLUS_42_WITHOUT_BATTERY);
63 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS55WITHOUTBATTERY,
64 ThirdGenerationInverterTypes.PLENTICORE_PLUS_55_WITHOUT_BATTERY);
65 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS70WITHOUTBATTERY,
66 ThirdGenerationInverterTypes.PLENTICORE_PLUS_70_WITHOUT_BATTERY);
67 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS85WITHOUTBATTERY,
68 ThirdGenerationInverterTypes.PLENTICORE_PLUS_85_WITHOUT_BATTERY);
69 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS100WITHOUTBATTERY,
70 ThirdGenerationInverterTypes.PLENTICORE_PLUS_100_WITHOUT_BATTERY);
73 public static final ThingTypeUID FIRST_GENERATION_INVERTER = new ThingTypeUID("kostalinverter", "kostalinverter");
75 private final HttpClient httpClient;
78 public KostalInverterFactory(@Reference final HttpClientFactory httpClientFactory) {
79 this.httpClient = httpClientFactory.getCommonHttpClient();
83 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
84 return thingTypeUID.equals(FIRST_GENERATION_INVERTER)
85 || SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.keySet().contains(thingTypeUID);
89 protected @Nullable ThingHandler createHandler(Thing thing) {
91 if (FIRST_GENERATION_INVERTER.equals(thing.getThingTypeUID())) {
92 return new WebscrapeHandler(thing);
95 if (SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.containsKey(thing.getThingTypeUID())) {
96 return new ThirdGenerationHandler(thing, httpClient,
97 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.get(thing.getThingTypeUID()));