/* * Connector to receive commands via port 39501 from the voice bridge onfiguration software * * Intial release: 9-Sep-22 */ metadata { definition(name: "UPB Command Connector", namespace: "UPB", author: "UPB Voice Bridge", importUrl: "") { capability "Switch" } } preferences { section("Configuration") { input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: false input name: "ConnectedAt", type: "text", title: "Last configuration update" } } // //----------------------------------------------------------------------------- // Standard stuff //----------------------------------------------------------------------------- // void installed() { } def logsOff() { log.warn ("debug logging disabled..."); device.updateSetting("logEnable", [value: "false", type: "bool"]); } def updated() { log.info ("updated..."); log.warn ("debug logging is: ${logEnable == true}"); if (logEnable) runIn(1800, logsOff); } // //----------------------------------------------------------------------------- // Used by the app //----------------------------------------------------------------------------- // def UpdateConnectedAt(String text) { if (logEnable) log.debug ("In UpdateConnectedAt " + text); device.updateSetting("ConnectedAt", [value: text, type: "text"]); } def UpdateDeviceLabel(String text) { device.setLabel(text) } def GetConnectedAt() { if (logEnable) log.debug ("In GetConnectedAt"); return settings.ConnectedAt; } // //----------------------------------------------------------------------------- // Operations //----------------------------------------------------------------------------- // def parse(String description) { def map = parseLanMessage(description); msgText = map.get('header'); bodyText = map.get('body'); if (logEnable) log.debug(bodyText); // Message is either POST designSync or POST /updateDevice or POST /updateScene if (msgText.indexOf('designSync') != -1) { parent.SyncConfiguration(); return; } else if (msgText.indexOf('updateDevice') != -1) { isDevice = 1; } else if (msgText.indexOf('updateScene') != -1) { isDevice = 0; } else { if (logEnable) log.debug("Unknown command ${msgText}"); return; } // String is upbID,channel,percent iChar = 0; c = bodyText[iChar]; //---- ID iChar = iChar + 1; c = bodyText[iChar]; idText = ""; while (c != ',') { idText = idText + c; iChar = iChar + 1; c = bodyText[iChar]; } int id = idText as Integer; //---- Channel iChar = iChar + 1; c = bodyText[iChar]; channelText = ""; while (c != ',') { channelText = channelText + c; iChar = iChar + 1; c = bodyText[iChar]; } int channel = channelText as Integer; //---- Percent iChar = iChar + 1; c = bodyText[iChar]; percentText = ""; while (c != ',') { percentText = percentText + c; iChar = iChar + 1; c = bodyText[iChar]; } int percent = percentText as Integer; if (logEnable) log.debug(command); if (logEnable) log.debug(id); if (logEnable) log.debug(channel); if (logEnable) log.debug(percent); parent.ProcessStateUpdate(isDevice, id, channel, percent); } def on() { // Not used } def off() { // Not used }