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