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"); }
public void AddDevice(Device device, bool isNew) { var deviceId = device.deviceId; var friendlyId = device.friendlyId; var manufacturer = device.manufacturer != null ? device.manufacturer : "Manufacturer"; AdapterDevice adapterDevice = null; Task <HttpResponseMessage> response = httpClient.GetAsync(new Uri(DCGWUrl + "devices/" + deviceId)).AsTask(); string body = response.Result.Content.ReadAsStringAsync().AsTask().Result; //DeviceProfiles deviceProifles = JsonConvert.DeserializeObject<DeviceProfiles>(JObject.Parse(body).ToString()); foreach (var eep in device.eeps) { var eepName = eep.eep; response = httpClient.GetAsync(new Uri(DCGWUrl + "profiles/" + eepName)).AsTask(); body = response.Result.Content.ReadAsStringAsync().AsTask().Result; ProfileDefination profileInfo = JsonConvert.DeserializeObject <ProfileDefination>(JObject.Parse(body).ToString()); var profile = profileInfo.profile; var functionGroups = profile.functionGroups; var title = profile.title != null ? profile.title : "TitleDesciption"; if (isLampProfile(eepName)) { adapterDevice = new Lamp(friendlyId, manufacturer, eepName, "0", deviceId, title); ((Lamp)adapterDevice).Adapter = this; } else { adapterDevice = new AdapterDevice(friendlyId, manufacturer, eepName, "0", deviceId, title); foreach (var functionGroup in functionGroups) { string titleFG = functionGroup.title != null ? functionGroup.title : "Property"; string direction = direction = functionGroup.direction;; var functions = functionGroup.functions; var property = new AdapterProperty(titleFG, ""); foreach (var function in functions) { var key = function.key; var description = function.description; var defaultValue = function.defaultValue; var values = function.values; string meaning = null; Range range = null; double min = 0.0; double max = 0.0; double step = 0.0; string unit = null; if (defaultValue == null) { var valueTk = values.First <Value>(); meaning = valueTk.meaning; range = valueTk.range; defaultValue = valueTk.value; if (range != null) { min = range.min; max = range.max; step = range.step; unit = range.unit; defaultValue = range.min; } } object defaultData = Windows.Foundation.PropertyValue.CreateString(defaultValue.ToString()); var valueAttr = new AdapterAttribute(key, defaultData, deviceId, E_ACCESS_TYPE.ACCESS_READWRITE); if (range != null) { valueAttr.Annotations.Add("min", defaultValue.ToString()); valueAttr.Annotations.Add("max", max.ToString()); valueAttr.Annotations.Add("range", step.ToString()); valueAttr.Annotations.Add("unit", unit); } if (direction.Equals("from")) { valueAttr = new AdapterAttribute(key, defaultData, deviceId, E_ACCESS_TYPE.ACCESS_READ); } else if (direction.Equals("both")) { object valueDataTest = Windows.Foundation.PropertyValue.CreateString(""); //This is a workaround to know if device supports both functionality //500 is response status for read only property and 400 for device that support both direct, //status is 400 because we are sending no value (valueDataTest is emplty string) uint status = SetHttpValue("devices/" + deviceId + "/state", valueDataTest, key); if (status == 500) { valueAttr = new AdapterAttribute(key, defaultData, deviceId, E_ACCESS_TYPE.ACCESS_READ); } } valueAttr.COVBehavior = SignalBehavior.Always; adapterDevice.AddChangeOfValueSignal(property, valueAttr.Value); property.Attributes.Add(valueAttr); } adapterDevice.Properties.Add(property); } } } IAdapterMethod Delete = new AdapterMethod("Delete", "Delete EO device", 0, "devices/" + deviceId); adapterDevice.Methods.Add(Delete); AdapterDevice AddedDevice = (AdapterDevice)GetObject(devicesDict, deviceId); if (AddedDevice == null) { this.devicesDict.Add(deviceId, adapterDevice); //update device list in the bridge if device is added when bridge is running if (isNew) { dsbBridge.UpdateDeviceCustome(adapterDevice, false); } this.NotifyDeviceArrival(adapterDevice); } }