예제 #1
0
        /// <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);
        }
예제 #2
0
        public override void SetIOMulti(List <CAPI.CAPIControl> colSend)
        {
            foreach (var control in colSend)
            {
                try
                {
                    int         refId       = control.Ref;
                    DeviceClass deviceClass = (DeviceClass)HS.GetDeviceByRef(refId);

                    var deviceIdentifier = DeviceIdentifier.Identify(deviceClass);

                    lock (connectorManagerLock)
                    {
                        if (connectorManager.TryGetValue(deviceIdentifier.DeviceId, out var connector))
                        {
                            connector.HandleCommand(deviceIdentifier, control.ControlValue, control.ControlUse).Wait();
                        }
                        else
                        {
                            throw new HspiException(Invariant($"{refId} Device Not Found for processing."));
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogError(Invariant($"Failed With {ExceptionHelper.GetFullMessage(ex)}"));
                }
            }
        }
예제 #3
0
        public override bool ActionConfigured(IPlugInAPI.strTrigActInfo actionInfo)
        {
            try
            {
                switch (actionInfo.TANumber)
                {
                case ActionRefreshTANumber:
                    if (actionInfo.DataIn != null)
                    {
                        RefreshDeviceAction refreshDeviceAction = ObjectSerialize.DeSerializeFromBytes(actionInfo.DataIn) as RefreshDeviceAction;
                        if ((refreshDeviceAction != null) && (refreshDeviceAction.DeviceRefId != 0))
                        {
                            return(HS.GetDeviceByRef(refreshDeviceAction.DeviceRefId) != null);
                        }
                    }

                    return(false);

                default:
                    return(base.ActionConfigured(actionInfo));
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(Invariant($"Failed to ActionConfigured with {ex.GetFullMessage()}"));
                return(false);
            }
        }
예제 #4
0
        public override string ConfigDevice(int deviceId, [AllowNull] string user, int userRights, bool newDevice)
        {
            if (newDevice)
            {
                return(string.Empty);
            }

            try
            {
                var deviceClass = (DeviceClass)HS.GetDeviceByRef(deviceId);

                if (deviceClass.get_Interface(HS) == PlugInData.PlugInName)
                {
                    var deviceIdentifier = DeviceIdentifier.Identify(deviceClass);
                    if (deviceIdentifier != null)
                    {
                        return(configPage.GetDeviceImportTab(deviceIdentifier));
                    }
                }
                else
                {
                    return(configPage.GetDeviceHistoryTab(deviceId));
                }
                return(string.Empty);
            }
            catch (Exception ex)
            {
                LogError(Invariant($"ConfigDevice for {deviceId} With {ex.Message}"));
                return(string.Empty);
            }
        }
예제 #5
0
        private async Task RecordDeviceValue(int deviceRefId, TrackedType trackedType)
        {
            var collector = await GetInfluxDBMeasurementsCollector().ConfigureAwait(false);

            if ((collector != null) && collector.IsTracked(deviceRefId, trackedType))
            {
                var device = HS.GetDeviceByRef(deviceRefId) as DeviceClass;
                await RecordDeviceValue(collector, HS, device).ConfigureAwait(false);
            }
        }
예제 #6
0
        public override void SetIOMulti(List <HomeSeerAPI.CAPI.CAPIControl> colSend)
        {
            foreach (CAPI.CAPIControl CC in colSend)
            {
                _log.Debug("SetIOMulti set value: " + CC.ControlValue.ToString() + "->ref:" + CC.Ref.ToString());

                //Get the device that did the request

                HS.SetDeviceValueByRef(CC.Ref, CC.ControlValue, true);

                var device = (Scheduler.Classes.DeviceClass)HS.GetDeviceByRef(CC.Ref);


                //This is a parent device, use its builtin device id
                var ped = (PlugExtraData.clsPlugExtraData)device.get_PlugExtraData_Get(HS);
                _pedData = ped.GetNamed("DeviceIdKey");
                var pedType = ped.GetNamed("Type");


                if (pedType.ToString() == "Target")
                {
                    SetTemperature(Convert.ToInt32(_pedData), Convert.ToInt32(CC.ControlValue));
                }
                else if (pedType.ToString() == "State")
                {
                    if (CC.ControlValue == 1)                     //Turn on ac
                    {
                        PowerOn(Convert.ToInt32(_pedData));
                    }
                    else if (CC.ControlValue == 0)                     //Turn off ac
                    {
                        PowerOff(Convert.ToInt32(_pedData));
                    }
                }
                else if (pedType.ToString() == "OperationMode")
                {
                    SetOperationMode(Convert.ToInt32(_pedData), Convert.ToInt32(CC.ControlValue));
                }
                else if (pedType.ToString() == Constants.FanSpeed)
                {
                    SetFanSpeed(Convert.ToInt32(_pedData), Convert.ToInt32(CC.ControlValue));
                }
                else if (pedType.ToString() == Constants.VaneVertical)
                {
                    SetVaneVertical(Convert.ToInt32(_pedData), Convert.ToInt32(CC.ControlValue));
                }
                else if (pedType.ToString() == Constants.VaneVertical)
                {
                    SetVaneHorizontal(Convert.ToInt32(_pedData), Convert.ToInt32(CC.ControlValue));
                }

                SaveToCloud(Convert.ToInt32(_pedData));
            }
        }
예제 #7
0
        public override string ConfigDevice(int deviceId, [AllowNull] string user, int userRights, bool newDevice)
        {
            if (newDevice)
            {
                return(string.Empty);
            }

            try
            {
                var deviceClass      = (DeviceClass)HS.GetDeviceByRef(deviceId);
                var deviceIdentifier = DeviceIdentifier.Identify(deviceClass);

                if (deviceIdentifier != null)
                {
                    foreach (var camera in pluginConfig.HikvisionIsapiCameras)
                    {
                        if (camera.Key == deviceIdentifier.CameraId)
                        {
                            StringBuilder stb = new StringBuilder();

                            stb.Append(@"<table style='width:100%;border-spacing:0px;'");
                            stb.Append("<tr height='5'><td style='width:25%'></td><td style='width:20%'></td><td style='width:55%'></td></tr>");
                            stb.Append($"<tr><td class='tablecell'>Name:</td><td class='tablecell' colspan=2>");
                            stb.Append(PageHelper.HtmlEncode(camera.Value.Name));
                            stb.Append("</td></tr>");
                            stb.Append($"<tr><td class='tablecell'>Uri:</td><td class='tablecell' colspan=2>");
                            stb.Append(Invariant($"<a href=\"{PageHelper.HtmlEncode(camera.Value.CameraHost)}\" target=\"_blank\">{PageHelper.HtmlEncode(camera.Value.CameraHost)}</a>"));
                            stb.Append("</td></tr>");
                            stb.Append($"<tr><td class='tablecell'>Type:</td><td class='tablecell' colspan=2>");
                            stb.Append(PageHelper.HtmlEncode(deviceIdentifier.DeviceType));
                            stb.Append("</td></tr>");
                            stb.Append(Invariant($"</td><td></td></tr>"));
                            stb.Append("<tr height='5'><td colspan=3></td></tr>");
                            stb.Append(@" </table>");

                            return(stb.ToString());
                        }
                    }
                }

                return(string.Empty);
            }
            catch (Exception ex)
            {
                LogError(Invariant($"ConfigDevice for {deviceId} With {ex.Message}"));
                return(string.Empty);
            }
        }
예제 #8
0
        public override void SetIOMulti(List <HomeSeerAPI.CAPI.CAPIControl> colSend)
        {
            foreach (CAPI.CAPIControl CC in colSend)
            {
                Console.WriteLine(JsonCommand["119788"].ToString());
                Console.WriteLine("SetIOMulti set value: " + CC.ControlValue.ToString() + "->ref:" + CC.Ref.ToString());

                //Get the device that did the request

                HS.SetDeviceValueByRef(CC.Ref, CC.ControlValue, false);

                var device = (Scheduler.Classes.DeviceClass)HS.GetDeviceByRef(CC.Ref);


                //This is a parent device, use its builtin device id
                var ped = (PlugExtraData.clsPlugExtraData)device.get_PlugExtraData_Get(HS);
                pedData = ped.GetNamed("DeviceId");
                var pedType = ped.GetNamed("Type");


                if (pedType.ToString() == "Target")
                {
                    SetTemperature(Convert.ToInt32(pedData), Convert.ToInt32(CC.ControlValue));
                }
                else if (pedType.ToString() == "State")
                {
                    if (CC.ControlValue == 1) //Turn on ac
                    {
                        PowerOn(Convert.ToInt32(pedData));
                    }
                    else if (CC.ControlValue == 0) //Turn off ac
                    {
                        PowerOff(Convert.ToInt32(pedData));
                    }
                }
                else if (pedType.ToString() == "OperationMode")
                {
                    SetOperationMode(Convert.ToInt32(pedData), Convert.ToInt32(CC.ControlValue));
                }
                else if (pedType.ToString() == "FanSpeedDevice")
                {
                    SetFanSpeed(Convert.ToInt32(pedData), Convert.ToInt32(CC.ControlValue));
                }
            }
        }
예제 #9
0
        public override string ConfigDevice(int deviceId, [AllowNull] string user, int userRights, bool newDevice)
        {
            if (newDevice)
            {
                return(string.Empty);
            }

            try
            {
                DeviceClass deviceClass      = (DeviceClass)HS.GetDeviceByRef(deviceId);
                var         deviceIdentifier = DeviceIdentifier.Identify(deviceClass);

                if (deviceIdentifier != null)
                {
                    foreach (var device in pluginConfig.Devices)
                    {
                        if (device.Key == deviceIdentifier.DeviceId)
                        {
                            StringBuilder stb = new StringBuilder();

                            stb.Append(@"<table style='width:100%;border-spacing:0px;'");
                            stb.Append("<tr height='5'><td style='width:25%'></td><td style='width:20%'></td><td style='width:55%'></td></tr>");
                            stb.Append(Invariant($"<tr><td class='tablecell'>Name:</td><td class='tablecell' colspan=2>{ConfigPage.HtmlEncode(device.Value.Name)}</td></tr>"));
                            stb.Append(Invariant($"<tr><td class='tablecell'>Device IP:</td><td class='tablecell' colspan=2>{ConfigPage.HtmlEncode(device.Value.DeviceIP)}</td></tr>"));
                            stb.Append(Invariant($"<tr><td class='tablecell'>Port:</td><td class='tablecell' colspan=2>{ConfigPage.HtmlEncode(deviceIdentifier.Port)}</td></tr>"));
                            stb.Append(Invariant($"<tr><td class='tablecell'>Type:</td><td class='tablecell' colspan=2>{EnumHelper.GetDescription(deviceIdentifier.DeviceType)}</td></tr>"));
                            stb.Append(Invariant($"</td><td></td></tr>"));
                            stb.Append("<tr height='5'><td colspan=3></td></tr>");
                            stb.Append(@" </table>");

                            return(stb.ToString());
                        }
                    }
                }

                return(string.Empty);
            }
            catch (Exception ex)
            {
                LogError(Invariant($"ConfigDevice for {deviceId} With {ex.Message}"));
                return(string.Empty);
            }
        }
예제 #10
0
        public void Fill(int deviceRefId, out string measurement, out double?maxValidValue, out double?minValidValue)
        {
            measurement   = null;
            maxValidValue = null;
            minValidValue = null;

            DeviceClass device     = HS.GetDeviceByRef(deviceRefId) as DeviceClass;
            var         deviceType = device.get_DeviceType_Get(HS);

            measurement = FindTypeString(new string[] {
                deviceType?.Device_SubType_Description,
                deviceType?.Device_API_Description,
                device.get_Name(HS)
            });

            switch (measurement)
            {
            case "temperature":
                maxValidValue = 255;
                minValidValue = -255;
                break;

            case "battery":
            case "humidity":
                maxValidValue = 100;
                minValidValue = 0;
                break;

            case "watts":
            case "kwh":
            case "pressure":
            case "amperes":
            case "co2":
            case "luminance":
            case "pm25":
                minValidValue = 0;
                break;
            }
        }
예제 #11
0
        public string GetName(int deviceRefId)
        {
            DeviceClass device = HS.GetDeviceByRef(deviceRefId) as DeviceClass;

            return(device != null?GetName(device) : null);
        }
예제 #12
0
        /// <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);
        }