/* public void addSSIDExtraData(Scheduler.Classes.DeviceClass Device, string Key, string value) * { * * * var EDO = Device.get_PlugExtraData_Get(Instance.host); * var parts = HttpUtility.ParseQueryString(EDO.GetNamed("SSIDKey").ToString()); * parts[Key] = value; * EDO.RemoveNamed("SSIDKey"); * EDO.AddNamed("SSIDKey", parts.ToString()); * Device.set_PlugExtraData_Set(Instance.host, EDO); * * }*/ public void setValue(CAPI.CAPIControl ActionIn) { var devID = ActionIn.Ref; var newDevice = SiidDevice.GetFromListByID(Instance.Devices, devID); Instance.host.SetDeviceValueByRef(newDevice.Ref, ActionIn.ControlValue, true); Instance.host.SetDeviceString(newDevice.Ref, "" + ActionIn.ControlValue, true); newDevice.UpdateExtraData("ScratchPadString", "" + ActionIn.ControlValue); }
public string parseInstances(string data) { // Console.WriteLine("ConfigDevicePost: " + data); System.Collections.Specialized.NameValueCollection changed = null; changed = System.Web.HttpUtility.ParseQueryString(data); string partID = changed["id"].Split('_')[0]; int devId = Int32.Parse(changed["id"].Split('_')[1]); if (partID == "S") { addSubrule(changed["id"]); } else if (partID == "R") { Reset(SiidDevice.GetFromListByID(Instance.Devices, devId)); } else { if (partID == "ScratchPadString") { changed["value"] = changed["value"].Replace(" ", "%2B"); } SiidDevice newDevice = SiidDevice.GetFromListByID(Instance.Devices, devId); //check for gateway change, do something special if (partID == "Name") { newDevice.Device.set_Name(Instance.host, changed["value"]); } else if (partID == "devdelete") { Instance.host.DeleteDevice(devId); SiidDevice.removeDev(Instance.Devices, devId); } else { newDevice.UpdateExtraData(partID, changed["value"]); UpdateDisplay(newDevice); } } return("True"); }
/// <summary> /// for all accumulators: float/double value ///SIID reset accumulator: -1 ///SIID set day of monthly reset: integer between 0 and 28 ///SIID set rate(units per dollar): float between 200 and 1000 (subtract 200 round to 4 decimal places), rate range between 0 and 800 ///SIID fixed cost: Between 1000 and 2000(subtract 1000 round to 4 decmil, range from 0 to 1000) ///For indoor / outdoor water: ///SIID Tiers(4 tiers with boundaries based on AWC or Lotsize), each tier needs an editable rate. /// Tier 1 rate between 2000 and 3000(subtract 2000, round to 4 decmil, range 0 to 1000) /// Tier 2 rate between 3000 and 4000(subtract 3000, round to 4 decmil, range 0 to 1000) /// Tier 3 rate between 4000 and 5000(subtract 4000, round to 4 decmil, range 0 to 1000) ///SIID AWC: Negative number less than - 10(negate, subtract 10) No hardcoded upper range ///SIID LotSize: -Either AWC or LOTSIZE depending on indooor / outdoor, can use the same range for setting /// </summary> /// <param name="ActionIn"></param> public void scratchpadCommandIn(CAPI.CAPIControl ActionIn) { try { var devID = ActionIn.Ref; var newDevice = SiidDevice.GetFromListByID(Instance.Devices, devID); if (ActionIn.ControlValue == -1) { //reset if -1 Reset(newDevice); } else if (ActionIn.ControlValue >= 0 && ActionIn.ControlValue < 35) { newDevice.UpdateExtraData("IsEnabled", "True"); newDevice.UpdateExtraData("IsAccumulator", "True"); newDevice.UpdateExtraData("ResetType", "3"); newDevice.UpdateExtraData("DayOfMonth", "" + Math.Round(ActionIn.ControlValue).ToString() + ""); } else if (ActionIn.ControlValue >= 200 && ActionIn.ControlValue < 1000) { SetRate(newDevice, ActionIn.ControlValue); } else if (ActionIn.ControlValue >= 1000 && ActionIn.ControlValue < 2000) { SetFixedCost(newDevice, ActionIn.ControlValue); } else if (ActionIn.ControlValue >= 2000) { SetTieredRate(newDevice, ActionIn.ControlValue); } else if (ActionIn.ControlValue <= -10) { SetAWC_LotSize(newDevice, ActionIn.ControlValue); } else { //Set to monthly, accumulator, active, with date as value Instance.hspi.Log("Error when parsing scratchpad command: Command was not in a recognised range. \nDevice: " + ActionIn.Ref + " Command: " + ActionIn.ControlValue.ToString(), 2); } } catch (Exception E) { Instance.hspi.Log("Error when parsing scratchpad command " + E.Message + "\nDevice: " + ActionIn.Ref + " Command: " + ActionIn.ControlValue.ToString(), 2); } }
public string BuildScratchDeviceTab(int id) { StringBuilder sb = new StringBuilder(); SiidDevice Dev = SiidDevice.GetFromListByID(Instance.Devices, id); htmlBuilder ScratchBuilder = new htmlBuilder("Scratch" + Instance.ajaxName); sb.Append("<div><h2>ScratchPad Rules:<h2><hl>"); htmlTable ScratchTable = ScratchBuilder.htmlTable(); ScratchTable.addHead(new string[] { "Rule Name", "Value", "Enable Rule", "Is Accumulator", "Reset Type", "Reset Interval", "Rule String", "Fixed Cost", "Show Tiered Rates", "Rate ($ per unit)", "Real Time Data Rule String", "Rule Formatting", "HomeseerID" }); //0,1,2,3,4,5 int ID = Dev.Ref; List <string> Row = new List <string>(); var EDO = Dev.Extra; var parts = HttpUtility.ParseQueryString(EDO.GetNamed("SSIDKey").ToString()); Row.Add(ScratchBuilder.stringInput("Name_" + ID, Dev.Device.get_Name(Instance.host)).print()); Row.Add(parts["DisplayedValue"]); Row.Add(ScratchBuilder.checkBoxInput("IsEnabled_" + ID, bool.Parse(parts["IsEnabled"])).print()); Row.Add(ScratchBuilder.checkBoxInput("IsAccumulator_" + ID, bool.Parse(parts["IsAccumulator"])).print()); //Reset type is 0=periodically, 1=daily,2=weekly,3=monthly Row.Add(ScratchBuilder.selectorInput(ScratchpadDevice.ResetType, "ResetType_" + ID, "ResetType_" + ID, Convert.ToInt32(parts["ResetType"])).print()); //Based on what selector input, this next cell will be crowded with the different input possibilities where all but one have display none StringBuilder ComplexCell = new StringBuilder(); ComplexCell.Append("<div id=0_" + ID + " style=display:none>Interval in minutes: " + ScratchBuilder.numberInput("ResetInterval_" + ID + "_0", Convert.ToInt32(parts["ResetInterval"])).print() + "</div>"); ComplexCell.Append("<div id=1_" + ID + " style=display:none>" + ScratchBuilder.timeInput("ResetTime_" + ID + "_1", parts["ResetTime"]).print() + "</div>"); ComplexCell.Append("<div id=2_" + ID + " style=display:none>" + ScratchBuilder.selectorInput(GeneralHelperFunctions.DaysOfWeek, "DayOfWeek_" + ID + "_2", "DayOfWeek_" + ID + "_2", Convert.ToInt32(parts["DayOfWeek"])).print() + "</div>"); ComplexCell.Append("<div id=3_" + ID + " style=display:none>Day of the month: " + ScratchBuilder.numberInput("DayOfMonth_" + ID + "_3", Convert.ToInt32(parts["DayOfMonth"])).print() + "</div>"); ComplexCell.Append(@"<script> UpdateDisplay=function(id){ console.log('UPDATING DISPLAY '+id); $('#0_'+id)[0].style.display='none'; $('#1_'+id)[0].style.display='none'; $('#2_'+id)[0].style.display='none'; $('#3_'+id)[0].style.display='none'; V = $('#ResetType_'+id)[0].value; $('#'+V+'_'+id)[0].style.display=''; } DoChange=function(){ console.log('DoChange'); console.log(this); UpdateDisplay(this.id.split('_')[1]); } UpdateDisplay(" + ID + @"); $('#ResetType_" + ID + @"').change(DoChange); //OK HERE </script>"); Row.Add(ComplexCell.ToString()); Row.Add(ScratchBuilder.stringInput("ScratchPadString_" + ID, parts["ScratchPadString"].Replace("(^p^)", "+")).print()); if (parts["FixedCost"] == null) { parts["FixedCost"] = "0"; } Row.Add(ScratchBuilder.stringInput("FixedCost_" + ID, parts["FixedCost"].Replace("(^p^)", "+")).print()); if (parts["showTier"] == null) { parts["showTier"] = "False"; } Row.Add(ScratchBuilder.checkBoxInput("showTier_" + ID, bool.Parse(parts["showTier"])).print()); if (parts["RateTier1"] == null) { parts["RateTier1"] = "0"; } if (parts["RateTier2"] == null) { parts["RateTier2"] = "0"; } if (parts["RateTier3"] == null) { parts["RateTier3"] = "0"; } if (parts["RateTier4"] == null) { parts["RateTier4"] = "0"; } if (parts["AWCOrLot"] == null) { parts["AWCOrLot"] = "8000"; } if (parts["showTier"] == "True") { Row.Add("<div id='tiers" + ID + "' style='display:inline'>Tier 1:" + ScratchBuilder.stringInput("RateTier1_" + ID, parts["RateTier1"]).print() + " Tier 2:" + ScratchBuilder.stringInput("RateTier2_" + ID, parts["RateTier2"]).print() + " Tier 3:" + ScratchBuilder.stringInput("RateTier3_" + ID, parts["RateTier3"]).print() + " Tier 4:" + ScratchBuilder.stringInput("RateTier4_" + ID, parts["RateTier4"]).print() + " AWC or LotSize:" + ScratchBuilder.stringInput("AWCOrLot_" + ID, parts["AWCOrLot"]).print() + "</div>" + "<div id='rate" + ID + "' style='display:none'>" + ScratchBuilder.stringInput("RateValue_" + ID, parts["RateValue"]).print() + "</div>" + @"<script> UpdateTier=function(id){ IsChecked = $('#showTier_' + id)[0].checked; if(IsChecked){ $('#tiers'+id)[0].style.display='inline'; $('#rate'+id)[0].style.display='none'; } else{ $('#tiers'+id)[0].style.display='none'; $('#rate'+id)[0].style.display='inline'; } } TierChange=function(){ console.log('TierChange'); console.log(this); UpdateTier(this.id.split('_')[1]); } UpdateTier(" + ID + @"); $('#showTier_" + ID + @"').change(TierChange); //OK HERE </script>"); } else { Row.Add("<div id='tiers" + ID + "' style='display:none'>Tier 1:" + ScratchBuilder.stringInput("RateTier1_" + ID, parts["RateTier1"]).print() + " Tier 2:" + ScratchBuilder.stringInput("RateTier2_" + ID, parts["RateTier2"]).print() + " Tier 3:" + ScratchBuilder.stringInput("RateTier3_" + ID, parts["RateTier3"]).print() + " Tier 4:" + ScratchBuilder.stringInput("RateTier4_" + ID, parts["RateTier4"]).print() + " AWC or LotSize:" + ScratchBuilder.stringInput("AWCOrLot_" + ID, parts["AWCOrLot"]).print() + "</div>" + "<div id='rate" + ID + "' style='display:none'>" + ScratchBuilder.stringInput("RateValue_" + ID, parts["RateValue"]).print() + "</div>" + @"<script> UpdateTier=function(id){ IsChecked = $('#showTier_' + id)[0].checked; if(IsChecked){ $('#tiers'+id)[0].style.display='inline'; $('#rate'+id)[0].style.display='none'; } else{ $('#tiers'+id)[0].style.display='none'; $('#rate'+id)[0].style.display='inline'; } } TierChange=function(){ console.log('TierChange'); console.log(this); UpdateTier(this.id.split('_')[1]); } UpdateTier(" + ID + @"); $('#showTier_" + ID + @"').change(TierChange); //OK HERE </script>"); } Row.Add(ScratchBuilder.stringInput("LiveUpdateID_" + ID, parts["LiveUpdateID"]).print()); //Instance.hspi.Log(parts["ScratchPadString"],0); Row.Add(ScratchBuilder.stringInput("DisplayString_" + ID, parts["DisplayString"]).print()); Row.Add("" + Dev.Ref); Row.Add(ScratchBuilder.button("R_" + ID.ToString(), "Reset").print()); Row.Add(ScratchBuilder.DeleteDeviceButton(ID.ToString()).print()); // Row.Add(ScratchBuilder.button("S_" + ID.ToString(), "Add Associated Device").print()); ScratchTable.addArrayRow(Row.ToArray()); sb.Append(ScratchTable.print()); sb.Append("</div>"); return(sb.ToString()); }
public string addSubrule(string data) { //Make a new rule, but make it in service to an existing rule: var dv = Instance.host.NewDeviceRef("R"); Scheduler.Classes.DeviceClass newDevice = (Scheduler.Classes.DeviceClass)Instance.host.GetDeviceByRef(dv); newDevice.set_InterfaceInstance(Instance.host, Instance.name); newDevice.set_Name(Instance.host, "Type Meter Rate" + dv); // newDevice.set_Location2(Instance.host, "ScratchpadSubRule"); newDevice.set_Location(Instance.host, "Utilities"); newDevice.set_Location2(Instance.host, "Rates"); //newDevice.set_Interface(Instance.host, "Modbus Configuration");//Put here the registered name of the page for what we want in the Modbus tab!!! So easy! newDevice.set_Interface(Instance.host, Util.IFACE_NAME); //Needed to link device to plugin, so the tab calls back to the correct hardcoded homeseer function //newDevice.set_InterfaceInstance()'' SET INTERFACE INSTANCE newDevice.set_Relationship(Instance.host, Enums.eRelationship.Not_Set); newDevice.MISC_Set(Instance.host, Enums.dvMISC.NO_LOG); newDevice.MISC_Set(Instance.host, Enums.dvMISC.SHOW_VALUES); // newDevice.MISC_Set(Instance.host, Enums.dvMISC.HIDDEN); HomeSeerAPI.PlugExtraData.clsPlugExtraData EDO = new PlugExtraData.clsPlugExtraData(); // EDO = newDevice.get_PlugExtraData_Get(Instance.host); string ruleString = makeNewRules(); string userNote = newDevice.get_UserNote(Instance.host); userNote = userNote.Split("PLUGIN EXTRA DATA:".ToCharArray())[0]; userNote += "PLUGIN EXTRA DATA:" + ruleString.ToString(); newDevice.set_UserNote(Instance.host, userNote); EDO.AddNamed("SSIDKey", ruleString); newDevice.set_PlugExtraData_Set(Instance.host, EDO); // newDevice.set_Device_Type_String(Instance.host, makeNewModbusGateway()); var DevINFO = new DeviceTypeInfo_m.DeviceTypeInfo(); DevINFO.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In; newDevice.set_DeviceType_Set(Instance.host, DevINFO); Instance.Devices.Add(new SiidDevice(Instance, newDevice)); MakeStewardVSP(dv); StringBuilder stb = new StringBuilder(); var page = this; string GatewayID = data.Split("_".ToCharArray())[1]; SiidDevice GateWay = SiidDevice.GetFromListByID(Instance.Devices, Convert.ToInt32(GatewayID)); Scheduler.Classes.DeviceClass Gateway = GateWay.Device; //Should keep in gateway a list of devices Gateway.AssociatedDevice_Add(Instance.host, dv); //This is totally working actually return("refresh"); stb.Append("<meta http-equiv=\"refresh\" content = \"0; URL='/deviceutility?ref=" + dv + "&edit=1'\" />"); // stb.Append("<a id = 'LALA' href='/deviceutility?ref=" + dv + "&edit=1'/><script>LALA.click()</script> "); page.AddBody(stb.ToString()); return(page.BuildPage()); }