2 * Copyright (c) 2010-2021 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.avmfritz.internal;
15 import static org.openhab.binding.avmfritz.internal.AVMFritzBindingConstants.*;
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;
41 * The {@link AVMFritzHandlerFactory} is responsible for creating things and thing handlers.
43 * @author Robert Bausdorf - Initial contribution
45 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.avmfritz")
47 public class AVMFritzHandlerFactory extends BaseThingHandlerFactory {
49 private final Logger logger = LoggerFactory.getLogger(AVMFritzHandlerFactory.class);
51 private final HttpClient httpClient;
52 private final AVMFritzDynamicCommandDescriptionProvider commandDescriptionProvider;
55 public AVMFritzHandlerFactory(final @Reference HttpClientFactory httpClientFactory,
56 final @Reference AVMFritzDynamicCommandDescriptionProvider stateDescriptionProvider) {
57 this.httpClient = httpClientFactory.getCommonHttpClient();
58 this.commandDescriptionProvider = stateDescriptionProvider;
62 * Provides the supported thing types
65 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
66 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
70 * Create handler of things.
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);
90 logger.error("ThingHandler not found for {}", thingTypeUID);