Search in sources :

Example 26 with ThingStatus

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

the class SDMBaseHandler method updateStateWithTraits.

protected void updateStateWithTraits(SDMTraits traits) {
    SDMConnectivityTrait connectivity = traits.connectivity;
    if (connectivity == null && device.traits.connectivity != null) {
        logger.debug("Skipping partial update for device with connectivity trait");
        return;
    }
    ThingStatus thingStatus = connectivity == null || connectivity.status == null || connectivity.status == SDMConnectivityStatus.ONLINE ? ThingStatus.ONLINE : ThingStatus.OFFLINE;
    if (thing.getStatus() != thingStatus) {
        updateStatus(thingStatus);
    }
}
Also used : ThingStatus(org.openhab.core.thing.ThingStatus) SDMConnectivityTrait(org.openhab.binding.nest.internal.sdm.dto.SDMTraits.SDMConnectivityTrait)

Example 27 with ThingStatus

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

the class RemoteopenhabThingHandler method updateThingStatus.

private void updateThingStatus(String thingUID, RemoteopenhabStatusInfo statusInfo) {
    ThingStatus status = ThingStatus.valueOf(statusInfo.status);
    // All remote status different from UNKNOWN or ONLINE or OFFLINE is considered as OFFLINE
    if (status != ThingStatus.UNKNOWN && status != ThingStatus.ONLINE && status != ThingStatus.OFFLINE) {
        status = ThingStatus.OFFLINE;
    }
    ThingStatusDetail detail = ThingStatusDetail.valueOf(statusInfo.statusDetail);
    updateStatus(status, detail, statusInfo.description);
    logger.debug("updateStatus {} with status {} detail {} description {}", thingUID, status, detail, statusInfo.description);
}
Also used : ThingStatus(org.openhab.core.thing.ThingStatus) ThingStatusDetail(org.openhab.core.thing.ThingStatusDetail)

Example 28 with ThingStatus

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

the class ShellyManagerOverviewPage method getStatusWarnings.

private Map<String, String> getStatusWarnings(ShellyManagerInterface handler) {
    Thing thing = handler.getThing();
    ThingStatus status = handler.getThing().getStatus();
    ShellyDeviceStats stats = handler.getStats();
    ShellyDeviceProfile profile = handler.getProfile();
    ShellyThingConfiguration config = thing.getConfiguration().as(ShellyThingConfiguration.class);
    TreeMap<String, String> result = new TreeMap<>();
    if ((status != ThingStatus.ONLINE) && (status != ThingStatus.UNKNOWN)) {
        result.put("Thing Status", status.toString());
    }
    State wifiSignal = handler.getChannelValue(CHANNEL_GROUP_DEV_STATUS, CHANNEL_DEVST_RSSI);
    if ((profile.alwaysOn || (profile.hasBattery && (status == ThingStatus.ONLINE))) && ((wifiSignal != UnDefType.NULL) && (((DecimalType) wifiSignal).intValue() < 2))) {
        result.put("Weak WiFi Signal", wifiSignal.toString());
    }
    if (profile.hasBattery) {
        State lowBattery = handler.getChannelValue(CHANNEL_GROUP_BATTERY, CHANNEL_SENSOR_BAT_LOW);
        if ((lowBattery == OnOffType.ON)) {
            lowBattery = handler.getChannelValue(CHANNEL_GROUP_BATTERY, CHANNEL_SENSOR_BAT_LEVEL);
            result.put("Battery Low", lowBattery.toString());
        }
    }
    if (stats.lastAlarm.equalsIgnoreCase(ALARM_TYPE_RESTARTED)) {
        result.put("Device Alarm", ALARM_TYPE_RESTARTED + " (" + convertTimestamp(stats.lastAlarmTs) + ")");
    }
    if (getBool(profile.status.overtemperature)) {
        result.put("Device Alarm", ALARM_TYPE_OVERTEMP);
    }
    if (getBool(profile.status.overload)) {
        result.put("Device Alarm", ALARM_TYPE_OVERLOAD);
    }
    if (getBool(profile.status.loaderror)) {
        result.put("Device Alarm", ALARM_TYPE_LOADERR);
    }
    if (profile.isSensor) {
        State sensorError = handler.getChannelValue(CHANNEL_GROUP_SENSOR, CHANNEL_SENSOR_ERROR);
        if (sensorError != UnDefType.NULL) {
            if (!sensorError.toString().isEmpty()) {
                result.put("Device Alarm", ALARM_TYPE_SENSOR_ERROR);
            }
        }
    }
    if (profile.alwaysOn && (status == ThingStatus.ONLINE)) {
        if ((config.eventsCoIoT) && (profile.settings.coiot != null)) {
            if ((profile.settings.coiot.enabled != null) && !profile.settings.coiot.enabled) {
                result.put("CoIoT Status", "COIOT_DISABLED");
            } else if (stats.coiotMessages == 0) {
                result.put("CoIoT Discovery", "NO_COIOT_DISCOVERY");
            } else if (stats.coiotMessages < 2) {
                result.put("CoIoT Multicast", "NO_COIOT_MULTICAST");
            }
        }
    }
    return result;
}
Also used : State(org.openhab.core.types.State) ThingStatus(org.openhab.core.thing.ThingStatus) ShellyThingConfiguration(org.openhab.binding.shelly.internal.config.ShellyThingConfiguration) TreeMap(java.util.TreeMap) ShellyDeviceProfile(org.openhab.binding.shelly.internal.api.ShellyDeviceProfile) Thing(org.openhab.core.thing.Thing) ShellyDeviceStats(org.openhab.binding.shelly.internal.handler.ShellyDeviceStats)

