]> git.basschouten.com Git - openhab-addons.git/blob
f1e96a0ff64ddf072723024e60af4d1d82330c17
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.haywardomnilogic.internal;
14
15 import static org.openhab.binding.haywardomnilogic.internal.HaywardBindingConstants.*;
16
17 import java.util.Collections;
18 import java.util.Set;
19 import java.util.stream.Collectors;
20 import java.util.stream.Stream;
21
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;
45
46 /**
47  * The {@link HaywardHandlerFactory} is responsible for creating things and thing
48  * handlers.
49  *
50  * @author Matt Myers - Initial contribution
51  */
52
53 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.haywardomnilogic")
54 @NonNullByDefault
55 public class HaywardHandlerFactory extends BaseThingHandlerFactory {
56
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;
61
62     @Override
63     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
64         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
65     }
66
67     @Activate
68     public HaywardHandlerFactory(final @Reference HaywardDynamicStateDescriptionProvider stateDescriptionProvider,
69             @Reference HttpClientFactory httpClientFactory) {
70         this.stateDescriptionProvider = stateDescriptionProvider;
71         this.httpClient = httpClientFactory.getCommonHttpClient();
72     }
73
74     /**
75      * Creates the specific handler for this thing.
76      */
77     @Override
78     protected @Nullable ThingHandler createHandler(Thing thing) {
79         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
80
81         if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_BRIDGE)) {
82             return new HaywardBridgeHandler(stateDescriptionProvider, (Bridge) thing, httpClient);
83         }
84         if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_BACKYARD)) {
85             return new HaywardBackyardHandler(thing);
86         }
87         if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_BOW)) {
88             return new HaywardBowHandler(thing);
89         }
90         if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_CHLORINATOR)) {
91             return new HaywardChlorinatorHandler(thing);
92         }
93         if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_COLORLOGIC)) {
94             return new HaywardColorLogicHandler(thing);
95         }
96         if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_FILTER)) {
97             return new HaywardFilterHandler(thing);
98         }
99         if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_HEATER)) {
100             return new HaywardHeaterHandler(thing);
101         }
102         if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_PUMP)) {
103             return new HaywardPumpHandler(thing);
104         }
105         if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_RELAY)) {
106             return new HaywardRelayHandler(thing);
107
108         }
109         if (thingTypeUID.equals(HaywardBindingConstants.THING_TYPE_VIRTUALHEATER)) {
110             return new HaywardVirtualHeaterHandler(thing);
111         }
112         return null;
113     }
114 }