2 * Copyright (c) 2010-2024 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.haywardomnilogic.internal;
15 import static org.openhab.binding.haywardomnilogic.internal.HaywardBindingConstants.*;
17 import java.util.Collections;
19 import java.util.stream.Collectors;
20 import java.util.stream.Stream;
22 import org.eclipse.jdt.annotation.NonNullByDefault;
23 import org.eclipse.jdt.annotation.Nullable;
24 import org.eclipse.jetty.client.HttpClient;
25 import org.openhab.binding.haywardomnilogic.internal.handler.HaywardBackyardHandler;
26 import org.openhab.binding.haywardomnilogic.internal.handler.HaywardBowHandler;
27 import org.openhab.binding.haywardomnilogic.internal.handler.HaywardBridgeHandler;
28 import org.openhab.binding.haywardomnilogic.internal.handler.HaywardChlorinatorHandler;
29 import org.openhab.binding.haywardomnilogic.internal.handler.HaywardColorLogicHandler;
30 import org.openhab.binding.haywardomnilogic.internal.handler.HaywardFilterHandler;
31 import org.openhab.binding.haywardomnilogic.internal.handler.HaywardHeaterHandler;
32 import org.openhab.binding.haywardomnilogic.internal.handler.HaywardPumpHandler;
33 import org.openhab.binding.haywardomnilogic.internal.handler.HaywardRelayHandler;
34 import org.openhab.binding.haywardomnilogic.internal.handler.HaywardVirtualHeaterHandler;
35 import org.openhab.core.io.net.http.HttpClientFactory;
36 import org.openhab.core.thing.Bridge;
37 import org.openhab.core.thing.Thing;
38 import org.openhab.core.thing.ThingTypeUID;
39 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
40 import org.openhab.core.thing.binding.ThingHandler;
41 import org.openhab.core.thing.binding.ThingHandlerFactory;
42 import org.osgi.service.component.annotations.Activate;
43 import org.osgi.service.component.annotations.Component;
44 import org.osgi.service.component.annotations.Reference;
47 * The {@link HaywardHandlerFactory} is responsible for creating things and thing
50 * @author Matt Myers - Initial contribution
53 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.haywardomnilogic")
55 public class HaywardHandlerFactory extends BaseThingHandlerFactory {
57 private static final Set<ThingTypeUID> SUPPORTED_THING_TYPES_UIDS = Collections.unmodifiableSet(
58 Stream.concat(BRIDGE_THING_TYPES_UIDS.stream(), THING_TYPES_UIDS.stream()).collect(Collectors.toSet()));
59 private final HaywardDynamicStateDescriptionProvider stateDescriptionProvider;
60 private final HttpClient httpClient;
63 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
64 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
68 public HaywardHandlerFactory(final @Reference HaywardDynamicStateDescriptionProvider stateDescriptionProvider,
69 @Reference HttpClientFactory httpClientFactory) {
70 this.stateDescriptionProvider = stateDescriptionProvider;
71 this.httpClient = httpClientFactory.getCommonHttpClient();
75 * Creates the specific handler for this thing.
78 protected @Nullable ThingHandler createHandler(Thing thing) {
79 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
81 if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_BRIDGE)) {
82 return new HaywardBridgeHandler(stateDescriptionProvider, (Bridge) thing, httpClient);
84 if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_BACKYARD)) {
85 return new HaywardBackyardHandler(thing);
87 if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_BOW)) {
88 return new HaywardBowHandler(thing);
90 if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_CHLORINATOR)) {
91 return new HaywardChlorinatorHandler(thing);
93 if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_COLORLOGIC)) {
94 return new HaywardColorLogicHandler(thing);
96 if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_FILTER)) {
97 return new HaywardFilterHandler(thing);
99 if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_HEATER)) {
100 return new HaywardHeaterHandler(thing);
102 if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_PUMP)) {
103 return new HaywardPumpHandler(thing);
105 if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_RELAY)) {
106 return new HaywardRelayHandler(thing);
109 if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_VIRTUALHEATER)) {
110 return new HaywardVirtualHeaterHandler(thing);