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.tradfri.internal;
15 import static org.openhab.binding.tradfri.internal.TradfriBindingConstants.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.tradfri.internal.handler.TradfriBlindHandler;
20 import org.openhab.binding.tradfri.internal.handler.TradfriControllerHandler;
21 import org.openhab.binding.tradfri.internal.handler.TradfriGatewayHandler;
22 import org.openhab.binding.tradfri.internal.handler.TradfriLightHandler;
23 import org.openhab.binding.tradfri.internal.handler.TradfriPlugHandler;
24 import org.openhab.binding.tradfri.internal.handler.TradfriSensorHandler;
25 import org.openhab.core.thing.Bridge;
26 import org.openhab.core.thing.Thing;
27 import org.openhab.core.thing.ThingTypeUID;
28 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
29 import org.openhab.core.thing.binding.ThingHandler;
30 import org.openhab.core.thing.binding.ThingHandlerFactory;
31 import org.osgi.service.component.annotations.Component;
34 * The {@link TradfriHandlerFactory} is responsible for creating things and thing handlers.
36 * @author Kai Kreuzer - Initial contribution
37 * @author Christoph Weitkamp - Added support for remote controller and motion sensor devices (read-only battery level)
38 * @author Manuel Raffel - Added support for blinds
40 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.tradfri")
42 public class TradfriHandlerFactory extends BaseThingHandlerFactory {
45 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
46 return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
50 protected @Nullable ThingHandler createHandler(Thing thing) {
51 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
53 if (GATEWAY_TYPE_UID.equals(thingTypeUID)) {
54 return new TradfriGatewayHandler((Bridge) thing);
55 } else if (THING_TYPE_DIMMER.equals(thingTypeUID) || THING_TYPE_REMOTE_CONTROL.equals(thingTypeUID)
56 || THING_TYPE_OPEN_CLOSE_REMOTE_CONTROL.equals(thingTypeUID)) {
57 return new TradfriControllerHandler(thing);
58 } else if (THING_TYPE_MOTION_SENSOR.equals(thingTypeUID)) {
59 return new TradfriSensorHandler(thing);
60 } else if (THING_TYPE_BLINDS.equals(thingTypeUID)) {
61 return new TradfriBlindHandler(thing);
62 } else if (SUPPORTED_LIGHT_TYPES_UIDS.contains(thingTypeUID)) {
63 return new TradfriLightHandler(thing);
64 } else if (SUPPORTED_PLUG_TYPES_UIDS.contains(thingTypeUID)) {
65 return new TradfriPlugHandler(thing);