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.tplinksmarthome.internal;
15 import static org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeBindingConstants.*;
16 import static org.openhab.binding.tplinksmarthome.internal.TPLinkSmartHomeThingType.*;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.tplinksmarthome.internal.device.BulbDevice;
21 import org.openhab.binding.tplinksmarthome.internal.device.DimmerDevice;
22 import org.openhab.binding.tplinksmarthome.internal.device.EnergySwitchDevice;
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(ThingTypeUID thingTypeUID) {
50 return SUPPORTED_THING_TYPES.contains(thingTypeUID);
55 protected ThingHandler createHandler(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 if (TPLinkSmartHomeThingType.isBulbDeviceWithTemperatureColor1(thingTypeUID)) {
67 device = new BulbDevice(thingTypeUID, COLOR_TEMPERATURE_1_MIN, COLOR_TEMPERATURE_1_MAX);
68 } else if (TPLinkSmartHomeThingType.isBulbDeviceWithTemperatureColor2(thingTypeUID)) {
69 device = new BulbDevice(thingTypeUID, COLOR_TEMPERATURE_2_MIN, COLOR_TEMPERATURE_2_MAX);
71 device = new BulbDevice(thingTypeUID);
75 device = new DimmerDevice();
78 if (HS110.is(thingTypeUID) || KP115.is(thingTypeUID)) {
79 device = new EnergySwitchDevice();
81 device = new SwitchDevice();
85 device = new SwitchDevice();
88 device = new RangeExtenderDevice();
91 device = new PowerStripDevice(type);
96 return new SmartHomeHandler(thing, device, type, ipAddressService);
100 protected void setTPLinkIpAddressCache(TPLinkIpAddressService ipAddressCache) {
101 this.ipAddressService = ipAddressCache;
104 protected void unsetTPLinkIpAddressCache(TPLinkIpAddressService ipAddressCache) {
105 this.ipAddressService = null;