]> git.basschouten.com Git - openhab-addons.git/blob
9276720c30643dc9da82a7b590122149d110bb00
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.draytonwiser.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.eclipse.jetty.client.HttpClient;
18 import org.openhab.binding.draytonwiser.internal.handler.ControllerHandler;
19 import org.openhab.binding.draytonwiser.internal.handler.HeatHubHandler;
20 import org.openhab.binding.draytonwiser.internal.handler.HotWaterHandler;
21 import org.openhab.binding.draytonwiser.internal.handler.RoomHandler;
22 import org.openhab.binding.draytonwiser.internal.handler.RoomStatHandler;
23 import org.openhab.binding.draytonwiser.internal.handler.SmartPlugHandler;
24 import org.openhab.binding.draytonwiser.internal.handler.TRVHandler;
25 import org.openhab.core.io.net.http.HttpClientFactory;
26 import org.openhab.core.thing.Bridge;
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;
35
36 /**
37  * The {@link DraytonWiserHandlerFactory} is responsible for creating things and thing
38  * handlers.
39  *
40  * @author Andrew Schofield - Initial contribution
41  */
42 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.draytonwiser")
43 @NonNullByDefault
44 public class DraytonWiserHandlerFactory extends BaseThingHandlerFactory {
45
46     private final HttpClient httpClient;
47
48     @Activate
49     public DraytonWiserHandlerFactory(@Reference final HttpClientFactory factory) {
50         httpClient = factory.getCommonHttpClient();
51     }
52
53     @Override
54     public boolean supportsThingType(final ThingTypeUID thingTypeUID) {
55         return DraytonWiserBindingConstants.SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
56     }
57
58     @Override
59     protected @Nullable ThingHandler createHandler(final Thing thing) {
60         final ThingTypeUID thingTypeUID = thing.getThingTypeUID();
61
62         if (DraytonWiserBindingConstants.THING_TYPE_BRIDGE.equals(thingTypeUID)) {
63             return new HeatHubHandler((Bridge) thing, httpClient);
64         } else if (DraytonWiserBindingConstants.THING_TYPE_ROOM.equals(thingTypeUID)) {
65             return new RoomHandler(thing);
66         } else if (DraytonWiserBindingConstants.THING_TYPE_ROOMSTAT.equals(thingTypeUID)) {
67             return new RoomStatHandler(thing);
68         } else if (DraytonWiserBindingConstants.THING_TYPE_ITRV.equals(thingTypeUID)) {
69             return new TRVHandler(thing);
70         } else if (DraytonWiserBindingConstants.THING_TYPE_CONTROLLER.equals(thingTypeUID)) {
71             return new ControllerHandler(thing);
72         } else if (DraytonWiserBindingConstants.THING_TYPE_HOTWATER.equals(thingTypeUID)) {
73             return new HotWaterHandler(thing);
74         } else if (DraytonWiserBindingConstants.THING_TYPE_SMARTPLUG.equals(thingTypeUID)) {
75             return new SmartPlugHandler(thing);
76         }
77
78         return null;
79     }
80 }