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
14 package org.openhab.binding.ipcamera.internal;
16 import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.*;
18 import java.net.UnknownHostException;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.openhab.binding.ipcamera.internal.onvif.OnvifDiscovery;
22 import org.openhab.core.config.discovery.AbstractDiscoveryService;
23 import org.openhab.core.config.discovery.DiscoveryResult;
24 import org.openhab.core.config.discovery.DiscoveryResultBuilder;
25 import org.openhab.core.config.discovery.DiscoveryService;
26 import org.openhab.core.thing.ThingTypeUID;
27 import org.openhab.core.thing.ThingUID;
28 import org.osgi.service.component.annotations.Component;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * The {@link IpCameraDiscoveryService} is responsible for auto finding cameras that have Onvif
35 * @author Matthew Skinner - Initial contribution
39 @Component(service = DiscoveryService.class, configurationPid = "binding.ipcamera")
40 public class IpCameraDiscoveryService extends AbstractDiscoveryService {
42 private final Logger logger = LoggerFactory.getLogger(IpCameraDiscoveryService.class);
44 public IpCameraDiscoveryService() {
45 super(SUPPORTED_THING_TYPES, 0, false);
49 protected void startBackgroundDiscovery() {
53 protected void deactivate() {
57 public void newCameraFound(String brand, String hostname, int onvifPort) {
58 ThingTypeUID thingtypeuid = new ThingTypeUID("ipcamera", brand);
59 ThingUID thingUID = new ThingUID(thingtypeuid, hostname.replace(".", ""));
60 DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID)
61 .withProperty(CONFIG_IPADDRESS, hostname).withProperty(CONFIG_ONVIF_PORT, onvifPort)
62 .withLabel(brand + " camera @" + hostname).build();
63 thingDiscovered(discoveryResult);
67 protected void startScan() {
68 removeOlderResults(getTimestampOfLastScan());
69 OnvifDiscovery onvifDiscovery = new OnvifDiscovery(this);
71 onvifDiscovery.discoverCameras();
72 } catch (UnknownHostException | InterruptedException e) {
74 "IpCamera Discovery has an issue discovering the network settings to find cameras with. Try setting up the camera manually.");