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.enphase.internal;
15 import static org.openhab.binding.enphase.internal.EnphaseBindingConstants.*;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.eclipse.jetty.client.HttpClient;
22 import org.openhab.binding.enphase.internal.handler.EnphaseInverterHandler;
23 import org.openhab.binding.enphase.internal.handler.EnphaseRelayHandler;
24 import org.openhab.binding.enphase.internal.handler.EnvoyBridgeHandler;
25 import org.openhab.core.i18n.LocaleProvider;
26 import org.openhab.core.i18n.TranslationProvider;
27 import org.openhab.core.io.net.http.HttpClientFactory;
28 import org.openhab.core.thing.Bridge;
29 import org.openhab.core.thing.Thing;
30 import org.openhab.core.thing.ThingTypeUID;
31 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
32 import org.openhab.core.thing.binding.ThingHandler;
33 import org.openhab.core.thing.binding.ThingHandlerFactory;
34 import org.osgi.service.component.annotations.Activate;
35 import org.osgi.service.component.annotations.Component;
36 import org.osgi.service.component.annotations.Reference;
39 * The {@link EnphaseHandlerFactory} is responsible for creating things and thing
42 * @author Hilbrand Bouwkamp - Initial contribution
45 @Component(configurationPid = "binding.enphase", service = ThingHandlerFactory.class)
46 public class EnphaseHandlerFactory extends BaseThingHandlerFactory {
48 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Set.of(THING_TYPE_ENPHASE_ENVOY,
49 THING_TYPE_ENPHASE_INVERTER, THING_TYPE_ENPHASE_RELAY);
51 private final MessageTranslator messageTranslator;
52 private final HttpClient commonHttpClient;
53 private final EnvoyHostAddressCache envoyHostAddressCache;
56 public EnphaseHandlerFactory(final @Reference LocaleProvider localeProvider,
57 final @Reference TranslationProvider i18nProvider, final @Reference HttpClientFactory httpClientFactory,
58 @Reference final EnvoyHostAddressCache envoyHostAddressCache) {
59 messageTranslator = new MessageTranslator(localeProvider, i18nProvider);
60 commonHttpClient = httpClientFactory.getCommonHttpClient();
61 this.envoyHostAddressCache = envoyHostAddressCache;
65 public boolean supportsThingType(final ThingTypeUID thingTypeUID) {
66 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
70 protected @Nullable ThingHandler createHandler(final Thing thing) {
71 final ThingTypeUID thingTypeUID = thing.getThingTypeUID();
73 if (THING_TYPE_ENPHASE_ENVOY.equals(thingTypeUID)) {
74 return new EnvoyBridgeHandler((Bridge) thing, commonHttpClient, envoyHostAddressCache);
75 } else if (THING_TYPE_ENPHASE_INVERTER.equals(thingTypeUID)) {
76 return new EnphaseInverterHandler(thing, messageTranslator);
77 } else if (THING_TYPE_ENPHASE_RELAY.equals(thingTypeUID)) {
78 return new EnphaseRelayHandler(thing, messageTranslator);