2 * Copyright (c) 2010-2024 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.boschshc.internal.devices;
15 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_CAMERA_360;
16 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_CAMERA_EYES;
17 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_CLIMATE_CONTROL;
18 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_DIMMER;
19 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_INTRUSION_DETECTION_SYSTEM;
20 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_INWALL_SWITCH;
21 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_LIGHT_CONTROL_2;
22 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_MOTION_DETECTOR;
23 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_SHC;
24 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_SHUTTER_CONTROL;
25 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_SHUTTER_CONTROL_2;
26 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_SMART_BULB;
27 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_SMART_PLUG_COMPACT;
28 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_SMOKE_DETECTOR;
29 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_SMOKE_DETECTOR_2;
30 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_THERMOSTAT;
31 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_TWINGUARD;
32 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_UNIVERSAL_SWITCH;
33 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_UNIVERSAL_SWITCH_2;
34 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_USER_DEFINED_STATE;
35 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_WALL_THERMOSTAT;
36 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_WATER_DETECTOR;
37 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_WINDOW_CONTACT;
38 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_WINDOW_CONTACT_2;
40 import java.util.Collection;
41 import java.util.List;
42 import java.util.function.Function;
44 import org.eclipse.jdt.annotation.NonNullByDefault;
45 import org.eclipse.jdt.annotation.Nullable;
46 import org.openhab.binding.boschshc.internal.devices.bridge.BridgeHandler;
47 import org.openhab.binding.boschshc.internal.devices.camera.CameraHandler;
48 import org.openhab.binding.boschshc.internal.devices.climatecontrol.ClimateControlHandler;
49 import org.openhab.binding.boschshc.internal.devices.intrusion.IntrusionDetectionHandler;
50 import org.openhab.binding.boschshc.internal.devices.lightcontrol.DimmerHandler;
51 import org.openhab.binding.boschshc.internal.devices.lightcontrol.LightControl2Handler;
52 import org.openhab.binding.boschshc.internal.devices.lightcontrol.LightControlHandler;
53 import org.openhab.binding.boschshc.internal.devices.motiondetector.MotionDetectorHandler;
54 import org.openhab.binding.boschshc.internal.devices.plug.PlugHandler;
55 import org.openhab.binding.boschshc.internal.devices.shuttercontrol.ShutterControl2Handler;
56 import org.openhab.binding.boschshc.internal.devices.shuttercontrol.ShutterControlHandler;
57 import org.openhab.binding.boschshc.internal.devices.smartbulb.SmartBulbHandler;
58 import org.openhab.binding.boschshc.internal.devices.smokedetector.SmokeDetector2Handler;
59 import org.openhab.binding.boschshc.internal.devices.smokedetector.SmokeDetectorHandler;
60 import org.openhab.binding.boschshc.internal.devices.thermostat.ThermostatHandler;
61 import org.openhab.binding.boschshc.internal.devices.twinguard.TwinguardHandler;
62 import org.openhab.binding.boschshc.internal.devices.universalswitch.UniversalSwitch2Handler;
63 import org.openhab.binding.boschshc.internal.devices.universalswitch.UniversalSwitchHandler;
64 import org.openhab.binding.boschshc.internal.devices.userdefinedstate.UserStateHandler;
65 import org.openhab.binding.boschshc.internal.devices.wallthermostat.WallThermostatHandler;
66 import org.openhab.binding.boschshc.internal.devices.waterleakage.WaterLeakageSensorHandler;
67 import org.openhab.binding.boschshc.internal.devices.windowcontact.WindowContact2Handler;
68 import org.openhab.binding.boschshc.internal.devices.windowcontact.WindowContactHandler;
69 import org.openhab.core.i18n.TimeZoneProvider;
70 import org.openhab.core.thing.Bridge;
71 import org.openhab.core.thing.Thing;
72 import org.openhab.core.thing.ThingTypeUID;
73 import org.openhab.core.thing.binding.BaseThingHandler;
74 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
75 import org.openhab.core.thing.binding.ThingHandler;
76 import org.openhab.core.thing.binding.ThingHandlerFactory;
77 import org.osgi.service.component.annotations.Activate;
78 import org.osgi.service.component.annotations.Component;
79 import org.osgi.service.component.annotations.Reference;
82 * The {@link BoschSHCHandlerFactory} is responsible for creating things and
85 * @author Stefan Kästle - Initial contribution
86 * @author Christian Oeing - Added Shutter Control and ThermostatHandler; refactored handler mapping
87 * @author Christian Oeing - Added WallThermostatHandler
88 * @author David Pace - Added cameras, intrusion detection system and smart plugs
89 * @author Christian Oeing - Added smoke detector
92 @Component(configurationPid = "binding.boschshc", service = ThingHandlerFactory.class)
93 public class BoschSHCHandlerFactory extends BaseThingHandlerFactory {
95 private TimeZoneProvider timeZoneProvider;
98 public BoschSHCHandlerFactory(final @Reference TimeZoneProvider timeZoneProvider) {
99 this.timeZoneProvider = timeZoneProvider;
102 private static class ThingTypeHandlerMapping {
103 public ThingTypeUID thingTypeUID;
104 public Function<Thing, BaseThingHandler> handlerSupplier;
106 public ThingTypeHandlerMapping(ThingTypeUID thingTypeUID, Function<Thing, BaseThingHandler> handlerSupplier) {
107 this.thingTypeUID = thingTypeUID;
108 this.handlerSupplier = handlerSupplier;
112 private final Collection<ThingTypeHandlerMapping> supportedThingTypes = List.of(
113 new ThingTypeHandlerMapping(THING_TYPE_SHC, thing -> new BridgeHandler((Bridge) thing)),
114 new ThingTypeHandlerMapping(THING_TYPE_INWALL_SWITCH, LightControlHandler::new),
115 new ThingTypeHandlerMapping(THING_TYPE_TWINGUARD, TwinguardHandler::new),
116 new ThingTypeHandlerMapping(THING_TYPE_WINDOW_CONTACT, WindowContactHandler::new),
117 new ThingTypeHandlerMapping(THING_TYPE_WINDOW_CONTACT_2, WindowContact2Handler::new),
118 new ThingTypeHandlerMapping(THING_TYPE_MOTION_DETECTOR, MotionDetectorHandler::new),
119 new ThingTypeHandlerMapping(THING_TYPE_SHUTTER_CONTROL, ShutterControlHandler::new),
120 new ThingTypeHandlerMapping(THING_TYPE_SHUTTER_CONTROL_2, ShutterControl2Handler::new),
121 new ThingTypeHandlerMapping(THING_TYPE_THERMOSTAT, ThermostatHandler::new),
122 new ThingTypeHandlerMapping(THING_TYPE_CLIMATE_CONTROL, ClimateControlHandler::new),
123 new ThingTypeHandlerMapping(THING_TYPE_WALL_THERMOSTAT, WallThermostatHandler::new),
124 new ThingTypeHandlerMapping(THING_TYPE_CAMERA_360, CameraHandler::new),
125 new ThingTypeHandlerMapping(THING_TYPE_CAMERA_EYES, CameraHandler::new),
126 new ThingTypeHandlerMapping(THING_TYPE_INTRUSION_DETECTION_SYSTEM, IntrusionDetectionHandler::new),
127 new ThingTypeHandlerMapping(THING_TYPE_SMART_PLUG_COMPACT, PlugHandler::new),
128 new ThingTypeHandlerMapping(THING_TYPE_SMART_BULB, SmartBulbHandler::new),
129 new ThingTypeHandlerMapping(THING_TYPE_SMOKE_DETECTOR, SmokeDetectorHandler::new),
130 new ThingTypeHandlerMapping(THING_TYPE_USER_DEFINED_STATE, UserStateHandler::new),
131 new ThingTypeHandlerMapping(THING_TYPE_UNIVERSAL_SWITCH,
132 thing -> new UniversalSwitchHandler(thing, timeZoneProvider)),
133 new ThingTypeHandlerMapping(THING_TYPE_UNIVERSAL_SWITCH_2,
134 thing -> new UniversalSwitch2Handler(thing, timeZoneProvider)),
135 new ThingTypeHandlerMapping(THING_TYPE_SMOKE_DETECTOR_2, SmokeDetector2Handler::new),
136 new ThingTypeHandlerMapping(THING_TYPE_LIGHT_CONTROL_2, LightControl2Handler::new),
137 new ThingTypeHandlerMapping(THING_TYPE_DIMMER, DimmerHandler::new),
138 new ThingTypeHandlerMapping(THING_TYPE_WATER_DETECTOR, WaterLeakageSensorHandler::new));
141 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
142 return supportedThingTypes.stream().anyMatch(mapping -> mapping.thingTypeUID.equals(thingTypeUID));
146 protected @Nullable ThingHandler createHandler(Thing thing) {
147 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
149 // Search for mapping for thing type and return handler for it if found. Otherwise return null.
150 return supportedThingTypes.stream().filter(mapping -> mapping.thingTypeUID.equals(thingTypeUID)).findFirst()
151 .<@Nullable BaseThingHandler> map(mapping -> mapping.handlerSupplier.apply(thing)).orElse(null);