Example 29 with ThingStatus

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

the class ShellyManagerPage method fillProperties.

protected Map<String, String> fillProperties(Map<String, String> properties, String uid, ShellyManagerInterface th) {
    try {
        Configuration serviceConfig = configurationAdmin.getConfiguration("binding." + BINDING_ID);
        bindingConfig.updateFromProperties(serviceConfig.getProperties());
    } catch (IOException e) {
        logger.debug("ShellyManager: Unable to get bindingConfig");
    }
    properties.putAll(th.getThing().getProperties());
    Thing thing = th.getThing();
    ThingStatus status = thing.getStatus();
    properties.put("thingName", getString(thing.getLabel()));
    properties.put("thingStatus", status.toString());
    ThingStatusDetail detail = thing.getStatusInfo().getStatusDetail();
    properties.put("thingStatusDetail", detail.equals(ThingStatusDetail.NONE) ? "" : getString(detail.toString()));
    properties.put("thingStatusDescr", getString(thing.getStatusInfo().getDescription()));
    properties.put(ATTRIBUTE_UID, uid);
    ShellyDeviceProfile profile = th.getProfile();
    ShellyThingConfiguration config = thing.getConfiguration().as(ShellyThingConfiguration.class);
    ShellyDeviceStats stats = th.getStats();
    properties.putAll(stats.asProperties());
    for (Map.Entry<String, Object> p : thing.getConfiguration().getProperties().entrySet()) {
        String key = p.getKey();
        if (p.getValue() != null) {
            String value = p.getValue().toString();
            properties.put(key, value);
        }
    }
    State state = th.getChannelValue(CHANNEL_GROUP_DEV_STATUS, CHANNEL_DEVST_NAME);
    if (state != UnDefType.NULL) {
        addAttribute(properties, th, CHANNEL_GROUP_DEV_STATUS, CHANNEL_DEVST_NAME);
    } else {
        // If the Shelly doesn't provide a device name (not configured) we use the service name
        String deviceName = getDeviceName(properties);
        properties.put(PROPERTY_DEV_NAME, !deviceName.isEmpty() ? deviceName : getString(properties.get(PROPERTY_SERVICE_NAME)));
    }
    if (config.userId.isEmpty()) {
        // Get defauls from Binding Config
        properties.put("userId", bindingConfig.defaultUserId);
        properties.put("password", bindingConfig.defaultPassword);
    }
    addAttribute(properties, th, CHANNEL_GROUP_DEV_STATUS, CHANNEL_DEVST_RSSI);
    addAttribute(properties, th, CHANNEL_GROUP_DEV_STATUS, CHANNEL_DEVST_UPTIME);
    addAttribute(properties, th, CHANNEL_GROUP_DEV_STATUS, CHANNEL_DEVST_HEARTBEAT);
    addAttribute(properties, th, CHANNEL_GROUP_DEV_STATUS, CHANNEL_DEVST_ITEMP);
    addAttribute(properties, th, CHANNEL_GROUP_DEV_STATUS, CHANNEL_DEVST_WAKEUP);
    addAttribute(properties, th, CHANNEL_GROUP_DEV_STATUS, CHANNEL_DEVST_CHARGER);
    addAttribute(properties, th, CHANNEL_GROUP_DEV_STATUS, CHANNEL_DEVST_UPDATE);
    addAttribute(properties, th, CHANNEL_GROUP_DEV_STATUS, CHANNEL_DEVST_ALARM);
    addAttribute(properties, th, CHANNEL_GROUP_DEV_STATUS, CHANNEL_DEVST_CHARGER);
    properties.put(ATTRIBUTE_DEBUG_MODE, getOption(profile.settings.debugEnable));
    properties.put(ATTRIBUTE_DISCOVERABLE, String.valueOf(getBool(profile.settings.discoverable)));
    properties.put(ATTRIBUTE_WIFI_RECOVERY, String.valueOf(getBool(profile.settings.wifiRecoveryReboot)));
    properties.put(ATTRIBUTE_APR_MODE, profile.settings.apRoaming != null ? getOption(profile.settings.apRoaming.enabled) : "n/a");
    properties.put(ATTRIBUTE_APR_TRESHOLD, profile.settings.apRoaming != null ? getOption(profile.settings.apRoaming.threshold) : "n/a");
    properties.put(ATTRIBUTE_PWD_PROTECT, profile.auth ? "enabled, user=" + getString(profile.settings.login.username) : "disabled");
    String tz = getString(profile.settings.timezone);
    properties.put(ATTRIBUTE_TIMEZONE, (tz.isEmpty() ? "n/a" : tz) + ", auto-detect: " + getBool(profile.settings.tzautodetect));
    properties.put(ATTRIBUTE_ACTIONS_SKIPPED, profile.status.astats != null ? String.valueOf(profile.status.astats.skipped) : "n/a");
    properties.put(ATTRIBUTE_MAX_ITEMP, stats.maxInternalTemp > 0 ? stats.maxInternalTemp + " °C" : "n/a");
    // Shelly H&T: When external power is connected the battery level is not valid
    if (!profile.isHT || (getInteger(profile.settings.externalPower) == 0)) {
        addAttribute(properties, th, CHANNEL_GROUP_BATTERY, CHANNEL_SENSOR_BAT_LEVEL);
    } else {
        properties.put(CHANNEL_SENSOR_BAT_LEVEL, "USB");
    }
    String wiFiSignal = getString(properties.get(CHANNEL_DEVST_RSSI));
    if (!wiFiSignal.isEmpty()) {
        properties.put("wifiSignalRssi", wiFiSignal + " / " + stats.wifiRssi + " dBm");
        properties.put("imgWiFi", "imgWiFi" + wiFiSignal);
    }
    if (profile.settings.sntp != null) {
        properties.put(ATTRIBUTE_SNTP_SERVER, getString(profile.settings.sntp.server) + ", enabled: " + getBool((profile.settings.sntp.enabled)));
    }
    boolean coiotEnabled = true;
    if ((profile.settings.coiot != null) && (profile.settings.coiot.enabled != null)) {
        coiotEnabled = profile.settings.coiot.enabled;
    }
    properties.put(ATTRIBUTE_COIOT_STATUS, !coiotEnabled ? "Disbaled in settings" : "Events are " + (config.eventsCoIoT ? "enabled" : "disabled"));
    properties.put(ATTRIBUTE_COIOT_PEER, (profile.settings.coiot != null) && !getString(profile.settings.coiot.peer).isEmpty() ? profile.settings.coiot.peer : "Multicast");
    if (profile.status.cloud != null) {
        properties.put(ATTRIBUTE_CLOUD_STATUS, getBool(profile.settings.cloud.enabled) ? getBool(profile.status.cloud.connected) ? "connected" : "enabled" : "disabled");
    } else {
        properties.put(ATTRIBUTE_CLOUD_STATUS, "unknown");
    }
    if (profile.status.mqtt != null) {
        properties.put(ATTRIBUTE_MQTT_STATUS, getBool(profile.settings.mqtt.enable) ? getBool(profile.status.mqtt.connected) ? "connected" : "enabled" : "disabled");
    } else {
        properties.put(ATTRIBUTE_MQTT_STATUS, "unknown");
    }
    String statusIcon = "";
    ThingStatus ts = th.getThing().getStatus();
    switch(ts) {
        case UNINITIALIZED:
        case REMOVED:
        case REMOVING:
            statusIcon = ICON_UNINITIALIZED;
            break;
        case OFFLINE:
            ThingStatusDetail sd = th.getThing().getStatusInfo().getStatusDetail();
            if (uid.contains(THING_TYPE_SHELLYUNKNOWN_STR) || (sd == ThingStatusDetail.CONFIGURATION_ERROR) || (sd == ThingStatusDetail.HANDLER_CONFIGURATION_PENDING)) {
                statusIcon = ICON_CONFIG;
                break;
            }
        default:
            statusIcon = ts.toString();
    }
    properties.put(ATTRIBUTE_STATUS_ICON, statusIcon.toLowerCase());
    return properties;
}
Also used : Configuration(org.osgi.service.cm.Configuration) ShellyBindingConfiguration(org.openhab.binding.shelly.internal.config.ShellyBindingConfiguration) ShellyThingConfiguration(org.openhab.binding.shelly.internal.config.ShellyThingConfiguration) ThingStatus(org.openhab.core.thing.ThingStatus) ThingStatusDetail(org.openhab.core.thing.ThingStatusDetail) IOException(java.io.IOException) State(org.openhab.core.types.State) ShellyThingConfiguration(org.openhab.binding.shelly.internal.config.ShellyThingConfiguration) ShellyDeviceProfile(org.openhab.binding.shelly.internal.api.ShellyDeviceProfile) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) Thing(org.openhab.core.thing.Thing) ShellyDeviceStats(org.openhab.binding.shelly.internal.handler.ShellyDeviceStats)

