use of com.daveoxley.cbus.Network in project openhab-addons by openhab.
the class CBusNetworkHandler method updateStatus.
private void updateStatus() {
CBusNetworkConfiguration configuration = this.configuration;
if (configuration == null) {
logger.debug("updateStatus - NetworkHandler not initialised");
return;
}
ThingStatus lastStatus = getThing().getStatus();
Network network = getNetwork();
CBusCGateHandler cbusCGateHandler = getCBusCGateHandler();
try {
if (cbusCGateHandler == null || !cbusCGateHandler.getThing().getStatus().equals(ThingStatus.ONLINE)) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, "CGate connection offline");
} else if (network == null) {
logger.debug("No network - set configuration error");
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "No Network object available");
} else if (network.isOnline()) {
updateStatus(ThingStatus.ONLINE);
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Network is not reporting online");
}
} catch (CGateException e) {
logger.warn("Problem checking network state for network {}", network.getNetworkID(), e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
}
if (!getThing().getStatus().equals(lastStatus)) {
ScheduledFuture<?> networkSync = this.networkSync;
if (lastStatus == ThingStatus.OFFLINE) {
if (networkSync == null || networkSync.isCancelled()) {
this.networkSync = scheduler.scheduleWithFixedDelay(this::doNetworkSync, 10, configuration.syncInterval, TimeUnit.SECONDS);
}
} else {
if (networkSync != null) {
networkSync.cancel(false);
}
}
for (Thing thing : getThing().getThings()) {
ThingHandler handler = thing.getHandler();
if (handler instanceof CBusGroupHandler) {
((CBusGroupHandler) handler).updateStatus();
}
}
}
}
use of com.daveoxley.cbus.Network in project openhab-addons by openhab.
the class CBusNetworkDiscovery method startScan.
@Override
protected void startScan() {
if (cBusCGateHandler.getThing().getStatus().equals(ThingStatus.ONLINE)) {
try {
ArrayList<Network> networks = Network.listAll(cBusCGateHandler.getCGateSession(), false);
for (Network network : networks) {
logger.debug("Found Network: {} {}", network.getNetworkID(), network.getName());
Map<String, Object> properties = new HashMap<>(3);
properties.put(CBusBindingConstants.CONFIG_NETWORK_ID, network.getNetworkID());
properties.put(CBusBindingConstants.PROPERTY_NETWORK_NAME, network.getName());
properties.put(CBusBindingConstants.CONFIG_NETWORK_PROJECT, network.getProjectName());
ThingUID uid = new ThingUID(CBusBindingConstants.BRIDGE_TYPE_NETWORK, network.getProjectName().toLowerCase().replace(" ", "_") + network.getNetworkID(), cBusCGateHandler.getThing().getUID().getId());
DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel(network.getProjectName() + "/" + network.getNetworkID() + " - " + network.getName()).withBridge(cBusCGateHandler.getThing().getUID()).build();
thingDiscovered(result);
}
} catch (CGateException e) {
logger.warn("Failed to discover networks", e);
}
}
}
Aggregations