/// <summary> /// Creates the HS device. /// </summary> /// <param name="parent">The data for parent of device.</param> /// <param name="rootDeviceData">The root device data.</param> /// <param name="deviceData">The device data.</param> /// <returns>New Device</returns> private DeviceClass CreateDevice([AllowNull] DeviceClass parent, [AllowNull] RootDeviceData rootDeviceData, DeviceDataBase deviceData) { if (rootDeviceData != null) { LogDebug(Invariant($"Creating {deviceData.Name} under {rootDeviceData.Name}")); } else { LogDebug(Invariant($"Creating Root {deviceData.Name}")); } DeviceClass device = null; int refId = HS.NewDeviceRef(rootDeviceData != null ? Invariant($"{rootDeviceData.Name} {deviceData.Name}") : deviceData.Name); if (refId > 0) { device = (DeviceClass)HS.GetDeviceByRef(refId); string address = rootDeviceData != null?CreateChildAddress(rootDeviceData.Name, deviceData.Name) : deviceData.Name; device.set_Address(HS, address); device.set_Device_Type_String(HS, deviceData.HSDeviceTypeString); var deviceType = new DeviceTypeInfo_m.DeviceTypeInfo(); deviceType.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In; deviceType.Device_Type = deviceData.HSDeviceType; device.set_DeviceType_Set(HS, deviceType); device.set_Interface(HS, Name); device.set_InterfaceInstance(HS, string.Empty); device.set_Last_Change(HS, DateTime.Now); device.set_Location(HS, Name); var pairs = deviceData.StatusPairs; foreach (var pair in pairs) { HS.DeviceVSP_AddPair(refId, pair); } var gPairs = deviceData.GraphicsPairs; foreach (var gpair in gPairs) { HS.DeviceVGP_AddPair(refId, gpair); } device.MISC_Set(HS, Enums.dvMISC.STATUS_ONLY); device.MISC_Set(HS, Enums.dvMISC.SHOW_VALUES); device.MISC_Clear(HS, Enums.dvMISC.AUTO_VOICE_COMMAND); device.MISC_Clear(HS, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE); device.set_Status_Support(HS, false); if (parent != null) { parent.set_Relationship(HS, Enums.eRelationship.Parent_Root); device.set_Relationship(HS, Enums.eRelationship.Child); device.AssociatedDevice_Add(HS, parent.get_Ref(HS)); parent.AssociatedDevice_Add(HS, device.get_Ref(HS)); } deviceData.SetInitialData(HS, device); } return(device); }
private void _createColor(string label) { if (Color != 0) { return; } IHSApplication hs = _plugin.hs; int hsRef = hs.NewDeviceRef(label + " Color"); DeviceClass device = (DeviceClass)hs.GetDeviceByRef(hsRef); device.set_Address(hs, GetSubDeviceAddress(SubDeviceType.Color)); device.set_Interface(hs, _plugin.Name); device.set_InterfaceInstance(hs, _plugin.InstanceFriendlyName()); device.set_Device_Type_String(hs, "LIFX Device Color"); device.set_DeviceType_Set(hs, new DeviceTypeInfo_m.DeviceTypeInfo { Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In }); // Create the buttons and slider VSVGPairs.VSPair colorPicker = new VSVGPairs.VSPair(ePairStatusControl.Both); colorPicker.PairType = VSVGPairs.VSVGPairType.SingleValue; colorPicker.Render = Enums.CAPIControlType.Color_Picker; colorPicker.ControlUse = ePairControlUse._ColorControl; hs.DeviceVSP_AddPair(hsRef, colorPicker); device.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES); hs.SetDeviceString(hsRef, "ffffff", false); Color = hsRef; }
static internal DeviceClass GenericHomeSeerDevice(DeviceClass dv, string dvName, string dvName_long, string device_id) { int dvRef; Log("Creating Device: " + dvName_long + " " + dvName, LogType.LOG_TYPE_INFO); var DT = new DeviceTypeInfo_m.DeviceTypeInfo(); DT.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In; if (dvName.Contains("Root")) { DT.Device_Type = 99; } hs.NewDeviceRef(dvName_long + " " + dvName); dvRef = hs.GetDeviceRefByName(dvName_long + " " + dvName); dv = (DeviceClass)hs.GetDeviceByRef(dvRef); dv.set_Address(hs, ""); SetDeviceKeys(dv, device_id, dvName); //dv.set_Code(hs, device_id + "-" + dvName_long + "-" + dvName); dv.set_Location(hs, "Thermostat"); dv.set_Location2(hs, "Ecobee"); dv.set_Interface(hs, IFACE_NAME); dv.set_Status_Support(hs, true); dv.set_Can_Dim(hs, false); dv.MISC_Set(hs, Enums.dvMISC.NO_LOG); dv.set_DeviceType_Set(hs, DT); dv.set_Relationship(hs, Enums.eRelationship.Child); return(dv); }
private void _createTemperature(string label) { if (Temperature != 0) { return; } IHSApplication hs = _plugin.hs; int hsRef = hs.NewDeviceRef(label + " Color Temperature"); DeviceClass device = (DeviceClass)hs.GetDeviceByRef(hsRef); device.set_Address(hs, GetSubDeviceAddress(SubDeviceType.Temperature)); device.set_Interface(hs, _plugin.Name); device.set_InterfaceInstance(hs, _plugin.InstanceFriendlyName()); device.set_Device_Type_String(hs, "LIFX Device Color Temperature"); device.set_DeviceType_Set(hs, new DeviceTypeInfo_m.DeviceTypeInfo { Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In }); VSVGPairs.VSPair temp = new VSVGPairs.VSPair(ePairStatusControl.Both); temp.PairType = VSVGPairs.VSVGPairType.Range; temp.Render = Enums.CAPIControlType.ValuesRangeSlider; temp.RangeStart = 2500; temp.RangeEnd = 9000; temp.RangeStatusSuffix = " K"; hs.DeviceVSP_AddPair(hsRef, temp); device.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES); _plugin.IgnoreNextDeviceControl(hsRef); hs.SetDeviceValueByRef(hsRef, 3200, false); Temperature = hsRef; }
private void _createBrightness(string label) { if (Brightness != 0) { return; } IHSApplication hs = _plugin.hs; int hsRef = hs.NewDeviceRef(label + " Brightness"); DeviceClass device = (DeviceClass)hs.GetDeviceByRef(hsRef); device.set_Address(hs, GetSubDeviceAddress(SubDeviceType.Brightness)); device.set_Interface(hs, _plugin.Name); device.set_InterfaceInstance(hs, _plugin.InstanceFriendlyName()); device.set_Device_Type_String(hs, "LIFX Device Brightness"); device.set_DeviceType_Set(hs, new DeviceTypeInfo_m.DeviceTypeInfo { Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In }); // Create the buttons and slider VSVGPairs.VSPair offBtn = new VSVGPairs.VSPair(ePairStatusControl.Both); offBtn.PairType = VSVGPairs.VSVGPairType.SingleValue; offBtn.Render = Enums.CAPIControlType.Button; offBtn.Status = "Off"; offBtn.ControlUse = ePairControlUse._Off; offBtn.Value = 0; offBtn.Render_Location = new Enums.CAPIControlLocation { Column = 1, Row = 1, }; VSVGPairs.VSPair onBtn = new VSVGPairs.VSPair(ePairStatusControl.Both); onBtn.PairType = VSVGPairs.VSVGPairType.SingleValue; onBtn.Render = Enums.CAPIControlType.Button; onBtn.Status = "On"; onBtn.ControlUse = ePairControlUse._On; onBtn.Value = 99; onBtn.Render_Location = new Enums.CAPIControlLocation { Column = 2, Row = 1, }; VSVGPairs.VSPair lastBtn = new VSVGPairs.VSPair(ePairStatusControl.Control); lastBtn.PairType = VSVGPairs.VSVGPairType.SingleValue; lastBtn.Render = Enums.CAPIControlType.Button; lastBtn.Status = "Last"; lastBtn.ControlUse = ePairControlUse._On_Alternate; lastBtn.Value = 255; lastBtn.Render_Location = new Enums.CAPIControlLocation { Column = 4, Row = 1, }; VSVGPairs.VSPair dim = new VSVGPairs.VSPair(ePairStatusControl.Both); dim.PairType = VSVGPairs.VSVGPairType.Range; dim.Render = Enums.CAPIControlType.ValuesRangeSlider; dim.RangeStart = 1; dim.RangeEnd = 98; dim.RangeStatusPrefix = "Dim "; dim.RangeStatusSuffix = "%"; dim.ControlUse = ePairControlUse._Dim; dim.Render_Location = new Enums.CAPIControlLocation { Column = 1, Row = 2, ColumnSpan = 3, }; hs.DeviceVSP_AddPair(hsRef, offBtn); hs.DeviceVSP_AddPair(hsRef, onBtn); hs.DeviceVSP_AddPair(hsRef, lastBtn); hs.DeviceVSP_AddPair(hsRef, dim); device.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES); device.MISC_Set(hs, Enums.dvMISC.IS_LIGHT); _plugin.IgnoreNextDeviceControl(hsRef); hs.SetDeviceValueByRef(hsRef, 0, false); Brightness = hsRef; }
static internal bool Camera_Devices(string cString, Camera camera, List <DeviceDataPoint> deviceList) { string name; string id; foreach (var ddPoint in deviceList) { id = GetDeviceKeys(ddPoint.device, out name); if (id == camera.device_id && name == cString) { Update_CameraDevice(camera, ddPoint); return(false); } } DeviceClass dv = new DeviceClass(); dv = GenericHomeSeerDevice(dv, cString, camera.name_long, camera.device_id, cString.Equals("Is Streaming")); var dvRef = dv.get_Ref(hs); id = GetDeviceKeys(dv, out name); switch (name) { case "Is Streaming": { dv.set_Relationship(hs, Enums.eRelationship.Parent_Root); dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES); VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair); SPair = new VSVGPairs.VSPair(ePairStatusControl.Both); SPair.PairType = VSVGPairs.VSVGPairType.SingleValue; SPair.Render = Enums.CAPIControlType.Button; SPair.Value = 1; SPair.Status = "On"; SPair.Render_Location.Row = 1; SPair.Render_Location.Column = 1; hs.DeviceVSP_AddPair(dvRef, SPair); SPair.Value = 0; SPair.Status = "Off"; SPair.Render_Location.Row = 1; SPair.Render_Location.Column = 2; hs.DeviceVSP_AddPair(dvRef, SPair); VSVGPairs.VGPair GPair = new VSVGPairs.VGPair(); GPair.PairType = VSVGPairs.VSVGPairType.SingleValue; GPair.Set_Value = 1; GPair.Graphic = "/images/HomeSeer/contemporary/on.gif"; hs.DeviceVGP_AddPair(dvRef, GPair); GPair.Set_Value = 0; GPair.Graphic = "/images/HomeSeer/contemporary/off.gif"; hs.DeviceVGP_AddPair(dvRef, GPair); break; } } //Update_CameraDevice(camera, dv, nest); return(true); }
static internal bool Structure_Devices(Structures structure, string thermId, List <DeviceDataPoint> deviceList) { string name; string id; foreach (var ddPoint in deviceList) { id = GetDeviceKeys(ddPoint.device, out name); if (id == thermId && name == "Structure") { Update_StructureDevice(structure, ddPoint); return(false); } } DeviceClass dv = new DeviceClass(); dv = GenericHomeSeerDevice(dv, "Structure", structure.name, thermId, false); var dvRef = dv.get_Ref(hs); id = GetDeviceKeys(dv, out name); dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES); VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair); SPair = new VSVGPairs.VSPair(ePairStatusControl.Both); SPair.PairType = VSVGPairs.VSVGPairType.SingleValue; SPair.Render = Enums.CAPIControlType.Button; /*SPair.Value = 0; * SPair.Status = "User Program"; * SPair.Render_Location.Row = 1; * SPair.Render_Location.Column = 1; * hs.DeviceVSP_AddPair(dvRef, SPair); * * SPair.Value = 1; * SPair.Status = "Away-Auto"; * SPair.Render_Location.Row = 1; * SPair.Render_Location.Column = 2; * hs.DeviceVSP_AddPair(dvRef, SPair);*/ SPair.Value = 0; SPair.Status = "Away"; SPair.Render_Location.Row = 1; SPair.Render_Location.Column = 2; hs.DeviceVSP_AddPair(dvRef, SPair); SPair.Value = 1; SPair.Status = "Home"; SPair.Render_Location.Row = 1; SPair.Render_Location.Column = 2; hs.DeviceVSP_AddPair(dvRef, SPair); VSVGPairs.VGPair GPair = new VSVGPairs.VGPair(); GPair.PairType = VSVGPairs.VSVGPairType.Range; GPair.RangeStart = 0; GPair.RangeEnd = 1; GPair.Graphic = "/images/HomeSeer/contemporary/home.png"; hs.DeviceVGP_AddPair(dvRef, GPair); return(true); }
static internal bool Thermostat_Devices(string tString, Thermostat thermostat, Structures structure, List <DeviceDataPoint> deviceList) { string name; string id; foreach (var ddPoint in deviceList) { id = GetDeviceKeys(ddPoint.device, out name); if (id == thermostat.device_id && name == tString) { Update_ThermostatDevice(thermostat, structure, ddPoint); return(false); } } DeviceClass dv = new DeviceClass(); dv = GenericHomeSeerDevice(dv, tString, thermostat.name_long, thermostat.device_id, tString.Equals("Is Online")); var dvRef = dv.get_Ref(hs); id = GetDeviceKeys(dv, out name); switch (name) { case "Is Online": { DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo(); dt.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat; dt.Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Root; dv.set_DeviceType_Set(hs, dt); dv.set_Relationship(hs, Enums.eRelationship.Parent_Root); dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY); VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair); SPair = new VSVGPairs.VSPair(ePairStatusControl.Status); SPair.PairType = VSVGPairs.VSVGPairType.SingleValue; SPair.Value = 1; SPair.Status = "Online"; hs.DeviceVSP_AddPair(dvRef, SPair); SPair.Value = 0; SPair.Status = "Offline"; hs.DeviceVSP_AddPair(dvRef, SPair); VSVGPairs.VGPair GPair = new VSVGPairs.VGPair(); GPair.PairType = VSVGPairs.VSVGPairType.SingleValue; GPair.Set_Value = 1; GPair.Graphic = "/images/HomeSeer/contemporary/ok.png"; hs.DeviceVGP_AddPair(dvRef, GPair); GPair.Set_Value = 0; GPair.Graphic = "/images/HomeSeer/contemporary/off.gif"; hs.DeviceVGP_AddPair(dvRef, GPair); break; } case "HVAC Mode": { dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES); DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo(); dt.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat; dt.Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Mode_Set; dt.Device_SubType = 0; dv.set_DeviceType_Set(hs, dt); VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair); SPair = new VSVGPairs.VSPair(ePairStatusControl.Both); SPair.PairType = VSVGPairs.VSVGPairType.SingleValue; SPair.Render = Enums.CAPIControlType.Button; SPair.Value = 0; SPair.Status = "Off"; SPair.Render_Location.Row = 1; SPair.Render_Location.Column = 1; SPair.ControlUse = ePairControlUse._ThermModeOff; hs.DeviceVSP_AddPair(dvRef, SPair); VSVGPairs.VGPair GPair = new VSVGPairs.VGPair(); GPair.PairType = VSVGPairs.VSVGPairType.SingleValue; GPair.Set_Value = 0; GPair.Graphic = "/images/HomeSeer/contemporary/off.gif"; hs.DeviceVGP_AddPair(dvRef, GPair); if (thermostat.can_cool == true && thermostat.can_heat == true) { SPair.Value = 1; SPair.Status = "Auto"; SPair.Render_Location.Row = 1; SPair.Render_Location.Column = 2; SPair.ControlUse = ePairControlUse._ThermModeAuto; hs.DeviceVSP_AddPair(dvRef, SPair); GPair.PairType = VSVGPairs.VSVGPairType.SingleValue; GPair.Set_Value = 1; GPair.Graphic = "/images/HomeSeer/contemporary/auto-mode.png"; hs.DeviceVGP_AddPair(dvRef, GPair); } if (thermostat.can_cool == true) { SPair.Value = 2; SPair.Status = "Cool"; SPair.Render_Location.Row = 1; SPair.Render_Location.Column = 2; SPair.ControlUse = ePairControlUse._ThermModeCool; hs.DeviceVSP_AddPair(dvRef, SPair); GPair.PairType = VSVGPairs.VSVGPairType.SingleValue; GPair.Set_Value = 2; GPair.Graphic = "/images/HomeSeer/contemporary/cooling.png"; hs.DeviceVGP_AddPair(dvRef, GPair); } if (thermostat.can_heat == true) { SPair.Value = 3; SPair.Status = "Heat"; SPair.Render_Location.Row = 1; SPair.Render_Location.Column = 2; SPair.ControlUse = ePairControlUse._ThermModeHeat; hs.DeviceVSP_AddPair(dvRef, SPair); GPair.PairType = VSVGPairs.VSVGPairType.SingleValue; GPair.Set_Value = 3; GPair.Graphic = "/images/HomeSeer/contemporary/heating.png"; hs.DeviceVGP_AddPair(dvRef, GPair); } SPair.Value = 4; SPair.Status = "Eco"; SPair.Render_Location.Row = 1; SPair.Render_Location.Column = 2; SPair.ControlUse = ePairControlUse.Not_Specified; hs.DeviceVSP_AddPair(dvRef, SPair); GPair.PairType = VSVGPairs.VSVGPairType.SingleValue; GPair.Set_Value = 4; GPair.Graphic = "/images/HomeSeer/contemporary/custom-color.png"; hs.DeviceVGP_AddPair(dvRef, GPair); break; } case "Target Temperature": case "Target Temperature High": case "Target Temperature Low": case "Ambient Temperature": { VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair); SPair = new VSVGPairs.VSPair(ePairStatusControl.Status); SPair.PairType = VSVGPairs.VSVGPairType.Range; SPair.RangeStart = -100; SPair.RangeEnd = 150; SPair.RangeStatusSuffix = " °" + VSVGPairs.VSPair.ScaleReplace; SPair.HasScale = true; hs.DeviceVSP_AddPair(dvRef, SPair); if (name.Equals("Target Temperature") || name.Equals("Target Temperature High") || name.Equals("Target Temperature Low")) { dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES); SPair = new VSVGPairs.VSPair(HomeSeerAPI.ePairStatusControl.Control); SPair.PairType = VSVGPairs.VSVGPairType.Range; SPair.Render = Enums.CAPIControlType.TextBox_Number; SPair.Render_Location.Row = 1; SPair.Render_Location.Column = 1; SPair.Status = "Enter target:"; SPair.RangeStart = 0; SPair.RangeEnd = 100; if (name.Equals("Target Temperature Low")) { SPair.ControlUse = ePairControlUse._HeatSetPoint; DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo(); dt.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat; dt.Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Setpoint; dt.Device_SubType = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceSubType_Setpoint.Heating_1; dv.set_DeviceType_Set(hs, dt); } else if (name.Equals("Target Temperature High")) { SPair.ControlUse = ePairControlUse._CoolSetPoint; DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo(); dt.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat; dt.Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Setpoint; dt.Device_SubType = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceSubType_Setpoint.Cooling_1; dv.set_DeviceType_Set(hs, dt); } hs.DeviceVSP_AddPair(dvRef, SPair); } else if (name.Equals("Ambient Temperature")) { DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo(); dt.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat; dt.Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Temperature; dv.set_DeviceType_Set(hs, dt); } VSVGPairs.VGPair GPair = new VSVGPairs.VGPair(); GPair.PairType = VSVGPairs.VSVGPairType.Range; GPair.RangeStart = -100; GPair.RangeEnd = 150; GPair.Graphic = "/images/HomeSeer/contemporary/thermometer-70.png"; hs.DeviceVGP_AddPair(dvRef, GPair); break; } case "Status": { VSVGPairs.VGPair GPair = new VSVGPairs.VGPair(); GPair.PairType = VSVGPairs.VSVGPairType.SingleValue; GPair.Graphic = "/images/HomeSeer/contemporary/alarmheartbeat.png"; hs.DeviceVGP_AddPair(dvRef, GPair); break; } case "Humidity": { DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo(); dt.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat; dt.Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Temperature; dt.Device_SubType = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceSubType_Temperature.Humidity; dv.set_DeviceType_Set(hs, dt); VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair); SPair = new VSVGPairs.VSPair(ePairStatusControl.Status); SPair.PairType = VSVGPairs.VSVGPairType.Range; SPair.RangeStart = 0; SPair.RangeEnd = 100; SPair.RangeStatusSuffix = " %"; hs.DeviceVSP_AddPair(dvRef, SPair); VSVGPairs.VGPair GPair = new VSVGPairs.VGPair(); GPair.PairType = VSVGPairs.VSVGPairType.Range; GPair.RangeStart = 0; GPair.RangeEnd = 100; GPair.Graphic = "/images/HomeSeer/contemporary/water.gif"; hs.DeviceVGP_AddPair(dvRef, GPair); break; } case "Battery Health": { VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair); SPair = new VSVGPairs.VSPair(ePairStatusControl.Status); SPair.PairType = VSVGPairs.VSVGPairType.SingleValue; SPair.Value = 1; SPair.Status = "Ok"; hs.DeviceVSP_AddPair(dvRef, SPair); SPair.Value = 0; SPair.Status = "Battery Low"; hs.DeviceVSP_AddPair(dvRef, SPair); VSVGPairs.VGPair GPair = new VSVGPairs.VGPair(); GPair.PairType = VSVGPairs.VSVGPairType.SingleValue; GPair.Set_Value = 1; GPair.Graphic = "/images/HomeSeer/contemporary/battery_100.png"; hs.DeviceVGP_AddPair(dvRef, GPair); GPair.Set_Value = 0; GPair.Graphic = "/images/HomeSeer/contemporary/battery_25.png"; hs.DeviceVGP_AddPair(dvRef, GPair); break; } } //Update_ThermostatDevice(thermostat, structure, dv, nest); return(true); }
/// <summary> /// Creates the HS device. /// </summary> /// <param name="optionalParentRefId">The optional parent reference identifier.</param> /// <param name="name">The name of device</param> /// <param name="deviceAddress">The device address.</param> /// <param name="deviceData">The device data.</param> /// <returns> /// New Device /// </returns> private DeviceClass CreateDevice(int?optionalParentRefId, string name, string deviceAddress, DeviceDataBase deviceData) { Trace.TraceInformation(Invariant($"Creating Device with Address:{deviceAddress}")); DeviceClass device = null; int refId = HS.NewDeviceRef(name); if (refId > 0) { device = (DeviceClass)HS.GetDeviceByRef(refId); string address = deviceAddress; device.set_Address(HS, address); device.set_Device_Type_String(HS, deviceData.HSDeviceTypeString); var deviceType = new DeviceTypeInfo_m.DeviceTypeInfo { Device_API = deviceData.DeviceAPI, Device_Type = deviceData.HSDeviceType }; device.set_DeviceType_Set(HS, deviceType); device.set_Interface(HS, PluginData.PlugInName); device.set_InterfaceInstance(HS, string.Empty); device.set_Last_Change(HS, DateTime.Now); device.set_Location(HS, PluginData.PlugInName); device.MISC_Set(HS, Enums.dvMISC.SHOW_VALUES); if (deviceData.StatusDevice) { device.MISC_Set(HS, Enums.dvMISC.STATUS_ONLY); device.MISC_Clear(HS, Enums.dvMISC.AUTO_VOICE_COMMAND); device.MISC_Clear(HS, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE); device.set_Status_Support(HS, true); } else { device.MISC_Set(HS, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE); device.MISC_Set(HS, Enums.dvMISC.AUTO_VOICE_COMMAND); device.set_Status_Support(HS, false); } var pairs = deviceData.StatusPairs; foreach (var pair in pairs) { HS.DeviceVSP_AddPair(refId, pair); } var gPairs = deviceData.GraphicsPairs; foreach (var gpair in gPairs) { HS.DeviceVGP_AddPair(refId, gpair); } DeviceClass parent = null; if (optionalParentRefId.HasValue) { parent = (DeviceClass)HS.GetDeviceByRef(optionalParentRefId.Value); } if (parent != null) { parent.set_Relationship(HS, Enums.eRelationship.Parent_Root); device.set_Relationship(HS, Enums.eRelationship.Child); device.AssociatedDevice_Add(HS, parent.get_Ref(HS)); parent.AssociatedDevice_Add(HS, device.get_Ref(HS)); } deviceData.SetOnDeviceCreateData(HS, CameraSettings, refId); } return(device); }
static internal bool Thermostat_Devices(string tString, Thermostat thermostat, List <DeviceDataPoint> deviceList, EcobeeConnection ecobee) { string name; string id; foreach (var ddPoint in deviceList) { id = GetDeviceKeys(ddPoint.device, out name); if (id == thermostat.identifier && name == tString) { Update_ThermostatDevice(thermostat, ddPoint, ecobee); return(false); } } DeviceClass dv = new DeviceClass(); dv = GenericHomeSeerDevice(dv, tString, thermostat.name, thermostat.identifier); var dvRef = dv.get_Ref(hs); id = GetDeviceKeys(dv, out name); switch (name) { case "Root": { DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo(); dt.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat; dt.Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Root; dv.set_DeviceType_Set(hs, dt); dv.set_Relationship(hs, Enums.eRelationship.Parent_Root); dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY); VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair); SPair = new VSVGPairs.VSPair(ePairStatusControl.Status); SPair.PairType = VSVGPairs.VSVGPairType.SingleValue; SPair.Value = 0; SPair.Status = "Thermostat Root"; hs.DeviceVSP_AddPair(dvRef, SPair); VSVGPairs.VGPair GPair = new VSVGPairs.VGPair(); GPair.PairType = VSVGPairs.VSVGPairType.SingleValue; GPair.Set_Value = 0; GPair.Graphic = "/images/HomeSeer/contemporary/ok.png"; hs.DeviceVGP_AddPair(dvRef, GPair); break; } case "HVAC Mode": { dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES); DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo(); dt.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat; dt.Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Mode_Set; dt.Device_SubType = 0; dv.set_DeviceType_Set(hs, dt); VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair); SPair = new VSVGPairs.VSPair(ePairStatusControl.Both); SPair.PairType = VSVGPairs.VSVGPairType.SingleValue; SPair.Render = Enums.CAPIControlType.Button; SPair.Value = 0; SPair.Status = "Off"; SPair.Render_Location.Row = 1; SPair.Render_Location.Column = 1; SPair.ControlUse = ePairControlUse._ThermModeOff; hs.DeviceVSP_AddPair(dvRef, SPair); VSVGPairs.VGPair GPair = new VSVGPairs.VGPair(); GPair.PairType = VSVGPairs.VSVGPairType.SingleValue; GPair.Set_Value = 0; GPair.Graphic = "/images/HomeSeer/contemporary/modeoff.png"; hs.DeviceVGP_AddPair(dvRef, GPair); SPair.Value = 1; SPair.Status = "Auto"; SPair.Render_Location.Row = 1; SPair.Render_Location.Column = 2; SPair.ControlUse = ePairControlUse._ThermModeAuto; hs.DeviceVSP_AddPair(dvRef, SPair); GPair.PairType = VSVGPairs.VSVGPairType.SingleValue; GPair.Set_Value = 1; GPair.Graphic = "/images/HomeSeer/contemporary/auto-mode.png"; hs.DeviceVGP_AddPair(dvRef, GPair); SPair.Value = 2; SPair.Status = "Cool"; SPair.Render_Location.Row = 1; SPair.Render_Location.Column = 2; SPair.ControlUse = ePairControlUse._ThermModeCool; hs.DeviceVSP_AddPair(dvRef, SPair); GPair.PairType = VSVGPairs.VSVGPairType.SingleValue; GPair.Set_Value = 2; GPair.Graphic = "/images/HomeSeer/contemporary/cooling.png"; hs.DeviceVGP_AddPair(dvRef, GPair); SPair.Value = 3; SPair.Status = "Heat"; SPair.Render_Location.Row = 1; SPair.Render_Location.Column = 2; SPair.ControlUse = ePairControlUse._ThermModeHeat; hs.DeviceVSP_AddPair(dvRef, SPair); GPair.PairType = VSVGPairs.VSVGPairType.SingleValue; GPair.Set_Value = 3; GPair.Graphic = "/images/HomeSeer/contemporary/heating.png"; hs.DeviceVGP_AddPair(dvRef, GPair); break; } case "Fan Mode": { dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES); DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo(); dt.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat; dt.Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Fan_Mode_Set; dt.Device_SubType = 0; dv.set_DeviceType_Set(hs, dt); VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair); SPair = new VSVGPairs.VSPair(ePairStatusControl.Both); SPair.PairType = VSVGPairs.VSVGPairType.SingleValue; SPair.Render = Enums.CAPIControlType.Button; SPair.Value = 0; SPair.Status = "Off"; SPair.Render_Location.Row = 1; SPair.Render_Location.Column = 1; hs.DeviceVSP_AddPair(dvRef, SPair); VSVGPairs.VGPair GPair = new VSVGPairs.VGPair(); GPair.PairType = VSVGPairs.VSVGPairType.SingleValue; GPair.Set_Value = 0; GPair.Graphic = "/images/HomeSeer/contemporary/fan-state-off.png"; hs.DeviceVGP_AddPair(dvRef, GPair); SPair.Value = 1; SPair.Status = "On"; SPair.Render_Location.Row = 1; SPair.Render_Location.Column = 2; SPair.ControlUse = ePairControlUse._ThermFanOn; hs.DeviceVSP_AddPair(dvRef, SPair); GPair.PairType = VSVGPairs.VSVGPairType.SingleValue; GPair.Set_Value = 1; GPair.Graphic = "/images/HomeSeer/contemporary/fan-on.png"; hs.DeviceVGP_AddPair(dvRef, GPair); SPair.Value = 2; SPair.Status = "Auto"; SPair.Render_Location.Row = 1; SPair.Render_Location.Column = 2; SPair.ControlUse = ePairControlUse._ThermFanAuto; hs.DeviceVSP_AddPair(dvRef, SPair); GPair.PairType = VSVGPairs.VSVGPairType.SingleValue; GPair.Set_Value = 2; GPair.Graphic = "/images/HomeSeer/contemporary/fan-auto.png"; hs.DeviceVGP_AddPair(dvRef, GPair); break; } case "Deadband": case "Target Temperature High": case "Target Temperature Low": case "Ambient Temperature": { VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair); SPair = new VSVGPairs.VSPair(ePairStatusControl.Status); SPair.PairType = VSVGPairs.VSVGPairType.Range; SPair.RangeStart = -150; SPair.RangeEnd = 100; SPair.RangeStatusSuffix = " °" + VSVGPairs.VSPair.ScaleReplace; SPair.HasScale = true; hs.DeviceVSP_AddPair(dvRef, SPair); if (name.Equals("Target Temperature High") || name.Equals("Target Temperature Low")) { dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES); SPair = new VSVGPairs.VSPair(HomeSeerAPI.ePairStatusControl.Control); SPair.PairType = VSVGPairs.VSVGPairType.Range; SPair.Render = Enums.CAPIControlType.TextBox_Number; SPair.Render_Location.Row = 1; SPair.Render_Location.Column = 1; SPair.Status = "Enter target:"; SPair.RangeStart = 0; SPair.RangeEnd = 100; if (name.Equals("Target Temperature Low")) { SPair.ControlUse = ePairControlUse._HeatSetPoint; DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo(); dt.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat; dt.Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Setpoint; dt.Device_SubType = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceSubType_Setpoint.Heating_1; dv.set_DeviceType_Set(hs, dt); } else if (name.Equals("Target Temperature High")) { SPair.ControlUse = ePairControlUse._CoolSetPoint; DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo(); dt.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat; dt.Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Setpoint; dt.Device_SubType = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceSubType_Setpoint.Cooling_1; dv.set_DeviceType_Set(hs, dt); } hs.DeviceVSP_AddPair(dvRef, SPair); } else if (name.Equals("Ambient Temperature")) { DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo(); dt.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat; dt.Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Temperature; dv.set_DeviceType_Set(hs, dt); } VSVGPairs.VGPair GPair = new VSVGPairs.VGPair(); GPair.PairType = VSVGPairs.VSVGPairType.Range; GPair.RangeStart = -100; GPair.RangeEnd = 150; GPair.Graphic = "/images/HomeSeer/contemporary/Thermometer-70.png"; hs.DeviceVGP_AddPair(dvRef, GPair); break; } case "Current Program": { dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES); VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair); SPair = new VSVGPairs.VSPair(ePairStatusControl.Status); SPair.PairType = VSVGPairs.VSVGPairType.SingleValue; SPair.Value = 0; SPair.Status = "Hold"; hs.DeviceVSP_AddPair(dvRef, SPair); SPair.Value = 1; SPair.Status = "Demand Response"; hs.DeviceVSP_AddPair(dvRef, SPair); SPair.Value = 2; SPair.Status = "Sensor"; hs.DeviceVSP_AddPair(dvRef, SPair); SPair.Value = 3; SPair.Status = "Switch Occupancy"; hs.DeviceVSP_AddPair(dvRef, SPair); SPair.Value = 4; SPair.Status = "Vacation"; hs.DeviceVSP_AddPair(dvRef, SPair); SPair.Value = 5; SPair.Status = "Quick Save"; hs.DeviceVSP_AddPair(dvRef, SPair); SPair.Value = 6; SPair.Status = "Today"; hs.DeviceVSP_AddPair(dvRef, SPair); SPair.Value = 7; SPair.Status = "Template"; hs.DeviceVSP_AddPair(dvRef, SPair); VSVGPairs.VGPair GPair = new VSVGPairs.VGPair(); GPair.PairType = VSVGPairs.VSVGPairType.Range; GPair.RangeStart = 0; GPair.RangeEnd = 4; GPair.Graphic = "/images/HomeSeer/contemporary/home.png"; hs.DeviceVGP_AddPair(dvRef, GPair); break; } case "HVAC Status": case "Fan Status": case "Cool Range": case "Heat Range": { VSVGPairs.VGPair GPair = new VSVGPairs.VGPair(); GPair.PairType = VSVGPairs.VSVGPairType.SingleValue; GPair.Graphic = "/images/HomeSeer/contemporary/alarmheartbeat.png"; hs.DeviceVGP_AddPair(dvRef, GPair); break; } case "Humidity": { DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo(); dt.Device_API = DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat; dt.Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceType_Thermostat.Temperature; dt.Device_SubType = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceSubType_Temperature.Humidity; dv.set_DeviceType_Set(hs, dt); VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair); SPair = new VSVGPairs.VSPair(ePairStatusControl.Status); SPair.PairType = VSVGPairs.VSVGPairType.Range; SPair.RangeStart = 0; SPair.RangeEnd = 100; SPair.RangeStatusSuffix = " %"; hs.DeviceVSP_AddPair(dvRef, SPair); VSVGPairs.VGPair GPair = new VSVGPairs.VGPair(); GPair.PairType = VSVGPairs.VSVGPairType.Range; GPair.RangeStart = 0; GPair.RangeEnd = 100; GPair.Graphic = "/images/HomeSeer/contemporary/water.gif"; hs.DeviceVGP_AddPair(dvRef, GPair); break; } case "Occupancy": { VSVGPairs.VSPair SPair = default(VSVGPairs.VSPair); SPair = new VSVGPairs.VSPair(ePairStatusControl.Status); SPair.PairType = VSVGPairs.VSVGPairType.SingleValue; SPair.Value = 0; SPair.Status = "Unoccupied"; hs.DeviceVSP_AddPair(dvRef, SPair); SPair.Value = 1; SPair.Status = "Occupied"; hs.DeviceVSP_AddPair(dvRef, SPair); SPair.Value = 2; SPair.Status = "No Event"; hs.DeviceVSP_AddPair(dvRef, SPair); VSVGPairs.VGPair GPair = new VSVGPairs.VGPair(); GPair.PairType = VSVGPairs.VSVGPairType.SingleValue; GPair.Set_Value = 0; GPair.Graphic = "/images/HomeSeer/contemporary/away.png"; hs.DeviceVGP_AddPair(dvRef, GPair); GPair.Set_Value = 1; GPair.Graphic = "/images/HomeSeer/contemporary/home.png"; hs.DeviceVGP_AddPair(dvRef, GPair); GPair.Set_Value = 2; GPair.Graphic = "/images/HomeSeer/contemporary/userclosing.png"; hs.DeviceVGP_AddPair(dvRef, GPair); break; } } return(true); }