Example 30 with ThingStatus

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

the class GrafikEyeHandler method internalInitialize.

/**
 * Initializes the grafik eye. Essentially validates the {@link GrafikEyeConfig}, updates the status to online and
 * starts a status refresh job
 */
private void internalInitialize() {
    config = getThing().getConfiguration().as(GrafikEyeConfig.class);
    if (config == null) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Configuration file missing");
        return;
    }
    final String configErr = config.validate();
    if (configErr != null) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, configErr);
        return;
    }
    final Bridge bridge = getBridge();
    if (bridge == null || !(bridge.getHandler() instanceof PrgBridgeHandler)) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "GrafikEye must have a parent PRG Bridge");
        return;
    }
    final ThingHandler handler = bridge.getHandler();
    if (handler.getThing().getStatus() != ThingStatus.ONLINE) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
        return;
    }
    updateStatus(ThingStatus.ONLINE);
    setFade(config.getFade());
    cancelPolling();
    pollingJob = this.scheduler.scheduleWithFixedDelay(new Runnable() {

        @Override
        public void run() {
            final ThingStatus status = getThing().getStatus();
            if (status == ThingStatus.ONLINE && config != null) {
                getProtocolHandler().refreshState(config.getControlUnit());
            }
        }
    }, 1, config.getPolling(), TimeUnit.SECONDS);
}
Also used : ThingStatus(org.openhab.core.thing.ThingStatus) ThingHandler(org.openhab.core.thing.binding.ThingHandler) BaseThingHandler(org.openhab.core.thing.binding.BaseThingHandler) Bridge(org.openhab.core.thing.Bridge)

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