]> git.basschouten.com Git - openhab-addons.git/blob
0f14591f43ef5565b4c34f24f72d9c228e7ce928
[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
14 package org.openhab.binding.ipcamera.internal;
15
16 import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.*;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.openhab.binding.ipcamera.internal.handler.IpCameraGroupHandler;
21 import org.openhab.binding.ipcamera.internal.handler.IpCameraHandler;
22 import org.openhab.core.net.NetworkAddressService;
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.Activate;
29 import org.osgi.service.component.annotations.Component;
30 import org.osgi.service.component.annotations.Reference;
31
32 /**
33  * The {@link IpCameraHandlerFactory} is responsible for creating things and thing
34  * handlers.
35  *
36  * @author Matthew Skinner - Initial contribution
37  */
38 @Component(service = ThingHandlerFactory.class, immediate = true, configurationPid = "binding.ipcamera")
39 @NonNullByDefault
40 public class IpCameraHandlerFactory extends BaseThingHandlerFactory {
41     private final @Nullable String openhabIpAddress;
42     private final GroupTracker groupTracker = new GroupTracker();
43
44     @Activate
45     public IpCameraHandlerFactory(final @Reference NetworkAddressService networkAddressService) {
46         openhabIpAddress = networkAddressService.getPrimaryIpv4HostAddress();
47     }
48
49     @Override
50     public boolean supportsThingType(ThingTypeUID thingTypeUID) {
51         if (SUPPORTED_THING_TYPES.contains(thingTypeUID) || GROUP_SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
52             return true;
53         }
54         return false;
55     }
56
57     @Override
58     protected @Nullable ThingHandler createHandler(Thing thing) {
59         ThingTypeUID thingTypeUID = thing.getThingTypeUID();
60
61         if (SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
62             return new IpCameraHandler(thing, openhabIpAddress, groupTracker);
63         } else if (GROUP_SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
64             return new IpCameraGroupHandler(thing, openhabIpAddress, groupTracker);
65         }
66         return null;
67     }
68 }