Search in sources :

Example 31 with StateOption

use of org.openhab.core.types.StateOption in project openhab-addons by openhab.

the class UpnpServerHandler method updateTitleSelection.

private void updateTitleSelection(List<UpnpEntry> titleList) {
    // Optionally, filter only items that can be played on the renderer
    logger.debug("Filtering content on server {}: {}", thing.getLabel(), config.filter);
    List<UpnpEntry> resultList = config.filter ? filterEntries(titleList, true) : titleList;
    List<StateOption> stateOptionList = new ArrayList<>();
    // Add a directory up selector if not in the directory root
    if ((!resultList.isEmpty() && !(DIRECTORY_ROOT.equals(resultList.get(0).getParentId()))) || (resultList.isEmpty() && !DIRECTORY_ROOT.equals(currentEntry.getId()))) {
        StateOption stateOption = new StateOption(UP, UP);
        stateOptionList.add(stateOption);
        logger.debug("UP added to selection list on server {}", thing.getLabel());
    }
    synchronized (entries) {
        // always only keep the current selection in the entry map to keep memory usage down
        entries.clear();
        resultList.forEach((value) -> {
            StateOption stateOption = new StateOption(value.getId(), value.getTitle());
            stateOptionList.add(stateOption);
            logger.trace("{} added to selection list on server {}", value.getId(), thing.getLabel());
            // back up
            if (value.isContainer()) {
                parentMap.put(value.getId(), value);
            }
            entries.add(value);
        });
    }
    logger.debug("{} entries added to selection list on server {}", stateOptionList.size(), thing.getLabel());
    updateStateDescription(currentSelectionChannelUID, stateOptionList);
    updateState(BROWSE, StringType.valueOf(currentEntry.getId()));
    updateState(CURRENTTITLE, StringType.valueOf(currentEntry.getTitle()));
    serveMedia();
}
Also used : ArrayList(java.util.ArrayList) UpnpEntry(org.openhab.binding.upnpcontrol.internal.queue.UpnpEntry) StateOption(org.openhab.core.types.StateOption)

Example 32 with StateOption

use of org.openhab.core.types.StateOption in project openhab-addons by openhab.

the class UpnpServerHandler method addRendererOption.

/**
 * Add a renderer to the renderer channel state option list.
 * This method is called from the {@link UpnpControlHandlerFactory} class when creating a renderer handler.
 *
 * @param key
 */
public void addRendererOption(String key) {
    synchronized (rendererStateOptionList) {
        UpnpRendererHandler handler = upnpRenderers.get(key);
        if (handler != null) {
            rendererStateOptionList.add(new StateOption(key, handler.getThing().getLabel()));
        }
    }
    updateStateDescription(rendererChannelUID, rendererStateOptionList);
    logger.debug("Renderer option {} added to {}", key, thing.getLabel());
}
Also used : StateOption(org.openhab.core.types.StateOption)

Example 33 with StateOption

use of org.openhab.core.types.StateOption in project openhab-addons by openhab.

the class UpnpServerHandler method initJob.

