Search in sources :

Example 16 with ThingStatus

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

the class AccountOverviewServlet method renderBridge.

private String renderBridge(Thing bridge, int index) {
    StringBuilder builder = new StringBuilder();
    builder.append("                    <li>\n");
    String thingUid = bridge.getUID().getAsString();
    String thingId = bridge.getUID().getId();
    builder.append("                        ");
    builder.append(thingUid.substring(0, thingUid.length() - thingId.length()));
    builder.append(" ");
    builder.append(thingId);
    builder.append(" ");
    builder.append(bridge.getConfiguration().get(MieleCloudBindingConstants.CONFIG_PARAM_EMAIL).toString());
    builder.append("\n");
    builder.append("                        <span class=\"status ");
    final ThingStatus status = bridge.getStatus();
    if (status == ThingStatus.ONLINE) {
        builder.append("online");
    } else {
        builder.append("offline");
    }
    builder.append("\">");
    builder.append(status.toString());
    builder.append("</span>\n");
    builder.append("                        <input class=\"trigger\" id=\"mielecloud-account-");
    builder.append(thingId);
    builder.append("\" type=\"checkbox\" name=\"things-file\" />\n");
    builder.append("                        <label for=\"mielecloud-account-");
    builder.append(thingId);
    builder.append("\">&lt; &gt;</label>\n");
    builder.append("                        <div class=\"things\">\n");
    builder.append("                            <span class=\"legend\">You can use this things-file template to pair all available devices:</span>\n");
    builder.append("                            <div class=\"code-container\">\n");
    builder.append("                                <a href=\"#\" onclick=\"copyCodeToClipboard(event, this);\" class=\"btn btn-outline-info btn-sm copy\">Copy</a>\n");
    builder.append("                                <textarea readonly>");
    builder.append(generateConfigurationTemplate((Bridge) bridge));
    builder.append("</textarea>\n");
    builder.append("                            </div>\n");
    builder.append("                        </div>\n");
    builder.append("                    </li>");
    return builder.toString();
}
Also used : ThingStatus(org.openhab.core.thing.ThingStatus) Bridge(org.openhab.core.thing.Bridge)

Example 17 with ThingStatus

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

the class NeeoDeviceHandler method initializeTask.

/**
 * Initializes the task be creating the {@link NeeoDeviceProtocol}, going online and then scheduling the refresh
 * task.
 */
