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.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.AVMFritzColorLightDeviceHandler;
22 import org.openhab.binding.avmfritz.internal.handler.AVMFritzHeatingDeviceHandler;
23 import org.openhab.binding.avmfritz.internal.handler.AVMFritzHeatingGroupHandler;
24 import org.openhab.binding.avmfritz.internal.handler.BoxHandler;
25 import org.openhab.binding.avmfritz.internal.handler.DeviceHandler;
26 import org.openhab.binding.avmfritz.internal.handler.GroupHandler;
27 import org.openhab.binding.avmfritz.internal.handler.Powerline546EHandler;
28 import org.openhab.core.io.net.http.HttpClientFactory;
29 import org.openhab.core.thing.Bridge;
30 import org.openhab.core.thing.Thing;
31 import org.openhab.core.thing.ThingTypeUID;
32 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
33 import org.openhab.core.thing.binding.ThingHandler;
34 import org.openhab.core.thing.binding.ThingHandlerFactory;
35 import org.osgi.service.component.annotations.Activate;
36 import org.osgi.service.component.annotations.Component;
37 import org.osgi.service.component.annotations.Reference;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
42 * The {@link AVMFritzHandlerFactory} is responsible for creating things and thing handlers.
44 * @author Robert Bausdorf - Initial contribution
46 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.avmfritz")
48 public class AVMFritzHandlerFactory extends BaseThingHandlerFactory {
50 private final Logger logger = LoggerFactory.getLogger(AVMFritzHandlerFactory.class);
52 private final HttpClient httpClient;
53 private final AVMFritzDynamicCommandDescriptionProvider commandDescriptionProvider;
56 public AVMFritzHandlerFactory(final @Reference HttpClientFactory httpClientFactory,
57 final @Reference AVMFritzDynamicCommandDescriptionProvider stateDescriptionProvider) {
58 this.httpClient = httpClientFactory.getCommonHttpClient();
59 this.commandDescriptionProvider = stateDescriptionProvider;
63 * Provides the supported thing types
66 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
67 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
71 * Create handler of things.
74 protected @Nullable ThingHandler createHandler(Thing thing) {
75 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
76 if (BRIDGE_THING_TYPE.equals(thingTypeUID)) {
77 return new BoxHandler((Bridge) thing, httpClient, commandDescriptionProvider);
78 } else if (POWERLINE546E_STANDALONE_THING_TYPE.equals(thingTypeUID)) {
79 return new Powerline546EHandler((Bridge) thing, httpClient, commandDescriptionProvider);
80 } else if (SUPPORTED_LIGHTING_THING_TYPES.contains(thingTypeUID)) {
81 return new AVMFritzColorLightDeviceHandler(thing);
82 } else if (SUPPORTED_BUTTON_THING_TYPES_UIDS.contains(thingTypeUID)) {
83 return new AVMFritzButtonHandler(thing);
84 } else if (SUPPORTED_HEATING_THING_TYPES.contains(thingTypeUID)) {
85 return new AVMFritzHeatingDeviceHandler(thing);
86 } else if (SUPPORTED_DEVICE_THING_TYPES_UIDS.contains(thingTypeUID)) {
87 return new DeviceHandler(thing);
88 } else if (GROUP_HEATING_THING_TYPE.equals(thingTypeUID)) {
89 return new AVMFritzHeatingGroupHandler(thing);
90 } else if (SUPPORTED_GROUP_THING_TYPES_UIDS.contains(thingTypeUID)) {
91 return new GroupHandler(thing);
93 logger.error("ThingHandler not found for {}", thingTypeUID);