@Override
protected void initJob() {
    synchronized (jobLock) {
        if (!upnpIOService.isRegistered(this)) {
            updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, "UPnP device with UDN " + getUDN() + " not yet registered");
            return;
        }
        if (!ThingStatus.ONLINE.equals(thing.getStatus())) {
            rendererStateOptionList = Collections.synchronizedList(new ArrayList<>());
            synchronized (rendererStateOptionList) {
                upnpRenderers.forEach((key, value) -> {
                    StateOption stateOption = new StateOption(key, value.getThing().getLabel());
                    rendererStateOptionList.add(stateOption);
                });
            }
            updateStateDescription(rendererChannelUID, rendererStateOptionList);
            getProtocolInfo();
            browse(currentEntry.getId(), "BrowseDirectChildren", "*", "0", "0", config.sortCriteria);
            playlistsListChanged();
            updateStatus(ThingStatus.ONLINE);
        }
        if (!upnpSubscribed) {
            addSubscriptions();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) StateOption(org.openhab.core.types.StateOption)

Example 34 with StateOption

use of org.openhab.core.types.StateOption in project openhab-addons by openhab.

the class ZmBridgeHandler method getMonitors.

@SuppressWarnings("null")
private synchronized List<Monitor> getMonitors() {
    List<Monitor> monitorList = new ArrayList<>();
    if (!zmAuth.isAuthorized()) {
        return monitorList;
    }
    try {
        String response = executeGet(buildUrl("/api/monitors.json"));
        MonitorsDTO monitorsDTO = GSON.fromJson(response, MonitorsDTO.class);
        if (monitorsDTO != null && monitorsDTO.monitorItems != null) {
            List<StateOption> options = new ArrayList<>();
            for (MonitorItemDTO monitorItemDTO : monitorsDTO.monitorItems) {
                MonitorDTO monitorDTO = monitorItemDTO.monitor;
                MonitorStatusDTO monitorStatusDTO = monitorItemDTO.monitorStatus;
                if (monitorDTO != null && monitorStatusDTO != null) {
                    Monitor monitor = new Monitor(monitorDTO.id, monitorDTO.name, monitorDTO.function, monitorDTO.enabled, monitorStatusDTO.status);
                    extractEventCounts(monitor, monitorItemDTO);
                    monitor.setImageUrl(buildStreamUrl(monitorDTO.id, STREAM_IMAGE));
                    monitor.setVideoUrl(buildStreamUrl(monitorDTO.id, STREAM_VIDEO));
                    monitorList.add(monitor);
                    options.add(new StateOption(monitorDTO.id, "Monitor " + monitorDTO.id));
                }
            }
            // Update state options
            stateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), CHANNEL_IMAGE_MONITOR_ID), options);
            stateDescriptionProvider.setStateOptions(new ChannelUID(getThing().getUID(), CHANNEL_VIDEO_MONITOR_ID), options);
            // Only update alarm and event info for monitors whose handlers are initialized
            Set<String> ids = monitorHandlers.keySet();
            for (Monitor m : monitorList) {
                if (ids.contains(m.getId())) {
                    m.setState(getState(m.getId()));
                    m.setLastEvent(getLastEvent(m.getId()));
                }
            }
        }
    } catch (JsonSyntaxException e) {
        logger.debug("Bridge: JsonSyntaxException: {}", e.getMessage(), e);
    }
    return monitorList;
}
Also used : MonitorStatusDTO(org.openhab.binding.zoneminder.internal.dto.MonitorStatusDTO) ArrayList(java.util.ArrayList) StateOption(org.openhab.core.types.StateOption) MonitorItemDTO(org.openhab.binding.zoneminder.internal.dto.MonitorItemDTO) MonitorDTO(org.openhab.binding.zoneminder.internal.dto.MonitorDTO) JsonSyntaxException(com.google.gson.JsonSyntaxException) ChannelUID(org.openhab.core.thing.ChannelUID) MonitorsDTO(org.openhab.binding.zoneminder.internal.dto.MonitorsDTO)

Example 35 with StateOption

use of org.openhab.core.types.StateOption in project openhab-addons by openhab.

the class OppoHandler method buildOptionDropdowns.