private void initializeTask() {
    final NeeoDeviceConfig config = getConfigAs(NeeoDeviceConfig.class);
    final String roomKey = getRoomKey();
    if (roomKey == null || roomKey.isEmpty()) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Room key (from the parent room bridge) was not found");
        return;
    }
    final String deviceKey = config.getDeviceKey();
    if (deviceKey == null || deviceKey.isEmpty()) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Device key was not found or empty");
        return;
    }
    try {
        NeeoUtil.checkInterrupt();
        final NeeoBrainApi brainApi = getNeeoBrainApi();
        if (brainApi == null) {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, "Cannot find the NEEO Brain API");
            return;
        }
        final NeeoRoom room = brainApi.getRoom(roomKey);
        final NeeoDevice device = room.getDevices().getDevice(deviceKey);
        if (device == null) {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Device (" + config.getDeviceKey() + ") was not found in room (" + roomKey + ")");
            return;
        }
        final ThingUID thingUid = getThing().getUID();
        final Map<String, String> properties = new HashMap<>();
        final NeeoDeviceDetails details = device.getDetails();
        if (details != null) {
            /**
             * The following properties have matches in org.openhab.io.neeo.OpenHabToDeviceConverter.java
             */
            addProperty(properties, "Source Name", details.getSourceName());
            addProperty(properties, "Adapter Name", details.getAdapterName());
            addProperty(properties, "Type", details.getType());
            addProperty(properties, "Manufacturer", details.getManufacturer());
            addProperty(properties, "Name", details.getName());
            final NeeoDeviceDetailsTiming timing = details.getTiming();
            if (timing != null) {
                properties.put("Standby Command Delay", toString(timing.getStandbyCommandDelay()));
                properties.put("Source Switch Delay", toString(timing.getSourceSwitchDelay()));
                properties.put("Shutdown Delay", toString(timing.getShutdownDelay()));
            }
            properties.put("Device Capabilities", Arrays.stream(details.getDeviceCapabilities()).collect(Collectors.joining(",")));
        }
        final ThingBuilder thingBuilder = editThing();
        thingBuilder.withLabel(device.getName() + " (NEEO " + brainApi.getBrain().getKey() + ")").withProperties(properties).withChannels(ChannelUtils.generateChannels(thingUid, device));
        updateThing(thingBuilder.build());
        NeeoUtil.checkInterrupt();
        final NeeoDeviceProtocol protocol = new NeeoDeviceProtocol(new NeeoHandlerCallback() {

            @Override
            public void statusChanged(ThingStatus status, ThingStatusDetail detail, String msg) {
                updateStatus(status, detail, msg);
            }

            @Override
            public void stateChanged(String channelId, State state) {
                updateState(channelId, state);
            }

            @Override
            public void setProperty(String propertyName, String propertyValue) {
                getThing().setProperty(propertyName, propertyValue);
            }

            @Override
            public void scheduleTask(Runnable task, long milliSeconds) {
                scheduler.schedule(task, milliSeconds, TimeUnit.MILLISECONDS);
            }

            @Override
            public void triggerEvent(String channelID, String event) {
                triggerChannel(channelID, event);
            }

            @Nullable
            @Override
            public NeeoBrainApi getApi() {
                return getNeeoBrainApi();
            }
        }, roomKey, deviceKey);
        deviceProtocol.getAndSet(protocol);
        NeeoUtil.checkInterrupt();
        updateStatus(ThingStatus.ONLINE);
    } catch (IOException e) {
        logger.debug("IOException during initialization", e);
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Room " + roomKey + " couldn't be found");
    } catch (InterruptedException e) {
        logger.debug("Initialization was interrupted", e);
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.HANDLER_INITIALIZING_ERROR, "Initialization was interrupted");
    }
}
Also used : NeeoDeviceDetailsTiming(org.openhab.binding.neeo.internal.models.NeeoDeviceDetailsTiming) ThingBuilder(org.openhab.core.thing.binding.builder.ThingBuilder) HashMap(java.util.HashMap) ThingStatus(org.openhab.core.thing.ThingStatus) ThingStatusDetail(org.openhab.core.thing.ThingStatusDetail) IOException(java.io.IOException) NeeoDevice(org.openhab.binding.neeo.internal.models.NeeoDevice) NeeoDeviceConfig(org.openhab.binding.neeo.internal.NeeoDeviceConfig) NeeoBrainApi(org.openhab.binding.neeo.internal.NeeoBrainApi) NeeoRoom(org.openhab.binding.neeo.internal.models.NeeoRoom) NeeoDeviceProtocol(org.openhab.binding.neeo.internal.NeeoDeviceProtocol) State(org.openhab.core.types.State) ThingUID(org.openhab.core.thing.ThingUID) NeeoDeviceDetails(org.openhab.binding.neeo.internal.models.NeeoDeviceDetails) Nullable(org.eclipse.jdt.annotation.Nullable) NeeoHandlerCallback(org.openhab.binding.neeo.internal.NeeoHandlerCallback)

Example 18 with ThingStatus

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

the class NeoBaseHandler method toBaseSendPollResponse.

// ======== helper methods used by this class or descendants ===========
/*
     * this method is called back by the NeoHub handler to inform this handler about
     * polling results from the hub handler
     */
public void toBaseSendPollResponse(NeoHubAbstractDeviceData deviceData) {
    NeoBaseConfiguration config = this.config;
    if (config == null) {
        return;
    }
    AbstractRecord deviceRecord = deviceData.getDeviceRecord(config.deviceNameInHub);
    if (deviceRecord == null) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
        logger.warn(MSG_FMT_DEVICE_CONFIG, thing.getLabel());
        return;
    }
    ThingStatus thingStatus = getThing().getStatus();
    if (deviceRecord.offline() && (thingStatus == ThingStatus.ONLINE)) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR);
        logger.debug(MSG_FMT_DEVICE_COMM, thing.getLabel());
        return;
    }
    if ((!deviceRecord.offline()) && (thingStatus != ThingStatus.ONLINE)) {
        updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE);
    }
    toOpenHabSendChannelValues(deviceRecord);
}
Also used : ThingStatus(org.openhab.core.thing.ThingStatus) AbstractRecord(org.openhab.binding.neohub.internal.NeoHubAbstractDeviceData.AbstractRecord)

Example 19 with ThingStatus

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

the class NeeoRoomHandler method initializeTask.

/**
 * Initializes the task be creating the {@link NeeoRoomProtocol}, going online and then scheduling the refresh task.
 */
