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