private void buildOptionDropdowns(int model) {
    if (model == MODEL83 || model == MODEL103 || model == MODEL105) {
        hdmiModeOptions.add(new StateOption("AUTO", "Auto"));
        hdmiModeOptions.add(new StateOption("SRC", "Source Direct"));
        if (!(model == MODEL83)) {
            hdmiModeOptions.add(new StateOption("4K2K", "4K*2K"));
        }
        hdmiModeOptions.add(new StateOption("1080P", "1080P"));
        hdmiModeOptions.add(new StateOption("1080I", "1080I"));
        hdmiModeOptions.add(new StateOption("720P", "720P"));
        hdmiModeOptions.add(new StateOption("SDP", "480P"));
        hdmiModeOptions.add(new StateOption("SDI", "480I"));
    }
    if (model == MODEL103 || model == MODEL105) {
        inputSourceOptions.add(new StateOption("0", "Blu-Ray Player"));
        inputSourceOptions.add(new StateOption("1", "HDMI/MHL IN-Front"));
        inputSourceOptions.add(new StateOption("2", "HDMI IN-Back"));
        inputSourceOptions.add(new StateOption("3", "ARC"));
        if (model == MODEL105) {
            inputSourceOptions.add(new StateOption("4", "Optical In"));
            inputSourceOptions.add(new StateOption("5", "Coaxial In"));
            inputSourceOptions.add(new StateOption("6", "USB Audio In"));
        }
    }
    if (model == MODEL203 || model == MODEL205) {
        hdmiModeOptions.add(new StateOption("AUTO", "Auto"));
        hdmiModeOptions.add(new StateOption("SRC", "Source Direct"));
        hdmiModeOptions.add(new StateOption("UHD_AUTO", "UHD Auto"));
        hdmiModeOptions.add(new StateOption("UHD24", "UHD24"));
        hdmiModeOptions.add(new StateOption("UHD50", "UHD50"));
        hdmiModeOptions.add(new StateOption("UHD60", "UHD60"));
        hdmiModeOptions.add(new StateOption("1080P_AUTO", "1080P Auto"));
        hdmiModeOptions.add(new StateOption("1080P24", "1080P24"));
        hdmiModeOptions.add(new StateOption("1080P50", "1080P50"));
        hdmiModeOptions.add(new StateOption("1080P60", "1080P60"));
        hdmiModeOptions.add(new StateOption("1080I50", "1080I50"));
        hdmiModeOptions.add(new StateOption("1080I60", "1080I60"));
        hdmiModeOptions.add(new StateOption("720P50", "720P50"));
        hdmiModeOptions.add(new StateOption("720P60", "720P60"));
        hdmiModeOptions.add(new StateOption("576P", "567P"));
        hdmiModeOptions.add(new StateOption("576I", "567I"));
        hdmiModeOptions.add(new StateOption("480P", "480P"));
        hdmiModeOptions.add(new StateOption("480I", "480I"));
        inputSourceOptions.add(new StateOption("0", "Blu-Ray Player"));
        inputSourceOptions.add(new StateOption("1", "HDMI IN"));
        inputSourceOptions.add(new StateOption("2", "ARC"));
        if (model == MODEL205) {
            inputSourceOptions.add(new StateOption("3", "Optical In"));
            inputSourceOptions.add(new StateOption("4", "Coaxial In"));
            inputSourceOptions.add(new StateOption("5", "USB Audio In"));
        }
    }
}
Also used : StateOption(org.openhab.core.types.StateOption)

Aggregations

StateOption (org.openhab.core.types.StateOption)109 ArrayList (java.util.ArrayList)68 ChannelUID (org.openhab.core.thing.ChannelUID)45 BigDecimal (java.math.BigDecimal)22 Test (org.junit.jupiter.api.Test)20 List (java.util.List)17 Nullable (org.eclipse.jdt.annotation.Nullable)17 Channel (org.openhab.core.thing.Channel)17 ChannelTypeUID (org.openhab.core.thing.type.ChannelTypeUID)16 StateDescription (org.openhab.core.types.StateDescription)16 StringType (org.openhab.core.library.types.StringType)14 StateDescriptionFragmentBuilder (org.openhab.core.types.StateDescriptionFragmentBuilder)13 Map (java.util.Map)11 NonNullByDefault (org.eclipse.jdt.annotation.NonNullByDefault)11 StateDescriptionFragment (org.openhab.core.types.StateDescriptionFragment)11 Thing (org.openhab.core.thing.Thing)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 Collectors (java.util.stream.Collectors)9 OnOffType (org.openhab.core.library.types.OnOffType)8