private void initializeTask() {
    final NeeoRoomConfig config = getConfigAs(NeeoRoomConfig.class);
    final String roomKey = config.getRoomKey();
    if (roomKey == null || roomKey.isEmpty()) {
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Room key (from the parent room bridge) was not found");
        return;
    }
    try {
        NeeoUtil.checkInterrupt();
        final NeeoBrainApi brainApi = getNeeoBrainApi();
        if (brainApi == null) {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE, "Cannot find the NEEO Brain API");
            return;
        }
        final NeeoRoom room = brainApi.getRoom(roomKey);
        final ThingUID thingUid = getThing().getUID();
        final Map<String, String> properties = new HashMap<>();
        properties.put("Key", roomKey);
        final ThingBuilder thingBuilder = editThing();
        thingBuilder.withLabel(room.getName() + " (NEEO " + brainApi.getBrain().getKey() + ")").withProperties(properties).withChannels(ChannelUtils.generateChannels(thingUid, room));
        updateThing(thingBuilder.build());
        NeeoUtil.checkInterrupt();
        final NeeoRoomProtocol protocol = new NeeoRoomProtocol(new NeeoHandlerCallback() {

            @Override
            public void statusChanged(ThingStatus status, ThingStatusDetail detail, String msg) {
                updateStatus(status, detail, msg);
            }

            @Override
            public void stateChanged(String channelId, State state) {
                updateState(channelId, state);
            }

            @Override
            public void setProperty(String propertyName, String propertyValue) {
                getThing().setProperty(propertyName, propertyValue);
            }

            @Override
            public void scheduleTask(Runnable task, long milliSeconds) {
                scheduler.schedule(task, milliSeconds, TimeUnit.MILLISECONDS);
            }

            @Override
            public void triggerEvent(String channelID, String event) {
                triggerChannel(channelID, event);
            }

            @Nullable
            @Override
            public NeeoBrainApi getApi() {
                return getNeeoBrainApi();
            }
        }, roomKey);
        roomProtocol.getAndSet(protocol);
        NeeoUtil.checkInterrupt();
        updateStatus(ThingStatus.ONLINE);
        if (config.getRefreshPolling() > 0) {
            NeeoUtil.checkInterrupt();
            NeeoUtil.cancel(refreshTask.getAndSet(scheduler.scheduleWithFixedDelay(() -> {
                try {
                    refreshState();
                } catch (InterruptedException e) {
                    logger.debug("Refresh State was interrupted", e);
                }
            }, 0, config.getRefreshPolling(), TimeUnit.SECONDS)));
        }
    } catch (IOException e) {
        logger.debug("IOException during initialization", e);
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "Room " + config.getRoomKey() + " couldn't be found");
    } catch (InterruptedException e) {
        logger.debug("Initialization was interrupted", e);
        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.HANDLER_INITIALIZING_ERROR, "Initialization was interrupted");
    }
}
Also used : ThingBuilder(org.openhab.core.thing.binding.builder.ThingBuilder) HashMap(java.util.HashMap) ThingStatus(org.openhab.core.thing.ThingStatus) ThingStatusDetail(org.openhab.core.thing.ThingStatusDetail) IOException(java.io.IOException) NeeoBrainApi(org.openhab.binding.neeo.internal.NeeoBrainApi) NeeoRoom(org.openhab.binding.neeo.internal.models.NeeoRoom) State(org.openhab.core.types.State) ThingUID(org.openhab.core.thing.ThingUID) NeeoRoomProtocol(org.openhab.binding.neeo.internal.NeeoRoomProtocol) NeeoRoomConfig(org.openhab.binding.neeo.internal.NeeoRoomConfig) Nullable(org.eclipse.jdt.annotation.Nullable) NeeoHandlerCallback(org.openhab.binding.neeo.internal.NeeoHandlerCallback)

Example 20 with ThingStatus

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

the class OpenWeatherMapAPIHandler method updateThings.

private void updateThings() {
    ThingStatus status = ThingStatus.ONLINE;
    List<Thing> childs = getThing().getThings();
    if (!childs.isEmpty()) {
        status = ThingStatus.OFFLINE;
        for (Thing thing : childs) {
            if (ThingStatus.ONLINE.equals(updateThing((AbstractOpenWeatherMapHandler) thing.getHandler(), thing))) {
                status = ThingStatus.ONLINE;
            }
        }
    }
    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