Exemplo n.º 1
0
        private Dictionary <int, TasmotaDevice> GetCurrentDevices()
        {
            var refIds = HS.GetRefsByInterface(PlugInData.PlugInId);

            var devices = new Dictionary <int, TasmotaDevice>();

            foreach (var refId in refIds)
            {
                combinedToken.Token.ThrowIfCancellationRequested();
                try
                {
                    var relationship = (ERelationship)HS.GetPropertyByRef(refId, EProperty.Relationship);

                    //data is stored in feature(child)
                    if (relationship == ERelationship.Device)
                    {
                        var deviceType = HSDeviceHelper.GetDeviceTypeFromPlugInData(HS, refId);

                        if (deviceType == TasmotaDevice.RootDeviceType)
                        {
                            TasmotaDevice importDevice = new TasmotaDevice(HS, refId, hostedMQTTServerDetails, combinedToken.Token);
                            devices.Add(refId, importDevice);
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Warn(Invariant($"{HSDeviceHelper.GetName(HS, refId)} has invalid plugin data load failed with {ex.GetFullMessage()}. Please recreate it."));
                }
            }

            return(devices);
        }
Exemplo n.º 2
0
        public static PlugExtraData CreatePlugInExtraData(T importDeviceData, string deviceType)
        {
            string data      = JsonConvert.SerializeObject(importDeviceData, Formatting.Indented);
            var    plugExtra = HSDeviceHelper.CreatePlugInExtraDataForDeviceType(deviceType);

            plugExtra.AddNamed(PlugInData.DevicePlugInDataNamedKey, data);
            return(plugExtra);
        }