2 * Copyright (c) 2010-2022 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.kostalinverter.internal;
15 import static org.openhab.binding.kostalinverter.internal.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.kostalinverter.internal.firstgeneration.WebscrapeHandler;
24 import org.openhab.binding.kostalinverter.internal.secondgeneration.SecondGenerationHandler;
25 import org.openhab.binding.kostalinverter.internal.thirdgeneration.ThirdGenerationHandler;
26 import org.openhab.binding.kostalinverter.internal.thirdgeneration.ThirdGenerationInverterTypes;
27 import org.openhab.core.io.net.http.HttpClientFactory;
28 import org.openhab.core.thing.Thing;
29 import org.openhab.core.thing.ThingTypeUID;
30 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
31 import org.openhab.core.thing.binding.ThingHandler;
32 import org.openhab.core.thing.binding.ThingHandlerFactory;
33 import org.osgi.service.component.annotations.Activate;
34 import org.osgi.service.component.annotations.Component;
35 import org.osgi.service.component.annotations.Reference;
38 * @author Christian Schneider - Initial contribution (as WebscrapeHandlerFactory.java)
39 * @author René Stakemeier - extension for the third generation of KOSTAL inverters
40 * @author Örjan Backsell - extension for the second generation of KOSTAL inverters
42 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.kostalinverter")
44 public class KostalInverterFactory extends BaseThingHandlerFactory {
46 private static final Map<ThingTypeUID, ThirdGenerationInverterTypes> SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS = new HashMap<>();
48 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PIKOIQ42, ThirdGenerationInverterTypes.PIKOIQ_42);
49 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PIKOIQ55, ThirdGenerationInverterTypes.PIKOIQ_55);
50 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PIKOIQ70, ThirdGenerationInverterTypes.PIKOIQ_70);
51 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PIKOIQ85, ThirdGenerationInverterTypes.PIKOIQ_85);
52 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PIKOIQ100, ThirdGenerationInverterTypes.PIKOIQ_100);
53 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS42WITHBATTERY,
54 ThirdGenerationInverterTypes.PLENTICORE_PLUS_42_WITH_BATTERY);
55 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS55WITHBATTERY,
56 ThirdGenerationInverterTypes.PLENTICORE_PLUS_55_WITH_BATTERY);
57 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS70WITHBATTERY,
58 ThirdGenerationInverterTypes.PLENTICORE_PLUS_70_WITH_BATTERY);
59 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS85WITHBATTERY,
60 ThirdGenerationInverterTypes.PLENTICORE_PLUS_85_WITH_BATTERY);
61 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS100WITHBATTERY,
62 ThirdGenerationInverterTypes.PLENTICORE_PLUS_100_WITH_BATTERY);
63 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS42WITHOUTBATTERY,
64 ThirdGenerationInverterTypes.PLENTICORE_PLUS_42_WITHOUT_BATTERY);
65 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS55WITHOUTBATTERY,
66 ThirdGenerationInverterTypes.PLENTICORE_PLUS_55_WITHOUT_BATTERY);
67 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS70WITHOUTBATTERY,
68 ThirdGenerationInverterTypes.PLENTICORE_PLUS_70_WITHOUT_BATTERY);
69 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS85WITHOUTBATTERY,
70 ThirdGenerationInverterTypes.PLENTICORE_PLUS_85_WITHOUT_BATTERY);
71 SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.put(PLENTICOREPLUS100WITHOUTBATTERY,
72 ThirdGenerationInverterTypes.PLENTICORE_PLUS_100_WITHOUT_BATTERY);
75 public static final ThingTypeUID FIRST_GENERATION_INVERTER = new ThingTypeUID("kostalinverter", "kostalinverter");
77 public static final ThingTypeUID SECOND_GENERATION_INVERTER = new ThingTypeUID("kostalinverter", "piko1020");
79 private final HttpClient httpClient;
82 public KostalInverterFactory(@Reference final HttpClientFactory httpClientFactory) {
83 this.httpClient = httpClientFactory.getCommonHttpClient();
87 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
88 return thingTypeUID.equals(FIRST_GENERATION_INVERTER) || thingTypeUID.equals(SECOND_GENERATION_INVERTER)
89 || SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS.keySet().contains(thingTypeUID);
93 protected @Nullable ThingHandler createHandler(Thing thing) {
95 if (FIRST_GENERATION_INVERTER.equals(thing.getThingTypeUID())) {
96 return new WebscrapeHandler(thing);
99 if (SECOND_GENERATION_INVERTER.equals(thing.getThingTypeUID())) {
100 return new SecondGenerationHandler(thing, httpClient);
103 ThirdGenerationInverterTypes inverterType = SUPPORTED_THIRD_GENERATION_THING_TYPES_UIDS
104 .get(thing.getThingTypeUID());
105 if (inverterType != null) {
106 return new ThirdGenerationHandler(thing, httpClient, inverterType);