Search in sources :

Example 1 with ThingStatus

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

Example 2 with ThingStatus

use of org.openhab.core.thing.ThingStatus 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)

Example 3 with ThingStatus

use of org.openhab.core.thing.ThingStatus in project openhab-addons by openhab.

the class CBusCGateHandler method updateStatus.

private void updateStatus() {
    ThingStatus lastStatus = getThing().getStatus();
    CGateSession cGateSession = this.cGateSession;
    if (cGateSession == null) {
        return;
    }
    if (cGateSession.isConnected()) {
        updateStatus(ThingStatus.ONLINE);
    } else {
        if (lastStatus != ThingStatus.OFFLINE) {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
        }
    }
    if (!getThing().getStatus().equals(lastStatus)) {
        boolean isOnline = getThing().getStatus().equals(ThingStatus.ONLINE);
        updateChildThings(isOnline);
    }
}
Also used : ThingStatus(org.openhab.core.thing.ThingStatus) CGateSession(com.daveoxley.cbus.CGateSession)

Example 4 with ThingStatus

use of org.openhab.core.thing.ThingStatus in project openhab-addons by openhab.

the class EvohomeAccountBridgeHandler method updateThings.

private void updateThings() {
    Map<String, TemperatureControlSystemStatus> idToTcsMap = new HashMap<>();
    Map<String, ZoneStatus> idToZoneMap = new HashMap<>();
    Map<String, GatewayStatus> tcsIdToGatewayMap = new HashMap<>();
    Map<String, String> zoneIdToTcsIdMap = new HashMap<>();
    Map<String, ThingStatus> idToTcsThingsStatusMap = new HashMap<>();
    // First, create a lookup table
    for (LocationStatus location : apiClient.getInstallationStatus()) {
        for (GatewayStatus gateway : location.getGateways()) {
            for (TemperatureControlSystemStatus tcs : gateway.getTemperatureControlSystems()) {
                idToTcsMap.put(tcs.getSystemId(), tcs);
                tcsIdToGatewayMap.put(tcs.getSystemId(), gateway);
                for (ZoneStatus zone : tcs.getZones()) {
                    idToZoneMap.put(zone.getZoneId(), zone);
                    zoneIdToTcsIdMap.put(zone.getZoneId(), tcs.getSystemId());
                }
            }
        }
    }
    // Then update the things by type, with pre-filtered info
    for (Thing handler : getThing().getThings()) {
        ThingHandler thingHandler = handler.getHandler();
        if (thingHandler instanceof EvohomeTemperatureControlSystemHandler) {
            EvohomeTemperatureControlSystemHandler tcsHandler = (EvohomeTemperatureControlSystemHandler) thingHandler;
            tcsHandler.update(tcsIdToGatewayMap.get(tcsHandler.getId()), idToTcsMap.get(tcsHandler.getId()));
            idToTcsThingsStatusMap.put(tcsHandler.getId(), tcsHandler.getThing().getStatus());
        }
        if (thingHandler instanceof EvohomeHeatingZoneHandler) {
            EvohomeHeatingZoneHandler zoneHandler = (EvohomeHeatingZoneHandler) thingHandler;
            zoneHandler.update(idToTcsThingsStatusMap.get(zoneIdToTcsIdMap.get(zoneHandler.getId())), idToZoneMap.get(zoneHandler.getId()));
        }
    }
}
Also used : HashMap(java.util.HashMap) ThingStatus(org.openhab.core.thing.ThingStatus) ThingHandler(org.openhab.core.thing.binding.ThingHandler) TemperatureControlSystemStatus(org.openhab.binding.evohome.internal.api.models.v2.response.TemperatureControlSystemStatus) GatewayStatus(org.openhab.binding.evohome.internal.api.models.v2.response.GatewayStatus) ZoneStatus(org.openhab.binding.evohome.internal.api.models.v2.response.ZoneStatus) LocationStatus(org.openhab.binding.evohome.internal.api.models.v2.response.LocationStatus) Thing(org.openhab.core.thing.Thing)

Example 5 with ThingStatus

use of org.openhab.core.thing.ThingStatus in project openhab-addons by openhab.

the class DarkSkyAPIHandler method determineBridgeStatus.

private void determineBridgeStatus() {
    ThingStatus status = ThingStatus.OFFLINE;
    for (Thing thing : getThing().getThings()) {
        if (ThingStatus.ONLINE.equals(thing.getStatus())) {
            status = ThingStatus.ONLINE;
            break;
        }
    }
    updateStatus(status);
}
Also used : ThingStatus(org.openhab.core.thing.ThingStatus) Thing(org.openhab.core.thing.Thing)

Aggregations

ThingStatus (org.openhab.core.thing.ThingStatus)62 ThingStatusDetail (org.openhab.core.thing.ThingStatusDetail)14 Thing (org.openhab.core.thing.Thing)12 Bridge (org.openhab.core.thing.Bridge)10 State (org.openhab.core.types.State)9 HashMap (java.util.HashMap)6 ThingHandler (org.openhab.core.thing.binding.ThingHandler)6 IOException (java.io.IOException)5 Nullable (org.eclipse.jdt.annotation.Nullable)4 AbstractRioHandlerCallback (org.openhab.binding.russound.internal.rio.AbstractRioHandlerCallback)4 StatefulHandlerCallback (org.openhab.binding.russound.internal.rio.StatefulHandlerCallback)4 ShellyDeviceProfile (org.openhab.binding.shelly.internal.api.ShellyDeviceProfile)4 CGateException (com.daveoxley.cbus.CGateException)3 Network (com.daveoxley.cbus.Network)3 TreeMap (java.util.TreeMap)3 SocketSession (org.openhab.binding.russound.internal.net.SocketSession)3 ThingStatusInfo (org.openhab.core.thing.ThingStatusInfo)3 CGateSession (com.daveoxley.cbus.CGateSession)2 Map (java.util.Map)2 CBusNetworkConfiguration (org.openhab.binding.cbus.internal.CBusNetworkConfiguration)2