]> git.basschouten.com Git - openhab-addons.git/blob
10738a1541cb342bfcde920cb6266a5f09aa5e82
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.avmfritz.internal;
14
15 import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.*;
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.avmfritz.internal.handler.AVMFritzButtonHandler;
21 import org.openhab.binding.avmfritz.internal.handler.AVMFritzHeatingDeviceHandler;
22 import org.openhab.binding.avmfritz.internal.handler.AVMFritzHeatingGroupHandler;
23 import org.openhab.binding.avmfritz.internal.handler.BoxHandler;
24 import org.openhab.binding.avmfritz.internal.handler.DeviceHandler;
25 import org.openhab.binding.avmfritz.internal.handler.GroupHandler;
26 import org.openhab.binding.avmfritz.internal.handler.Powerline546EHandler;
27 import org.openhab.core.io.net.http.HttpClientFactory;
28 import org.openhab.core.thing.Bridge;
29 import org.openhab.core.thing.Thing;
30 import org.openhab.core.thing.ThingTypeUID;
31 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
32 import org.openhab.core.thing.binding.ThingHandler;
33 import org.openhab.core.thing.binding.ThingHandlerFactory;
34 import org.osgi.service.component.annotations.Activate;
35 import org.osgi.service.component.annotations.Component;
36 import org.osgi.service.component.annotations.Reference;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40 /**
41  * The {@link AVMFritzHandlerFactory} is responsible for creating things and thing handlers.
42  *
43  * @author Robert Bausdorf - Initial contribution
44  */
45 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.avmfritz")
46 @NonNullByDefault
47 public class AVMFritzHandlerFactory extends BaseThingHandlerFactory {
48
49     private final Logger logger = LoggerFactory.getLogger(AVMFritzHandlerFactory.class);
50
51     private final HttpClient httpClient;
52     private final AVMFritzDynamicCommandDescriptionProvider commandDescriptionProvider;
53
54     @Activate
55     public AVMFritzHandlerFactory(final @Reference HttpClientFactory httpClientFactory,
56             final @Reference AVMFritzDynamicCommandDescriptionProvider stateDescriptionProvider) {
57         this.httpClient = httpClientFactory.getCommonHttpClient();
58         this.commandDescriptionProvider = stateDescriptionProvider;
59     }
60
61     /**
62      * Provides the supported thing types
63      */
64     @Override
65     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
66         return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
67     }
68
69     /**
70      * Create handler of things.
71      */
72     @Override
73     protected @Nullable ThingHandler createHandler(Thing thing) {
74         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
75         if (BRIDGE_THING_TYPE.equals(thingTypeUID)) {
76             return new BoxHandler((Bridge) thing, httpClient, commandDescriptionProvider);
77         } else if (PL546E_STANDALONE_THING_TYPE.equals(thingTypeUID)) {
78             return new Powerline546EHandler((Bridge) thing, httpClient, commandDescriptionProvider);
79         } else if (SUPPORTED_BUTTON_THING_TYPES_UIDS.contains(thingTypeUID)) {
80             return new AVMFritzButtonHandler(thing);
81         } else if (SUPPORTED_HEATING_THING_TYPES.contains(thingTypeUID)) {
82             return new AVMFritzHeatingDeviceHandler(thing);
83         } else if (SUPPORTED_DEVICE_THING_TYPES_UIDS.contains(thingTypeUID)) {
84             return new DeviceHandler(thing);
85         } else if (GROUP_HEATING_THING_TYPE.equals(thingTypeUID)) {
86             return new AVMFritzHeatingGroupHandler(thing);
87         } else if (SUPPORTED_GROUP_THING_TYPES_UIDS.contains(thingTypeUID)) {
88             return new GroupHandler(thing);
89         } else {
90             logger.error("ThingHandler not found for {}", thingTypeUID);
91         }
92         return null;
93     }
94 }