2 * Copyright (c) 2010-2023 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.*;
17 import java.util.Collection;
18 import java.util.List;
19 import java.util.function.Function;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.eclipse.jdt.annotation.Nullable;
23 import org.openhab.binding.boschshc.internal.devices.bridge.BridgeHandler;
24 import org.openhab.binding.boschshc.internal.devices.camera.CameraHandler;
25 import org.openhab.binding.boschshc.internal.devices.climatecontrol.ClimateControlHandler;
26 import org.openhab.binding.boschshc.internal.devices.intrusion.IntrusionDetectionHandler;
27 import org.openhab.binding.boschshc.internal.devices.lightcontrol.LightControlHandler;
28 import org.openhab.binding.boschshc.internal.devices.motiondetector.MotionDetectorHandler;
29 import org.openhab.binding.boschshc.internal.devices.plug.PlugHandler;
30 import org.openhab.binding.boschshc.internal.devices.shuttercontrol.ShutterControlHandler;
31 import org.openhab.binding.boschshc.internal.devices.smartbulb.SmartBulbHandler;
32 import org.openhab.binding.boschshc.internal.devices.smokedetector.SmokeDetectorHandler;
33 import org.openhab.binding.boschshc.internal.devices.thermostat.ThermostatHandler;
34 import org.openhab.binding.boschshc.internal.devices.twinguard.TwinguardHandler;
35 import org.openhab.binding.boschshc.internal.devices.userdefinedstate.UserStateHandler;
36 import org.openhab.binding.boschshc.internal.devices.wallthermostat.WallThermostatHandler;
37 import org.openhab.binding.boschshc.internal.devices.windowcontact.WindowContact2Handler;
38 import org.openhab.binding.boschshc.internal.devices.windowcontact.WindowContactHandler;
39 import org.openhab.core.thing.Bridge;
40 import org.openhab.core.thing.Thing;
41 import org.openhab.core.thing.ThingTypeUID;
42 import org.openhab.core.thing.binding.BaseThingHandler;
43 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
44 import org.openhab.core.thing.binding.ThingHandler;
45 import org.openhab.core.thing.binding.ThingHandlerFactory;
46 import org.osgi.service.component.annotations.Component;
49 * The {@link BoschSHCHandlerFactory} is responsible for creating things and
52 * @author Stefan Kästle - Initial contribution
53 * @author Christian Oeing - Added Shutter Control and ThermostatHandler; refactored handler mapping
54 * @author Christian Oeing - Added WallThermostatHandler
55 * @author David Pace - Added cameras, intrusion detection system and smart plugs
56 * @author Christian Oeing - Added smoke detector
59 @Component(configurationPid = "binding.boschshc", service = ThingHandlerFactory.class)
60 public class BoschSHCHandlerFactory extends BaseThingHandlerFactory {
62 private static class ThingTypeHandlerMapping {
63 public ThingTypeUID thingTypeUID;
64 public Function<Thing, BaseThingHandler> handlerSupplier;
66 public ThingTypeHandlerMapping(ThingTypeUID thingTypeUID, Function<Thing, BaseThingHandler> handlerSupplier) {
67 this.thingTypeUID = thingTypeUID;
68 this.handlerSupplier = handlerSupplier;
72 private static final Collection<ThingTypeHandlerMapping> SUPPORTED_THING_TYPES = List.of(
73 new ThingTypeHandlerMapping(THING_TYPE_SHC, thing -> new BridgeHandler((Bridge) thing)),
74 new ThingTypeHandlerMapping(THING_TYPE_INWALL_SWITCH, LightControlHandler::new),
75 new ThingTypeHandlerMapping(THING_TYPE_TWINGUARD, TwinguardHandler::new),
76 new ThingTypeHandlerMapping(THING_TYPE_WINDOW_CONTACT, WindowContactHandler::new),
77 new ThingTypeHandlerMapping(THING_TYPE_WINDOW_CONTACT_2, WindowContact2Handler::new),
78 new ThingTypeHandlerMapping(THING_TYPE_MOTION_DETECTOR, MotionDetectorHandler::new),
79 new ThingTypeHandlerMapping(THING_TYPE_SHUTTER_CONTROL, ShutterControlHandler::new),
80 new ThingTypeHandlerMapping(THING_TYPE_THERMOSTAT, ThermostatHandler::new),
81 new ThingTypeHandlerMapping(THING_TYPE_CLIMATE_CONTROL, ClimateControlHandler::new),
82 new ThingTypeHandlerMapping(THING_TYPE_WALL_THERMOSTAT, WallThermostatHandler::new),
83 new ThingTypeHandlerMapping(THING_TYPE_CAMERA_360, CameraHandler::new),
84 new ThingTypeHandlerMapping(THING_TYPE_CAMERA_EYES, CameraHandler::new),
85 new ThingTypeHandlerMapping(THING_TYPE_INTRUSION_DETECTION_SYSTEM, IntrusionDetectionHandler::new),
86 new ThingTypeHandlerMapping(THING_TYPE_SMART_PLUG_COMPACT, PlugHandler::new),
87 new ThingTypeHandlerMapping(THING_TYPE_SMART_BULB, SmartBulbHandler::new),
88 new ThingTypeHandlerMapping(THING_TYPE_SMOKE_DETECTOR, SmokeDetectorHandler::new),
89 new ThingTypeHandlerMapping(THING_TYPE_USER_DEFINED_STATE, UserStateHandler::new));
92 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
93 return SUPPORTED_THING_TYPES.stream().anyMatch(mapping -> mapping.thingTypeUID.equals(thingTypeUID));
97 protected @Nullable ThingHandler createHandler(Thing thing) {
98 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
100 // Search for mapping for thing type and return handler for it if found. Otherwise return null.
101 return SUPPORTED_THING_TYPES.stream().filter(mapping -> mapping.thingTypeUID.equals(thingTypeUID)).findFirst()
102 .<@Nullable BaseThingHandler> map(mapping -> mapping.handlerSupplier.apply(thing)).orElse(null);