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.draytonwiser.internal;
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;
37 * The {@link DraytonWiserHandlerFactory} is responsible for creating things and thing
40 * @author Andrew Schofield - Initial contribution
42 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.draytonwiser")
44 public class DraytonWiserHandlerFactory extends BaseThingHandlerFactory {
46 private final HttpClient httpClient;
49 public DraytonWiserHandlerFactory(@Reference final HttpClientFactory factory) {
50 httpClient = factory.getCommonHttpClient();
54 public boolean supportsThingType(final ThingTypeUID thingTypeUID) {
55 return DraytonWiserBindingConstants.SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
59 protected @Nullable ThingHandler createHandler(final Thing thing) {
60 final ThingTypeUID thingTypeUID = thing.getThingTypeUID();
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);