Search in sources :

Example 1 with Project

use of com.daveoxley.cbus.Project 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();
}
Also used : Project(com.daveoxley.cbus.Project) ThingStatus(org.openhab.core.thing.ThingStatus) Network(com.daveoxley.cbus.Network) CGateSession(com.daveoxley.cbus.CGateSession) CBusNetworkConfiguration(org.openhab.binding.cbus.internal.CBusNetworkConfiguration) CGateException(com.daveoxley.cbus.CGateException)

Aggregations

CGateException (com.daveoxley.cbus.CGateException)1 CGateSession (com.daveoxley.cbus.CGateSession)1 Network (com.daveoxley.cbus.Network)1 Project (com.daveoxley.cbus.Project)1 CBusNetworkConfiguration (org.openhab.binding.cbus.internal.CBusNetworkConfiguration)1 ThingStatus (org.openhab.core.thing.ThingStatus)1