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