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_WINDOW_CONTACT;
37 import static org.openhab.binding.boschshc.internal.devices.BoschSHCBindingConstants.THING_TYPE_WINDOW_CONTACT_2;
39 import java.util.Collection;
40 import java.util.List;
41 import java.util.function.Function;
43 import org.eclipse.jdt.annotation.NonNullByDefault;
44 import org.eclipse.jdt.annotation.Nullable;
45 import org.openhab.binding.boschshc.internal.devices.bridge.BridgeHandler;
46 import org.openhab.binding.boschshc.internal.devices.camera.CameraHandler;
47 import org.openhab.binding.boschshc.internal.devices.climatecontrol.ClimateControlHandler;
48 import org.openhab.binding.boschshc.internal.devices.intrusion.IntrusionDetectionHandler;
49 import org.openhab.binding.boschshc.internal.devices.lightcontrol.DimmerHandler;
50 import org.openhab.binding.boschshc.internal.devices.lightcontrol.LightControl2Handler;
51 import org.openhab.binding.boschshc.internal.devices.lightcontrol.LightControlHandler;
52 import org.openhab.binding.boschshc.internal.devices.motiondetector.MotionDetectorHandler;
53 import org.openhab.binding.boschshc.internal.devices.plug.PlugHandler;
54 import org.openhab.binding.boschshc.internal.devices.shuttercontrol.ShutterControl2Handler;
55 import org.openhab.binding.boschshc.internal.devices.shuttercontrol.ShutterControlHandler;
56 import org.openhab.binding.boschshc.internal.devices.smartbulb.SmartBulbHandler;
57 import org.openhab.binding.boschshc.internal.devices.smokedetector.SmokeDetector2Handler;
58 import org.openhab.binding.boschshc.internal.devices.smokedetector.SmokeDetectorHandler;
59 import org.openhab.binding.boschshc.internal.devices.thermostat.ThermostatHandler;
60 import org.openhab.binding.boschshc.internal.devices.twinguard.TwinguardHandler;
61 import org.openhab.binding.boschshc.internal.devices.universalswitch.UniversalSwitch2Handler;
62 import org.openhab.binding.boschshc.internal.devices.universalswitch.UniversalSwitchHandler;
63 import org.openhab.binding.boschshc.internal.devices.userdefinedstate.UserStateHandler;
64 import org.openhab.binding.boschshc.internal.devices.wallthermostat.WallThermostatHandler;
65 import org.openhab.binding.boschshc.internal.devices.windowcontact.WindowContact2Handler;
66 import org.openhab.binding.boschshc.internal.devices.windowcontact.WindowContactHandler;
67 import org.openhab.core.i18n.TimeZoneProvider;
68 import org.openhab.core.thing.Bridge;
69 import org.openhab.core.thing.Thing;
70 import org.openhab.core.thing.ThingTypeUID;
71 import org.openhab.core.thing.binding.BaseThingHandler;
72 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
73 import org.openhab.core.thing.binding.ThingHandler;
74 import org.openhab.core.thing.binding.ThingHandlerFactory;
75 import org.osgi.service.component.annotations.Activate;
76 import org.osgi.service.component.annotations.Component;
77 import org.osgi.service.component.annotations.Reference;
80 * The {@link BoschSHCHandlerFactory} is responsible for creating things and
83 * @author Stefan Kästle - Initial contribution
84 * @author Christian Oeing - Added Shutter Control and ThermostatHandler; refactored handler mapping
85 * @author Christian Oeing - Added WallThermostatHandler
86 * @author David Pace - Added cameras, intrusion detection system and smart plugs
87 * @author Christian Oeing - Added smoke detector
90 @Component(configurationPid = "binding.boschshc", service = ThingHandlerFactory.class)
91 public class BoschSHCHandlerFactory extends BaseThingHandlerFactory {
93 private TimeZoneProvider timeZoneProvider;
96 public BoschSHCHandlerFactory(final @Reference TimeZoneProvider timeZoneProvider) {
97 this.timeZoneProvider = timeZoneProvider;
100 private static class ThingTypeHandlerMapping {
101 public ThingTypeUID thingTypeUID;
102 public Function<Thing, BaseThingHandler> handlerSupplier;
104 public ThingTypeHandlerMapping(ThingTypeUID thingTypeUID, Function<Thing, BaseThingHandler> handlerSupplier) {
105 this.thingTypeUID = thingTypeUID;
106 this.handlerSupplier = handlerSupplier;
110 private final Collection<ThingTypeHandlerMapping> supportedThingTypes = List.of(
111 new ThingTypeHandlerMapping(THING_TYPE_SHC, thing -> new BridgeHandler((Bridge) thing)),
112 new ThingTypeHandlerMapping(THING_TYPE_INWALL_SWITCH, LightControlHandler::new),
113 new ThingTypeHandlerMapping(THING_TYPE_TWINGUARD, TwinguardHandler::new),
114 new ThingTypeHandlerMapping(THING_TYPE_WINDOW_CONTACT, WindowContactHandler::new),
115 new ThingTypeHandlerMapping(THING_TYPE_WINDOW_CONTACT_2, WindowContact2Handler::new),
116 new ThingTypeHandlerMapping(THING_TYPE_MOTION_DETECTOR, MotionDetectorHandler::new),
117 new ThingTypeHandlerMapping(THING_TYPE_SHUTTER_CONTROL, ShutterControlHandler::new),
118 new ThingTypeHandlerMapping(THING_TYPE_SHUTTER_CONTROL_2, ShutterControl2Handler::new),
119 new ThingTypeHandlerMapping(THING_TYPE_THERMOSTAT, ThermostatHandler::new),
120 new ThingTypeHandlerMapping(THING_TYPE_CLIMATE_CONTROL, ClimateControlHandler::new),
121 new ThingTypeHandlerMapping(THING_TYPE_WALL_THERMOSTAT, WallThermostatHandler::new),
122 new ThingTypeHandlerMapping(THING_TYPE_CAMERA_360, CameraHandler::new),
123 new ThingTypeHandlerMapping(THING_TYPE_CAMERA_EYES, CameraHandler::new),
124 new ThingTypeHandlerMapping(THING_TYPE_INTRUSION_DETECTION_SYSTEM, IntrusionDetectionHandler::new),
125 new ThingTypeHandlerMapping(THING_TYPE_SMART_PLUG_COMPACT, PlugHandler::new),
126 new ThingTypeHandlerMapping(THING_TYPE_SMART_BULB, SmartBulbHandler::new),
127 new ThingTypeHandlerMapping(THING_TYPE_SMOKE_DETECTOR, SmokeDetectorHandler::new),
128 new ThingTypeHandlerMapping(THING_TYPE_USER_DEFINED_STATE, UserStateHandler::new),
129 new ThingTypeHandlerMapping(THING_TYPE_UNIVERSAL_SWITCH,
130 thing -> new UniversalSwitchHandler(thing, timeZoneProvider)),
131 new ThingTypeHandlerMapping(THING_TYPE_UNIVERSAL_SWITCH_2,
132 thing -> new UniversalSwitch2Handler(thing, timeZoneProvider)),
133 new ThingTypeHandlerMapping(THING_TYPE_SMOKE_DETECTOR_2, SmokeDetector2Handler::new),
134 new ThingTypeHandlerMapping(THING_TYPE_LIGHT_CONTROL_2, LightControl2Handler::new),
135 new ThingTypeHandlerMapping(THING_TYPE_DIMMER, DimmerHandler::new));
138 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
139 return supportedThingTypes.stream().anyMatch(mapping -> mapping.thingTypeUID.equals(thingTypeUID));
143 protected @Nullable ThingHandler createHandler(Thing thing) {
144 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
146 // Search for mapping for thing type and return handler for it if found. Otherwise return null.
147 return supportedThingTypes.stream().filter(mapping -> mapping.thingTypeUID.equals(thingTypeUID)).findFirst()
148 .<@Nullable BaseThingHandler> map(mapping -> mapping.handlerSupplier.apply(thing)).orElse(null);