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.tplinksmarthome.internal;
15 import static org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeThingType.SUPPORTED_THING_TYPES;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.tplinksmarthome.internal.device.BulbDevice;
20 import org.openhab.binding.tplinksmarthome.internal.device.DimmerDevice;
21 import org.openhab.binding.tplinksmarthome.internal.device.EnergySwitchDevice;
22 import org.openhab.binding.tplinksmarthome.internal.device.LightStripDevice;
23 import org.openhab.binding.tplinksmarthome.internal.device.PowerStripDevice;
24 import org.openhab.binding.tplinksmarthome.internal.device.RangeExtenderDevice;
25 import org.openhab.binding.tplinksmarthome.internal.device.SmartHomeDevice;
26 import org.openhab.binding.tplinksmarthome.internal.device.SwitchDevice;
27 import org.openhab.binding.tplinksmarthome.internal.handler.SmartHomeHandler;
28 import org.openhab.core.thing.Thing;
29 import org.openhab.core.thing.ThingTypeUID;
30 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
31 import org.openhab.core.thing.binding.ThingHandler;
32 import org.openhab.core.thing.binding.ThingHandlerFactory;
33 import org.osgi.service.component.annotations.Component;
34 import org.osgi.service.component.annotations.Reference;
37 * The {@link TPLinkSmartHomeHandlerFactory} is responsible for creating things and thing handlers.
39 * @author Christian Fischer - Initial contribution
40 * @author Hilbrand Bouwkamp - Specific handlers for different type of devices.
43 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.tplinksmarthome")
44 public class TPLinkSmartHomeHandlerFactory extends BaseThingHandlerFactory {
46 private @NonNullByDefault({}) TPLinkIpAddressService ipAddressService;
49 public boolean supportsThingType(final ThingTypeUID thingTypeUID) {
50 return SUPPORTED_THING_TYPES.contains(thingTypeUID);
55 protected ThingHandler createHandler(final Thing thing) {
56 final ThingTypeUID thingTypeUID = thing.getThingTypeUID();
57 final TPLinkSmartHomeThingType type = TPLinkSmartHomeThingType.THING_TYPE_MAP.get(thingTypeUID);
62 final SmartHomeDevice device;
64 switch (type.getDeviceType()) {
66 device = new BulbDevice(type);
69 device = new DimmerDevice();
72 device = new LightStripDevice(type);
75 device = new SwitchDevice();
77 case PLUG_WITH_ENERGY:
78 device = new EnergySwitchDevice();
81 device = new PowerStripDevice(type);
84 device = new SwitchDevice();
87 device = new RangeExtenderDevice();
92 return new SmartHomeHandler(thing, device, type, ipAddressService);
96 protected void setTPLinkIpAddressCache(final TPLinkIpAddressService ipAddressCache) {
97 this.ipAddressService = ipAddressCache;
100 protected void unsetTPLinkIpAddressCache(final TPLinkIpAddressService ipAddressCache) {
101 this.ipAddressService = null;