/** * Converts a String value "ON" or "1" to {@link OnOffType#ON} or else to {@link OnOffType#OFF}. * * @param state String to convert to {@link OnOffType} * @return returns the ON or OFF state based on the String */ public static OnOffType from(String state) { return from("ON".equalsIgnoreCase(state) || "1".equalsIgnoreCase(state)); }
@Override public String toString() { return toFullString(); }
@Override public String format(String pattern) { return String.format(pattern, this.toString()); }
@Override public void onTriggerFromHandler(String event) { if (CommonTriggerEvents.PRESSED.equals(event)) { OnOffType newState = OnOffType.ON.equals(previousState) ? OnOffType.OFF : OnOffType.ON; callback.sendCommand(newState); previousState = newState; } }
@Override public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { for (Object key : req.getParameterMap().keySet()) { String itemName = key.toString(); if (!itemName.startsWith("__")) { // all additional webapp params start with "__" and should be ignored String commandName = req.getParameter(itemName); try { Item item = itemRegistry.getItem(itemName); // we need a special treatment for the "TOGGLE" command of switches; // this is no command officially supported and must be translated // into real commands by the webapp. if ((item instanceof SwitchItem || item instanceof GroupItem) && commandName.equals("TOGGLE")) { commandName = OnOffType.ON.equals(item.getStateAs(OnOffType.class)) ? "OFF" : "ON"; } Command command = TypeParser.parseCommand(item.getAcceptedCommandTypes(), commandName); if (command != null) { eventPublisher.post(ItemEventFactory.createCommandEvent(itemName, command)); } else { logger.warn("Received unknown command '{}' for item '{}'", commandName, itemName); } } catch (ItemNotFoundException e) { logger.warn("Received command '{}' for item '{}', but the item does not exist in the registry", commandName, itemName); } } } }
if (item != null) { if ("toggle".equalsIgnoreCase(value) && (item instanceof SwitchItem || item instanceof RollershutterItem)) { if (OnOffType.ON.equals(item.getStateAs(OnOffType.class))) { command = OnOffType.OFF; if (OnOffType.OFF.equals(item.getStateAs(OnOffType.class))) { command = OnOffType.ON;
/** * Converts a String value "ON" or "1" to {@link OnOffType#ON} or else to {@link OnOffType#OFF}. * * @param state String to convert to {@link OnOffType} * @return returns the ON or OFF state based on the String */ public static OnOffType from(String state) { return from("ON".equalsIgnoreCase(state) || "1".equalsIgnoreCase(state)); }
@Override public String format(String pattern) { return String.format(pattern, this.toString()); }
@Override public String toString() { return toFullString(); }