]> git.basschouten.com Git - openhab-addons.git/blob
6d616609434f396de703f10622ef96bdd392ccc5
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.zoneminder.internal;
14
15 import java.util.Collections;
16 import java.util.Set;
17 import java.util.stream.Collectors;
18 import java.util.stream.Stream;
19
20 import org.openhab.binding.zoneminder.internal.handler.ZoneMinderServerBridgeHandler;
21 import org.openhab.binding.zoneminder.internal.handler.ZoneMinderThingMonitorHandler;
22 import org.openhab.core.thing.Bridge;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.thing.ThingTypeUID;
25 import org.openhab.core.thing.binding.BaseThingHandlerFactory;
26 import org.openhab.core.thing.binding.ThingHandler;
27 import org.openhab.core.thing.binding.ThingHandlerFactory;
28 import org.osgi.service.component.annotations.Component;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 /**
33  * The {@link ZoneMinderHandlerFactory} is responsible for creating things and thing
34  * handlers.
35  *
36  * @author Martin S. Eskildsen - Initial contribution
37  *
38  */
39 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.zoneminder")
40 public class ZoneMinderHandlerFactory extends BaseThingHandlerFactory {
41
42     private final Logger logger = LoggerFactory.getLogger(ZoneMinderHandlerFactory.class);
43
44     public static final Set<ThingTypeUID> SUPPORTED_THING_TYPES = Collections
45             .unmodifiableSet(Stream.concat(ZoneMinderServerBridgeHandler.SUPPORTED_THING_TYPES.stream(),
46                     ZoneMinderThingMonitorHandler.SUPPORTED_THING_TYPES.stream()).collect(Collectors.toSet()));
47
48     @Override
49     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
50         return SUPPORTED_THING_TYPES.contains(thingTypeUID);
51     }
52
53     @Override
54     protected ThingHandler createHandler(Thing thing) {
55         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
56
57         if (thingTypeUID.equals(ZoneMinderConstants.THING_TYPE_BRIDGE_ZONEMINDER_SERVER)) {
58             logger.debug("[FACTORY]: creating handler for bridge thing '{}'", thing);
59             return new ZoneMinderServerBridgeHandler((Bridge) thing);
60         } else if (thingTypeUID.equals(ZoneMinderConstants.THING_TYPE_THING_ZONEMINDER_MONITOR)) {
61             return new ZoneMinderThingMonitorHandler(thing);
62         }
63
64         return null;
65     }
66 }