forked from openhab/openhab-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[paradoxalarm] - Discovery service implementation (openhab#5826)
* Discovery service implementation Signed-off-by: Konstantin Polihronov <[email protected]> Signed-off-by: Maximilian Hess <[email protected]>
- Loading branch information
Showing
5 changed files
with
167 additions
and
14 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
...ain/java/org/openhab/binding/paradoxalarm/internal/discovery/ParadoxDiscoveryService.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,115 @@ | ||
/** | ||
* Copyright (c) 2010-2019 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.paradoxalarm.internal.discovery; | ||
|
||
import static org.openhab.binding.paradoxalarm.internal.handlers.ParadoxAlarmBindingConstants.*; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.eclipse.smarthome.config.discovery.AbstractDiscoveryService; | ||
import org.eclipse.smarthome.config.discovery.DiscoveryResult; | ||
import org.eclipse.smarthome.config.discovery.DiscoveryResultBuilder; | ||
import org.eclipse.smarthome.core.thing.ThingUID; | ||
import org.openhab.binding.paradoxalarm.internal.communication.IParadoxCommunicator; | ||
import org.openhab.binding.paradoxalarm.internal.exceptions.ParadoxRuntimeException; | ||
import org.openhab.binding.paradoxalarm.internal.handlers.ParadoxIP150BridgeHandler; | ||
import org.openhab.binding.paradoxalarm.internal.model.ParadoxInformation; | ||
import org.openhab.binding.paradoxalarm.internal.model.ParadoxPanel; | ||
import org.openhab.binding.paradoxalarm.internal.model.Partition; | ||
import org.openhab.binding.paradoxalarm.internal.model.Zone; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* The {@link ParadoxDiscoveryService} is responsible for discovery of partitions, zones and the panel once bridge is | ||
* created. | ||
* | ||
* @author Konstnatin Polihronov - Initial Contribution | ||
*/ | ||
public class ParadoxDiscoveryService extends AbstractDiscoveryService { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(ParadoxDiscoveryService.class); | ||
|
||
private ParadoxIP150BridgeHandler ip150BridgeHandler; | ||
|
||
public ParadoxDiscoveryService(ParadoxIP150BridgeHandler ip150BridgeHandler) { | ||
super(SUPPORTED_THING_TYPES_UIDS, 15, false); | ||
this.ip150BridgeHandler = ip150BridgeHandler; | ||
} | ||
|
||
@Override | ||
protected void startScan() { | ||
IParadoxCommunicator communicator = ip150BridgeHandler.getCommunicator(); | ||
if (communicator != null && communicator.isOnline()) { | ||
ParadoxPanel panel = ParadoxPanel.getInstance(); | ||
discoverPanel(panel.getPanelInformation()); | ||
discoverPartitions(panel.getPartitions()); | ||
discoverZones(panel.getZones()); | ||
} else { | ||
logger.debug("Communicator null or not online. Trace={}", new ParadoxRuntimeException()); | ||
} | ||
} | ||
|
||
private void discoverPanel(ParadoxInformation panelInformation) { | ||
if (panelInformation != null) { | ||
Map<String, Object> properties = new HashMap<>(); | ||
properties.put(PANEL_TYPE_PROPERTY_NAME, panelInformation.getPanelType().name()); | ||
properties.put(PANEL_SERIAL_NUMBER_PROPERTY_NAME, panelInformation.getSerialNumber()); | ||
properties.put(PANEL_APPLICATION_VERSION_PROPERTY_NAME, panelInformation.getApplicationVersion()); | ||
properties.put(PANEL_BOOTLOADER_VERSION_PROPERTY_NAME, panelInformation.getBootLoaderVersion()); | ||
properties.put(PANEL_HARDWARE_VERSION_PROPERTY_NAME, panelInformation.getHardwareVersion()); | ||
|
||
ThingUID bridgeUid = ip150BridgeHandler.getThing().getUID(); | ||
ThingUID thingUID = new ThingUID(PANEL_THING_TYPE_UID, bridgeUid, PARADOX_PANEL_THING_TYPE_ID); | ||
DiscoveryResult result = DiscoveryResultBuilder.create(thingUID).withProperties(properties) | ||
.withBridge(bridgeUid).withLabel("Paradox panel - " + panelInformation.getPanelType()).build(); | ||
logger.debug("Panel DiscoveryResult={}", result); | ||
thingDiscovered(result); | ||
} | ||
} | ||
|
||
private void discoverPartitions(List<Partition> partitions) { | ||
partitions.stream().forEach(partition -> { | ||
String thingId = PARTITION_THING_TYPE_ID + partition.getId(); | ||
String label = partition.getLabel(); | ||
ThingUID bridgeUid = ip150BridgeHandler.getThing().getUID(); | ||
|
||
ThingUID thingUID = new ThingUID(PARTITION_THING_TYPE_UID, bridgeUid, thingId); | ||
DiscoveryResult result = DiscoveryResultBuilder.create(thingUID).withBridge(bridgeUid) | ||
.withLabel("Partition " + label).withProperty(PARTITION_THING_TYPE_ID, thingId) | ||
.withProperty("id", partition.getId()).build(); | ||
logger.debug("Partition DiscoveryResult={}", result); | ||
|
||
thingDiscovered(result); | ||
}); | ||
} | ||
|
||
private void discoverZones(List<Zone> zones) { | ||
zones.stream().forEach(zone -> { | ||
String thingId = zone.getLabel().replaceAll(" ", "_"); | ||
String label = zone.getLabel(); | ||
ThingUID bridgeUid = ip150BridgeHandler.getThing().getUID(); | ||
|
||
ThingUID thingUID = new ThingUID(ZONE_THING_TYPE_UID, bridgeUid, thingId); | ||
DiscoveryResult result = DiscoveryResultBuilder.create(thingUID).withBridge(bridgeUid) | ||
.withLabel("Zone " + label).withProperty(ZONE_THING_TYPE_ID, thingId) | ||
.withProperty("id", zone.getId()).build(); | ||
logger.debug("Zone DiscoveryResult={}", result); | ||
|
||
thingDiscovered(result); | ||
}); | ||
} | ||
|
||
} |
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
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