use of com.daveoxley.cbus.Application in project openhab-addons by openhab.
the class CBusGroupDiscovery method startScan.
@Override
protected synchronized void startScan() {
if (cbusNetworkHandler.getThing().getStatus().equals(ThingStatus.ONLINE)) {
ThingUID bridgeUid = cbusNetworkHandler.getThing().getBridgeUID();
if (bridgeUid == null) {
scanFinished();
return;
}
try {
Map<Integer, ThingTypeUID> applications = new HashMap<Integer, ThingTypeUID>();
applications.put(CBusBindingConstants.CBUS_APPLICATION_LIGHTING, CBusBindingConstants.THING_TYPE_LIGHT);
applications.put(CBusBindingConstants.CBUS_APPLICATION_DALI, CBusBindingConstants.THING_TYPE_DALI);
applications.put(CBusBindingConstants.CBUS_APPLICATION_TEMPERATURE, CBusBindingConstants.THING_TYPE_TEMPERATURE);
applications.put(CBusBindingConstants.CBUS_APPLICATION_TRIGGER, CBusBindingConstants.THING_TYPE_TRIGGER);
Network network = cbusNetworkHandler.getNetwork();
if (network == null) {
scanFinished();
return;
}
for (Map.Entry<Integer, ThingTypeUID> applicationItem : applications.entrySet()) {
Application application = network.getApplication(applicationItem.getKey());
if (application == null) {
continue;
}
ArrayList<Group> groups = application.getGroups(false);
for (Group group : groups) {
logger.debug("Found group: {} {} {}", application.getName(), group.getGroupID(), group.getName());
Map<String, Object> properties = new HashMap<>();
properties.put(CBusBindingConstants.PROPERTY_APPLICATION_ID, Integer.toString(applicationItem.getKey()));
properties.put(CBusBindingConstants.CONFIG_GROUP_ID, Integer.toString(group.getGroupID()));
properties.put(CBusBindingConstants.PROPERTY_GROUP_NAME, group.getName());
properties.put(CBusBindingConstants.PROPERTY_NETWORK_ID, Integer.toString(network.getNetworkID()));
ThingUID uid = new ThingUID(applicationItem.getValue(), Integer.toString(group.getGroupID()), bridgeUid.getId(), cbusNetworkHandler.getThing().getUID().getId());
DiscoveryResult result = DiscoveryResultBuilder.create(uid).withProperties(properties).withLabel("CBUS " + group.getName() + "(" + group.getGroupID() + ")").withBridge(cbusNetworkHandler.getThing().getUID()).build();
thingDiscovered(result);
}
}
} catch (CGateException e) {
logger.debug("Failed to discover groups", e);
}
}
scanFinished();
}
use of com.daveoxley.cbus.Application in project openhab-addons by openhab.
the class CBusGroupHandler method getGroup.
@Nullable
private Group getGroup() {
try {
CBusNetworkHandler networkHandler = cBusNetworkHandler;
if (networkHandler == null) {
return null;
}
Network network = networkHandler.getNetwork();
if (network != null) {
Application application = network.getApplication(applicationId);
if (application == null) {
logger.debug("getGroup() Cant get application for id {}", applicationId);
return null;
}
logger.debug("GetGroup for {}/id {}", applicationId, groupId);
return application.getGroup(groupId);
}
} catch (CGateException e) {
logger.debug("GetGroup for id {}/{} failed {}", applicationId, groupId, e.getMessage());
}
return null;
}
Aggregations