]> git.basschouten.com Git - openhab-addons.git/blob
2a217c7743fcc4f426ab870b14eeea1f31cee2d2
[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.doorbird.internal;
14
15 import static org.openhab.binding.doorbird.internal.DoorbirdBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.eclipse.jetty.client.HttpClient;
20 import org.openhab.binding.doorbird.internal.handler.ControllerHandler;
21 import org.openhab.binding.doorbird.internal.handler.DoorbellHandler;
22 import org.openhab.core.i18n.TimeZoneProvider;
23 import org.openhab.core.io.net.http.HttpClientFactory;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.thing.ThingTypeUID;
26 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
27 import org.openhab.core.thing.binding.ThingHandler;
28 import org.openhab.core.thing.binding.ThingHandlerFactory;
29 import org.osgi.service.component.annotations.Activate;
30 import org.osgi.service.component.annotations.Component;
31 import org.osgi.service.component.annotations.Reference;
32
33 /**
34  * The {@link DoorbirdHandlerFactory} is responsible for creating Doorbird thing
35  * handlers.
36  *
37  * @author Mark Hilbush - Initial contribution
38  */
39 @NonNullByDefault
40 @Component(configurationPid = "binding.doorbird", service = ThingHandlerFactory.class)
41 public class DoorbirdHandlerFactory extends BaseThingHandlerFactory {
42     private final TimeZoneProvider timeZoneProvider;
43     private final HttpClient httpClient;
44
45     @Activate
46     public DoorbirdHandlerFactory(@Reference TimeZoneProvider timeZoneProvider,
47             @Reference HttpClientFactory httpClientFactory) {
48         this.timeZoneProvider = timeZoneProvider;
49         this.httpClient = httpClientFactory.getCommonHttpClient();
50     }
51
52     @Override
53     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
54         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
55     }
56
57     @Override
58     protected @Nullable ThingHandler createHandler(Thing thing) {
59         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
60         if (THING_TYPE_D101.equals(thingTypeUID) || THING_TYPE_D210X.equals(thingTypeUID)) {
61             return new DoorbellHandler(thing, timeZoneProvider, httpClient, bundleContext);
62         } else if (THING_TYPE_A1081.equals(thingTypeUID)) {
63             return new ControllerHandler(thing);
64         }
65         return null;
66     }
67 }