forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves openhab#16690 Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
- Loading branch information
Showing
4 changed files
with
140 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...openhab/binding/denonmarantz/internal/discovery/DenonMarantzUpnpDiscoveryParticipant.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* Copyright (c) 2010-2024 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.denonmarantz.internal.discovery; | ||
|
||
import static org.openhab.binding.denonmarantz.internal.DenonMarantzBindingConstants.*; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.jupnp.model.meta.DeviceDetails; | ||
import org.jupnp.model.meta.RemoteDevice; | ||
import org.openhab.core.config.discovery.DiscoveryResult; | ||
import org.openhab.core.config.discovery.DiscoveryResultBuilder; | ||
import org.openhab.core.config.discovery.upnp.UpnpDiscoveryParticipant; | ||
import org.openhab.core.thing.Thing; | ||
import org.openhab.core.thing.ThingTypeUID; | ||
import org.openhab.core.thing.ThingUID; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* The {@link DenonMarantzUpnpDiscoveryParticipant} is responsible for discovering Denon AV Receivers. | ||
* It uses the central {@link org.openhab.core.config.discovery.upnp.internal.UpnpDiscoveryService}. | ||
* | ||
* @author Jacob Laursen - Initial contribution | ||
*/ | ||
@Component(configurationPid = "discovery.denonmarantz") | ||
@NonNullByDefault | ||
public class DenonMarantzUpnpDiscoveryParticipant implements UpnpDiscoveryParticipant { | ||
|
||
private Logger logger = LoggerFactory.getLogger(DenonMarantzUpnpDiscoveryParticipant.class); | ||
|
||
@Override | ||
public Set<ThingTypeUID> getSupportedThingTypeUIDs() { | ||
return Set.of(THING_TYPE_AVR); | ||
} | ||
|
||
@Override | ||
public @Nullable DiscoveryResult createResult(RemoteDevice device) { | ||
logger.debug("AVR found: {}", device.getDisplayString()); | ||
ThingUID thingUID = getThingUID(device); | ||
if (thingUID == null) { | ||
return null; | ||
} | ||
|
||
DeviceDetails details = device.getDetails(); | ||
String host = details.getBaseURL().getHost(); | ||
String model = details.getModelDetails().getModelName(); | ||
String serialNumber = details.getSerialNumber().toLowerCase(); | ||
|
||
Map<String, Object> properties = new HashMap<>(3); | ||
properties.put(PARAMETER_HOST, host); | ||
properties.put(Thing.PROPERTY_VENDOR, VENDOR_DENON); | ||
properties.put(Thing.PROPERTY_MODEL_ID, model); | ||
properties.put(Thing.PROPERTY_SERIAL_NUMBER, serialNumber); | ||
|
||
return DiscoveryResultBuilder.create(thingUID).withProperties(properties).withLabel(VENDOR_DENON + " " + model) | ||
.withRepresentationProperty(Thing.PROPERTY_SERIAL_NUMBER).build(); | ||
} | ||
|
||
@Override | ||
public @Nullable ThingUID getThingUID(RemoteDevice device) { | ||
DeviceDetails details = device.getDetails(); | ||
if (!VENDOR_DENON.equalsIgnoreCase(details.getManufacturerDetails().getManufacturer())) { | ||
return null; | ||
} | ||
return new ThingUID(THING_TYPE_AVR, details.getSerialNumber().toLowerCase()); | ||
} | ||
} |