private String getVolumeCommand(PlexBindingConfig config, Command command) { int newVolume = 100; PlexSession session = getSessionByMachineId(config.getMachineIdentifier()); if (session != null) { newVolume = session.getVolume(); } if (command.getClass().equals(PercentType.class)) { PercentType percentType = (PercentType) command; newVolume = percentType.intValue(); } else if (command.getClass().equals(IncreaseDecreaseType.class)) { if (command.equals(IncreaseDecreaseType.DECREASE)) { newVolume = Math.max(0, newVolume - VOLUME_STEP); } else { newVolume = Math.min(100, newVolume + VOLUME_STEP); } } if (session != null) { session.setVolume(newVolume); callback.updateReceived(session); } String url = String.format("playback/setParameters?volume=%d", newVolume); return url; }
private String getProgressCommand(PlexBindingConfig config, Command command) { PlexSession session = getSessionByMachineId(config.getMachineIdentifier()); String url = null; if (session != null) { int offset = 0; if (command.getClass().equals(PercentType.class)) { PercentType percent = (PercentType) command; offset = new BigDecimal(session.getDuration()) .multiply( percent .toBigDecimal() .divide(new BigDecimal("100"), new MathContext(5, RoundingMode.HALF_UP))) .intValue(); offset = Math.max(0, offset); offset = Math.min(session.getDuration(), offset); url = String.format("playback/seekTo?offset=%d", offset); } else if (command.getClass().equals(IncreaseDecreaseType.class)) { if (command.equals(IncreaseDecreaseType.DECREASE)) { url = PlexProperty.STEP_BACK.getName(); } else { url = PlexProperty.STEP_FORWARD.getName(); } } } return url; }
/** {@inheritDoc} */ @Override protected void internalReceiveCommand(String itemName, Command command) { logger.debug("internalReceiveCommand({},{}) is called!", itemName, command); if (harmonyHubGateway == null) { logger.warn( "A command was received, but could not be executed as no Harmony Hub has been configured"); return; } for (HarmonyHubBindingProvider provider : providers) { HarmonyHubBindingConfig config = provider.getHarmonyHubBindingConfig(itemName); if (config.getBindingType().getDirection() == HarmonyHubBindingDirection.IN) { logger.warn( "item {} is not configured to send outbound commands! Please change to > or * in the binding"); continue; } switch (config.getBindingType()) { case PressButton: logger.debug( "PressButton command:{} q:{} p1:{} p2:{}", command.toString(), config.getQualifier(), config.getParam1(), config.getParam2()); String cmd = config.getParam2(); if (cmd == null) { cmd = command.toString(); } try { harmonyHubGateway.pressButton( config.getQualifier(), Integer.parseInt(config.getParam1()), cmd); } catch (NumberFormatException ignored) { harmonyHubGateway.pressButton(config.getQualifier(), config.getParam1(), cmd); } break; case StartActivity: try { harmonyHubGateway.startActivity( config.getQualifier(), Integer.parseInt(config.getParam1())); } catch (NumberFormatException ignored) { harmonyHubGateway.startActivity(config.getQualifier(), config.getParam1()); } break; case CurrentActivity: harmonyHubGateway.startActivity(config.getQualifier(), command.toString()); break; default: break; } } }
/** {@inheritDoc} */ @Override protected void internalReceiveCommand(String itemName, Command command) { try { logger.debug("internalReceiveCommand: itemName '{}', command '{}'", itemName, command); // Lookup the MiOS Unit name and property for this item String unitName = getMiosUnitName(itemName); MiosUnitConnector connector = getMiosConnector(unitName); if (connector == null) { logger.warn( "Received command ({}) for item '{}' but no connector found for MiOS Unit '{}', ignoring", new Object[] {command.toString(), itemName, unitName}); return; } if (!connector.isConnected()) { logger.warn( "Received command ({}) for item '{}' but the connection to the MiOS Unit '{}' is down, ignoring", new Object[] {command.toString(), itemName, unitName}); return; } for (BindingProvider provider : providers) { if (provider instanceof MiosBindingProvider) { MiosBindingProviderImpl miosProvider = (MiosBindingProviderImpl) provider; MiosBindingConfig config = miosProvider.getMiosBindingConfig(itemName); if (config != null) { ItemRegistry reg = miosProvider.getItemRegistry(); if (reg != null) { Item item = reg.getItem(config.getItemName()); State state = item.getState(); connector.invokeCommand(config, command, state); } else { logger.warn( "internalReceiveCommand: Missing ItemRegistry for item '{}' command '{}'", itemName, command); } } else { logger.trace( "internalReceiveCommand: Missing BindingConfig for item '{}' command '{}'", itemName, command); } } } } catch (Exception e) { logger.error("Error handling command", e); } }
@Override protected void internalReceiveCommand(String itemName, Command command) { MqttItemConfig itemConfig = getBindingProvider().getItemConfig(itemName); for (MqttMessagePublisher publisher : itemConfig.getMessagePublishers()) { if (publisher.supportsCommand(command)) { logger.debug("Publishing command {} to {}", command.toString(), publisher.getTopic()); publisher.publish(publisher.getTopic(), command.toString().getBytes()); } } }
@Override public void complete_ValidCommand( EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { super.complete_ValidState(model, ruleCall, context, acceptor); for (Command command : stateAndCommandProvider.getAllCommands()) { if (command.toString().startsWith(context.getPrefix())) { acceptor.accept(createCompletionProposal(command.toString(), context)); } } }
protected void parseDecodedCommand(String itemName, IrCommand theCommand, Command ohCommand) { if (theCommand != null) { // traverse the providers, for each provider, check each binding if it matches theCommand for (IRtransBindingProvider provider : providers) { if (provider.providesBindingFor(itemName)) { List<org.openhab.core.types.Command> commands = provider.getAllCommands(itemName); // first check if commands are defined, and that they have the correct DirectionType Iterator<org.openhab.core.types.Command> listIterator = commands.listIterator(); while (listIterator.hasNext()) { org.openhab.core.types.Command aCommand = listIterator.next(); IrCommand providerCommand = new IrCommand(); providerCommand.remote = provider.getRemote(itemName, aCommand); providerCommand.command = provider.getIrCommand(itemName, aCommand); if (aCommand == ohCommand) { if (providerCommand.matches(theCommand)) { List<Class<? extends State>> stateTypeList = provider.getAcceptedDataTypes(itemName, aCommand); State newState = null; if (aCommand instanceof DecimalType) { newState = createStateFromString( stateTypeList, theCommand.remote + "," + theCommand.command); } else { newState = createStateFromString(stateTypeList, aCommand.toString()); } if (newState != null) { eventPublisher.postUpdate(itemName, newState); } else { logger.warn( "Can not create an Item State to match command {} on item {} ", aCommand, itemName); } } else { logger.info( "The IRtrans command '{},{}' does not match the command '{}' of the binding configuration for item '{}'", new Object[] {theCommand.remote, theCommand.command, ohCommand, itemName}); } } } } } } }
/** {@inheritDoc} */ @Override public SatelCommand convertCommand(Command command, IntegraType integraType, String userCode) { if (command instanceof OnOffType) { boolean switchOn = ((OnOffType) command == OnOffType.ON); switch (this.statusType) { case TROUBLES: case TROUBLES_MEMORY: if (switchOn) { return null; } else { return new ClearTroublesCommand(userCode); } // do nothing for other types of status default: break; } } else if (this.statusType == StatusType.DATE_TIME) { DateTimeType dateTime = null; if (command instanceof StringType) { dateTime = DateTimeType.valueOf(command.toString()); } else if (command instanceof DateTimeType) { dateTime = (DateTimeType) command; } if (dateTime != null) { return new SetClockCommand(dateTime.getCalendar(), userCode); } } return null; }
/** @{inheritDoc */ @Override protected void internalReceiveCommand(String itemName, Command command) { logger.debug( "internalReceiveCommand() for item: " + itemName + " with command: " + command.toString()); if (this.providers.isEmpty()) { logger.error("Binding is properly configured or loaded. No provider was found."); return; } for (PanasonicTVBindingProvider provider : this.providers) { PanasonicTVBindingConfig config = provider.getBindingConfigForItem(itemName); if (config == null) { continue; } int response = sendCommand(config); if (response != 200) { logger.warn( "Command " + config.getCommand() + " to TV with IP " + registeredTVs.get(config.getTv()) + " failed with HTTP Reponse Code " + response); continue; } eventPublisher.postUpdate(itemName, OnOffType.OFF); } }
/* (non-Javadoc) * @see org.openhab.core.binding.AbstractBinding#internalReceiveCommand(java.lang.String, org.openhab.core.types.Command) */ @Override protected void internalReceiveCommand(String itemName, Command command) { logger.trace("Received command (item='{}', command='{}')", itemName, command.toString()); if (!isEcho(itemName, command)) { writeToKNX(itemName, command); } }
/* (non-Javadoc) * @see org.openhab.core.binding.AbstractBinding#internalReceiveCommand(java.lang.String, org.openhab.core.types.Command) */ @Override protected void internalReceiveCommand(String itemName, Command command) { final String type = command.toString().toLowerCase(); for (EBusBindingProvider provider : providers) { byte[] data = commandProcessor.composeSendData(provider, itemName, type); connector.send(data); } }
/** * Called when an openhab command arrives for this device feature * * @param c the binding config of the item which sends the command * @param cmd the command to be exectued */ public void handleCommand(InsteonPLMBindingConfig c, Command cmd) { Class<? extends Command> key = cmd.getClass(); CommandHandler h = m_commandHandlers.containsKey(key) ? m_commandHandlers.get(key) : m_defaultCommandHandler; logger.trace( "{} uses {} to handle command {} for {}", getName(), h.getClass().getSimpleName(), key.getSimpleName(), getDevice().getAddress()); h.handleCommand(c, cmd, getDevice()); }
public void receiveCommand( String itemName, Command command, BticinoBindingConfig itemBindingConfig) { try { synchronized (m_lock) { // An command is received from the openHab system // analyse it and execute it logger.debug( "Gateway [" + m_gateway_id + "], Command '{}' received for item {}", (Object[]) new String[] {command.toString(), itemName}); ProtocolRead l_pr = new ProtocolRead(itemBindingConfig.who + "*" + itemBindingConfig.where); l_pr.addProperty("who", itemBindingConfig.who); l_pr.addProperty("address", itemBindingConfig.where); int l_who = Integer.parseInt(itemBindingConfig.who); switch (l_who) { // Lights case 1: { if (OnOffType.ON.equals(command)) l_pr.addProperty("what", "1"); else l_pr.addProperty("what", "0"); break; } // Shutter case 2: { if (UpDownType.UP.equals(command)) l_pr.addProperty("what", "1"); else if (UpDownType.DOWN.equals(command)) l_pr.addProperty("what", "2"); else if (StopMoveType.STOP.equals(command)) l_pr.addProperty("what", "0"); break; } // CEN Basic & Evolved case 15: { // Only for the on type, send a CEN event (aka a pushbutton // device) // the CEN can start a scenario on eg. a MH200N gateway // device if (OnOffType.ON.equals(command)) l_pr.addProperty("what", itemBindingConfig.what); break; } } m_open_web_net.onCommand(l_pr); } } catch (Exception e) { logger.error( "Gateway [" + m_gateway_id + "], Error processing receiveCommand '{}'", (Object[]) new String[] {e.getMessage()}); } }
/** @{inheritDoc */ @Override protected void internalReceiveCommand(String itemName, Command command) { logger.debug("Received command item='{}', command='{}'", itemName, command.toString()); for (Ipx800DeviceConnector device : devices.values()) { for (Ipx800Port slot : device.getAllPorts()) { Ipx800Item itemSlot = slot.getItemSlot(itemName); if (itemSlot != null) { itemSlot.setState((State) command); if (itemSlot instanceof Ipx800OutputItem) { device.setOutput((Ipx800OutputItem) itemSlot); } } } } }
/** Sends an xPL message upon command received by an Item */ @Override protected void internalReceiveCommand(String itemName, Command command) { for (XplBindingProvider provider : providers) { XplBindingConfig config = provider.getConfig(itemName); if ((config == null) || (config.NamedParameter == null)) { continue; } if (config.Message.getSource() == null) { config.Message.setSource(xplTransportService.getSourceIdentifier()); } config.Message.setNamedValue(config.NamedParameter, command.toString().toLowerCase()); xplTransportService.sendMessage(config.Message); } }
/** {@inheritDoc} */ @Override void receiveCommand( Item item, Command command, ZWaveNode node, ZWaveThermostatFanModeCommandClass commandClass, int endpointId, Map<String, String> arguments) { ZWaveCommandConverter<?, ?> converter = this.getCommandConverter(command.getClass()); if (converter == null) { logger.warn( "NODE {}: No converter found for item = {} endpoint = {}, ignoring command.", node.getNodeId(), item.getName(), endpointId); return; } logger.debug( "NODE {}: receiveCommand with converter {} ", node.getNodeId(), converter.getClass()); SerialMessage serialMessage = node.encapsulate( commandClass.setValueMessage( ((BigDecimal) converter.convertFromCommandToValue(item, command)).intValue()), commandClass, endpointId); logger.debug("NODE {}: receiveCommand sending message {} ", node.getNodeId(), serialMessage); if (serialMessage == null) { logger.warn( "NODE {}: Generating message failed for command class = {}, endpoint = {}", node.getNodeId(), commandClass.getCommandClass().getLabel(), endpointId); return; } this.getController().sendData(serialMessage); if (command instanceof State) this.getEventPublisher().postUpdate(item.getName(), (State) command); }
/** @{inheritDoc} */ @Override protected void internalReceiveCommand(String itemName, Command command) { logger.trace("internalReceiveCommand({},{}) is called!", itemName, command); for (AutelisBindingProvider provider : providers) { Item item = provider.getItem(itemName); String config = provider.getAutelisBindingConfigString(itemName); Matcher m = commandPattern.matcher(config); if (m.find() && m.groupCount() > 1) { String type = m.group(1); String name = m.group(2); if (type.equals(AUTELIS_TYPES_EQUIP)) { String cmd = AUTELIS_CMD_VALUE; int value; if (command == OnOffType.OFF) { value = 0; } else if (command == OnOffType.ON) { value = 1; } else if (command instanceof DecimalType) { value = ((DecimalType) item.getStateAs(DecimalType.class)).intValue(); if (value >= 3) { // this is a dim type. not sure what 2 does cmd = AUTELIS_CMD_DIM; } } else { logger.error("Equipment commands must be of Decimal type not {}", command); break; } String response = HttpUtil.executeUrl( "GET", baseURL + "/set.cgi?name=" + name + "&" + cmd + "=" + value, TIMEOUT); logger.trace("equipment set {} {} {} : result {}", name, cmd, value, response); } else if (type.equals(AUTELIS_TYPES_TEMP)) { String value; if (command == IncreaseDecreaseType.INCREASE) { value = AUTELIS_CMD_UP; } else if (command == IncreaseDecreaseType.DECREASE) { value = AUTELIS_CMD_DOWN; } else { value = command.toString(); } String cmd; // name ending in sp are setpoints, ht are heat types? if (name.endsWith(AUTELIS_SETPOINT)) { cmd = AUTELIS_TYPES_TEMP; } else if (name.endsWith(AUTELIS_HEATTYPE)) { cmd = AUTELIS_CMD_HEAT; } else { logger.error("Unknown temp type {}", name); break; } String response = HttpUtil.executeUrl( "GET", baseURL + "/set.cgi?wait=1&name=" + name + "&" + cmd + "=" + value, TIMEOUT); logger.trace("temp set {} {} : result {}", cmd, value, response); } } else if (config.equals(AUTELIS_TYPES_LIGHTS)) { /* * lighting command * possible values, but we will let anything through. * alloff, allon, csync, cset, cswim, party, romance, caribbean, american, * sunset, royalty, blue, green, red, white, magenta, hold, recall */ String response = HttpUtil.executeUrl("GET", baseURL + "lights.cgi?val=" + command.toString(), TIMEOUT); logger.trace("lights set {} : result {}", command.toString(), response); } else { logger.error("Unsupported set config {}", config); } } scheduleClearTime(UPDATE_CLEARTIME); }
@Override protected void internalReceiveCommand(String itemName, Command command) { // find the EcoTouch binding for the itemName EcoTouchTags tag = null; for (EcoTouchBindingProvider provider : providers) { try { tag = provider.getTypeForItemName(itemName); break; } catch (Exception e) { } } // consider special cases if (tag == EcoTouchTags.TYPE_ADAPT_HEATING) { double adapt = Double.parseDouble(command.toString()); adapt = (adapt + 2) * 2; adapt = Math.max(0, adapt); adapt = Math.min(8, adapt); command = new DecimalType((int) adapt); } EcoTouchConnector connector = new EcoTouchConnector(ip, username, password, cookies); int value = 0; switch (tag.getType()) { case Analog: value = (int) (Double.parseDouble(command.toString()) * 10); break; case Word: if (command == OnOffType.ON) { value = 1; } else if (command == OnOffType.OFF) { value = 0; } else { value = Integer.parseInt(command.toString()); } break; case Bitfield: try { // read-modify-write style value = connector.getValue(tag.getTagName()); int bitmask = 1 << tag.getBitNum(); if (command == OnOffType.OFF || Integer.parseInt(command.toString()) == 0) { value = value & ~bitmask; } else { value = value | bitmask; } } catch (Exception e1) { // connector.getValue() already logged a specific debug message logger.warn("cannot send command '" + command + "' to item '" + itemName + "'"); return; } } try { connector.setValue(tag.getTagName(), value); // It does not make sense to check the returned value from // setValue(). // Even if the tag is read only, one would get the newly set value // back. } catch (Exception e) { // connector.setValue() already logged a specific debug message logger.warn("cannot send command '" + command + "' to item '" + itemName + "'"); } }
/** {@inheritDoc} */ @Override public void internalReceiveCommand(String itemName, Command command) { logger.debug("Received command from {}", itemName); // resolve serial number for item String serialNumber = null; for (MaxCubeBindingProvider provider : providers) { serialNumber = provider.getSerialNumber(itemName); if (StringUtils.isBlank(serialNumber)) { continue; } // send command to MAX!Cube LAN Gateway Device device = findDevice(serialNumber, devices); if (device == null) { logger.debug( "Cannot send command to device with serial number {}, device not listed.", serialNumber); continue; } String rfAddress = device.getRFAddress(); String commandString = null; if (command instanceof DecimalType || command instanceof OnOffType) { DecimalType decimalType = DEFAULT_OFF_TEMPERATURE; if (command instanceof DecimalType) { decimalType = (DecimalType) command; } else if (command instanceof OnOffType) { decimalType = OnOffType.ON.equals(command) ? DEFAULT_ON_TEMPERATURE : DEFAULT_OFF_TEMPERATURE; } S_Command cmd = new S_Command( rfAddress, device.getRoomId(), ((HeatingThermostat) device).getMode(), decimalType.doubleValue()); commandString = cmd.getCommandString(); } else if (command instanceof StringType) { String commandContent = command.toString().trim().toUpperCase(); S_Command cmd = null; ThermostatModeType commandThermoType = null; if (commandContent.contentEquals(ThermostatModeType.AUTOMATIC.toString())) { commandThermoType = ThermostatModeType.AUTOMATIC; cmd = new S_Command(rfAddress, device.getRoomId(), commandThermoType); } else if (commandContent.contentEquals(ThermostatModeType.BOOST.toString())) { commandThermoType = ThermostatModeType.BOOST; Double setTemp = Double.parseDouble(((HeatingThermostat) device).getTemperatureSetpoint().toString()); cmd = new S_Command(rfAddress, device.getRoomId(), commandThermoType, setTemp); } else if (commandContent.contentEquals(ThermostatModeType.MANUAL.toString())) { commandThermoType = ThermostatModeType.MANUAL; Double setTemp = Double.parseDouble(((HeatingThermostat) device).getTemperatureSetpoint().toString()); cmd = new S_Command(rfAddress, device.getRoomId(), commandThermoType, setTemp); logger.debug("updates to MANUAL mode with temperature '{}'", setTemp); } else { logger.debug( "Only updates to AUTOMATIC, MANUAL & BOOST supported, received value ;'{}'", commandContent); continue; } commandString = cmd.getCommandString(); } if (commandString != null) { try { if (socket == null) { this.socketConnect(); } writer.write(commandString); logger.debug(commandString); writer.flush(); Message message = null; String raw = reader.readLine(); try { while (!this.messageProcessor.isMessageAvailable()) { this.messageProcessor.addReceivedLine(raw); raw = reader.readLine(); } message = this.messageProcessor.pull(); } catch (Exception e) { logger.info("Error while handling response from MAX! Cube lan gateway!"); logger.debug(Utils.getStackTrace(e)); this.messageProcessor.reset(); } if (message != null) { if (message.getType() == MessageType.S) { sMessageProcessing((S_Message) message); } } if (!exclusive) { socket.close(); socket = null; } } catch (UnknownHostException e) { logger.info( "Host error occurred while connecting to MAX! Cube lan gateway '{}': {}", ip, e.getMessage()); socketClose(); } catch (IOException e) { logger.info( "IO error occurred while writing to MAX! Cube lan gateway '{}': {}", ip, e.getMessage()); socketClose(); // reconnect on next execution } catch (Exception e) { logger.info( "Error occurred while writing to MAX! Cube lan gateway '{}': {}", ip, e.getMessage()); logger.info(Utils.getStackTrace(e)); socketClose(); // reconnect on next execution } logger.debug("Command Sent to {}", ip); } else { logger.debug("Null Command not sent to {}", ip); } } }