2 * Copyright (c) 2010-2020 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.zoneminder.internal;
15 import java.util.Collections;
17 import java.util.stream.Collectors;
18 import java.util.stream.Stream;
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;
33 * The {@link ZoneMinderHandlerFactory} is responsible for creating things and thing
36 * @author Martin S. Eskildsen - Initial contribution
39 @Component(service = ThingHandlerFactory.class, configurationPid = "binding.zoneminder")
40 public class ZoneMinderHandlerFactory extends BaseThingHandlerFactory {
42 private final Logger logger = LoggerFactory.getLogger(ZoneMinderHandlerFactory.class);
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()));
49 public boolean supportsThingType(ThingTypeUID thingTypeUID) {
50 return SUPPORTED_THING_TYPES.contains(thingTypeUID);
54 protected ThingHandler createHandler(Thing thing) {
55 ThingTypeUID thingTypeUID = thing.getThingTypeUID();
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);