/** * Fetches the XML string from a Autelis controller. * * @return */ private String fetchStateFromController() { // we will reconstruct the document with all the responses combined for // XPATH StringBuilder sb = new StringBuilder("<response>"); // pull down the three xml documents String[] statuses = {AUTELIS_TYPES_STATUS, AUTELIS_TYPES_CHEMISTRY, AUTELIS_TYPES_PUMPS}; for (String status : statuses) { String response = HttpUtil.executeUrl("GET", baseURL + "/" + status + ".xml", TIMEOUT); logger.trace(baseURL + "/" + status + ".xml \n {}", response); if (response == null) { logger.warn("No response from Autelis controller!"); return null; } // get the xml data between the response tags and append to our main // doc Matcher m = responsePattern.matcher(response); if (m.find()) { sb.append(m.group(1)); } } // finish our "new" XML Document sb.append("</response>"); /* * This xmlDoc will now contain the three XML documents we retrieved * wrapped in response tags for easier querying in XPath. */ return sb.toString(); }
/** * Send an XBMC notification via POST-HTTP. Errors will be logged, returned values just ignored. * Additional implementation to be able to show also images and to define a display time * * @param host the XBMC client to be notified * @param port the XBMC web server port * @param title the notification title * @param message the notification text * @param image A URL pointing to an image (only used if not null) * @param displayTime A display time for the message in milliseconds (between 1500 and 2147483647 * (inclusive)) */ @ActionDoc( text = "Send an XBMC notification via POST-HTTP. Errors will be logged, returned values just ignored. ") public static void sendXbmcNotification( @ParamDoc(name = "host") String host, @ParamDoc(name = "port") int port, @ParamDoc(name = "title") String title, @ParamDoc(name = "message") String message, @ParamDoc(name = "image") String image, @ParamDoc(name = "displayTime") long displayTime) { String url = "http://" + host + ":" + port + "/jsonrpc"; StringBuilder content = new StringBuilder(); content.append( "{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"GUI.ShowNotification\",\"params\":{\"title\":\"" + title + "\",\"message\":\"" + message + "\""); if (StringUtils.isNotEmpty(image)) { content.append(",\"image\":\"" + image + "\""); } if (displayTime >= 1500 && displayTime <= 2147483647) { content.append(",\"displaytime\":" + displayTime); } content.append("}}"); HttpUtil.executeUrl( "POST", url, IOUtils.toInputStream(content.toString()), CONTENT_TYPE_JSON, 1000); }
/** @{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); }