use of com.daveoxley.cbus.CGateException in project openhab-addons by openhab.
the class CBusDaliHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
Group group = this.group;
if (group == null) {
return;
}
if (command instanceof RefreshType) {
try {
int level = group.getLevel();
logger.debug("handle RefreshType Command for Chanell {} Group {} level {}", channelUID, groupId, level);
if (channelUID.getId().equals(CBusBindingConstants.CHANNEL_LEVEL)) {
updateState(channelUID, new PercentType((int) (level * 100 / 255.0)));
}
} catch (CGateException e) {
logger.debug("Failed to getLevel for group {}", groupId, e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Communication Error");
}
} else {
if (channelUID.getId().equals(CBusBindingConstants.CHANNEL_LEVEL)) {
logger.debug("Channel Level command for {}: {}", channelUID, command);
try {
if (command instanceof OnOffType) {
if (command == OnOffType.ON) {
group.on();
} else if (command == OnOffType.OFF) {
group.off();
}
} else if (command instanceof PercentType) {
PercentType value = (PercentType) command;
group.ramp((int) Math.round(value.doubleValue() / 100 * 255), 0);
} else if (command instanceof IncreaseDecreaseType) {
int level = group.getLevel();
if (command == IncreaseDecreaseType.DECREASE) {
level = Math.max(level - 1, 0);
} else if (command == IncreaseDecreaseType.INCREASE) {
level = Math.min(level + 1, 255);
}
group.ramp(level, 0);
logger.debug("Change group level to {}", level);
}
} catch (CGateException e) {
logger.debug("Cannot send command {} to {}", command, group, e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Communication Error");
}
}
}
}
use of com.daveoxley.cbus.CGateException in project openhab-addons by openhab.
the class CBusNetworkHandler method checkNetworkOnline.
private void checkNetworkOnline() {
Network network = getNetwork();
try {
if (network != null && network.isOnline()) {
logger.debug("Network is online");
ScheduledFuture<?> initNetwork = this.initNetwork;
if (initNetwork != null) {
initNetwork.cancel(false);
this.initNetwork = null;
}
} else {
ThingStatus lastStatus = getThing().getStatus();
logger.debug("Network still not online {}", lastStatus);
}
} catch (CGateException e) {
logger.warn("Cannot check if network is online {} ", network.getNetworkID());
}
updateStatus();
}
use of com.daveoxley.cbus.CGateException in project openhab-addons by openhab.
the class CBusNetworkHandler method cgateOnline.
private void cgateOnline() {
CBusNetworkConfiguration configuration = this.configuration;
if (configuration == null) {
logger.debug("cgateOnline - NetworkHandler not initialised");
return;
}
ThingStatus lastStatus = getThing().getStatus();
logger.debug("cgateOnline {}", lastStatus);
Integer networkID = configuration.id;
String project = configuration.project;
logger.debug("cgateOnline netid {} project {}", networkID, project);
Project projectObject = getProjectObject();
Network network = getNetwork();
logger.debug("network {}", network);
CBusCGateHandler cbusCGateHandler = getCBusCGateHandler();
if (cbusCGateHandler == null) {
logger.debug("NoCGateHandler");
return;
}
try {
if (projectObject == null) {
CGateSession session = cbusCGateHandler.getCGateSession();
if (session != null) {
try {
projectObject = (Project) session.getCGateObject("//" + project);
this.projectObject = projectObject;
} catch (CGateException ignore) {
// We dont need to do anything other than stop this propagating
}
}
if (projectObject == null) {
logger.debug("Cant get projectobject");
return;
}
}
if (network == null) {
CGateSession session = cbusCGateHandler.getCGateSession();
if (session != null) {
try {
network = (Network) session.getCGateObject("//" + project + "/" + networkID);
this.network = network;
} catch (CGateException ignore) {
// We dont need to do anything other than stop this propagating
}
}
if (network == null) {
logger.debug("cgateOnline: Cant get network");
return;
}
}
String state = network.getState();
logger.debug("Network state is {}", state);
if ("new".equals(state)) {
projectObject.start();
logger.debug("Need to wait for it to be synced");
} else if ("sync".equals(state)) {
logger.debug("Network is syncing so wait for it to be ok");
}
if (!"ok".equals(state)) {
ScheduledFuture<?> initNetwork = this.initNetwork;
if (initNetwork == null || initNetwork.isCancelled()) {
this.initNetwork = scheduler.scheduleWithFixedDelay(this::checkNetworkOnline, 30, 30, TimeUnit.SECONDS);
logger.debug("Schedule a check every minute");
} else {
logger.debug("initNetwork alreadys started");
}
updateStatus();
return;
}
} catch (CGateException e) {
logger.warn("Cannot load C-Bus network {}", networkID, e);
updateStatus(ThingStatus.UNINITIALIZED, ThingStatusDetail.COMMUNICATION_ERROR);
}
updateStatus();
}
use of com.daveoxley.cbus.CGateException in project openhab-addons by openhab.
the class CBusNetworkHandler method doNetworkSync.
private void doNetworkSync() {
Network network = getNetwork();
try {
if (getThing().getStatus().equals(ThingStatus.ONLINE) && network != null) {
logger.info("Starting network sync on network {}", network.getNetworkID());
network.startSync();
}
} catch (CGateException e) {
logger.warn("Cannot start network sync on network {} - {}", network.getNetworkID(), e.getMessage());
}
}
use of com.daveoxley.cbus.CGateException in project openhab-addons by openhab.
the class CBusTemperatureHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
// Read only thing - no commands to handle
if (command instanceof RefreshType) {
try {
Group group = this.group;
if (group != null) {
int level = group.getLevel();
logger.debug("handle RefreshType Command for Chanell {} Group {} level {}", channelUID, groupId, level);
if (channelUID.getId().equals(CBusBindingConstants.CHANNEL_TEMP)) {
updateState(channelUID, new QuantityType<>(level, CELSIUS));
}
}
} catch (CGateException e) {
logger.debug("Failed to getLevel for group {}", groupId, e);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Communication Error");
}
}
}
Aggregations