public void AddEODevice(LearnInTelegram learnInTelegram)
        {
            var device = learnInTelegram.device;

            device.friendlyId = FriendlyName;
            device.operable   = true;

            var timestamp = learnInTelegram.header.timestamp;

            learnInTelegram.header.timestamp = timestamp.Remove(timestamp.Length - 3, 1);
            var firstSeen = device.firstSeen;

            device.firstSeen = firstSeen.Remove(firstSeen.Length - 3, 1);

            if (!NewDeviceProfile.Equals("F6-02-01") && !NewDeviceProfile.Equals("other"))
            {
                device.eeps.First().eep = NewDeviceProfile;

                Task <HttpResponseMessage> response = httpClient.GetAsync(new Uri(DCGWUrl + "profiles/" + NewDeviceProfile)).AsTask();
                string body = response.Result.Content.ReadAsStringAsync().AsTask().Result;

                ProfileDefination profileInfo = JsonConvert.DeserializeObject <ProfileDefination>(JObject.Parse(body).ToString());

                var profile        = profileInfo.profile;
                var functionGroups = profile.functionGroups;

                device.transmitModes.Clear();

                foreach (var functionGroup in functionGroups)
                {
                    var functions = functionGroup.functions;

                    foreach (var function in functions)
                    {
                        TransmitMode transmitMode = new TransmitMode();
                        transmitMode.key = function.key;
                        transmitMode.transmitOnConnect   = function.transmitOnConnect;
                        transmitMode.transmitOnEvent     = function.transmitOnEvent;
                        transmitMode.transmitOnDuplicate = function.transmitOnDuplicate;
                        device.transmitModes.Add(transmitMode);
                    }
                }
                NewDeviceProfile = null;
            }
            SetHttpValue("devices/" + device.deviceId, learnInTelegram, null);
            SetHttpValue("system/receiveMode", null, "normalMode");
        }
        // This thread Listen for any change in Stream API
        private Task ReadStreamAsync()
        {
            return(Task.Run(() =>
            {
                var request = PrepareRequest(HttpMethod.Get, "devices/stream", "", "");
                var response = httpClient.SendRequestAsync(request, HttpCompletionOption.ResponseHeadersRead).AsTask().Result;

                if (response.IsSuccessStatusCode)
                {
                    using (response)
                    {
                        using (var stream = response.Content.ReadAsInputStreamAsync().GetResults())
                        {
                            IBuffer buffer = new Windows.Storage.Streams.Buffer(10000);
                            string bufferStream = "";

                            while (true)
                            {
                                buffer = stream.ReadAsync(buffer, buffer.Capacity, InputStreamOptions.Partial).AsTask().Result;
                                DataReader dataReader = DataReader.FromBuffer(buffer);
                                bufferStream += dataReader.ReadString(buffer.Length);

                                var isJsonValid = ValidateJSON(bufferStream);
                                //Debug.WriteLine(isJsonValid + ":::" + bufferStream + "xxx");
                                if (isJsonValid)
                                {
                                    var streamJson = JObject.Parse(bufferStream);
                                    var JsonProperty = streamJson.Property("header");
                                    Header header = JsonConvert.DeserializeObject <Header>(JsonProperty.Value.ToString());

                                    bufferStream = "";
                                    var content = header.content;
                                    if (content.Equals("telegram"))
                                    {
                                        TelegramBody telegram = JsonConvert.DeserializeObject <TelegramBody>(streamJson.ToString());
                                        updateDevice(telegram.telegram);
                                    }
                                    else
                                    if (content.Equals("device"))
                                    {
                                        LearnInTelegram learnInTelegram = JsonConvert.DeserializeObject <LearnInTelegram>(streamJson.ToString());
                                        var device = learnInTelegram.device;
                                        var deviceId = device.deviceId;
                                        var operable = device.operable;
                                        var deleted = device.deleted;

                                        if (!operable && !deleted)
                                        {
                                            if (NewDeviceProfile != null)
                                            {
                                                AddEODevice(learnInTelegram);
                                            }
                                        }
                                        else if (deleted)
                                        {
                                            AdapterDevice DeletedDevice = (AdapterDevice)GetObject(devicesDict, deviceId);
                                            if (DeletedDevice != null)
                                            {
                                                DeleteDevice(DeletedDevice);
                                            }
                                        }
                                        else if (operable)
                                        {
                                            IList <Device> devices = new List <Device>();
                                            devices.Add(device);
                                            AddDevice(device, true);
                                            UpdateDevices(devices);
                                        }
                                    }
                                    else
                                    if (content.Equals("devices"))
                                    {
                                        StreamDevices devices = JsonConvert.DeserializeObject <StreamDevices>(streamJson.ToString());
                                        UpdateDevices(devices.devices);
                                    }
                                }
                            }
                        }
                    }
                }
            }));
        }