//Add an extra AllJoyn device for Learn-in an EO device private AdapterDevice AddLearnInDevice() { AdapterDevice LearnInEODevice = new AdapterDevice("LearnInEODevice", "Digital-Concepts", "", "", "", ""); IAdapterMethod Add_RockerSwitch = new AdapterMethod("Add_RockerSwitch", "Set EO Gateway to learn in mode", 0, ""); Add_RockerSwitch.InputParams.Add(new AdapterValue("FriendlyName", "FriendlyName", null)); LearnInEODevice.Methods.Add(Add_RockerSwitch); IAdapterMethod Add_Sensor = new AdapterMethod("Add_Sensor", "Set EO Gateway to learn in mode", 0, ""); Add_Sensor.InputParams.Add(new AdapterValue("FriendlyName", "FriendlyName", null)); LearnInEODevice.Methods.Add(Add_Sensor); IAdapterMethod Add_Handle = new AdapterMethod("Add_Handle", "Set EO Gateway to learn in mode", 0, ""); Add_Handle.InputParams.Add(new AdapterValue("FriendlyName", "FriendlyName", null)); LearnInEODevice.Methods.Add(Add_Handle); IAdapterMethod Add_Other = new AdapterMethod("Add_Other", "Set EO Gateway to learn in mode", 0, ""); Add_Other.InputParams.Add(new AdapterValue("FriendlyName", "FriendlyName", null)); LearnInEODevice.Methods.Add(Add_Other); return(LearnInEODevice); }
public HueBridgeDevice(Q42.HueApi.HueClient client, HueBridgeDescription desc, Adapter bridge) : base("PhilipsHue", desc.Manufacturer, desc.ModelName, "", desc.SerialNumber, $"{desc.FriendlyName}\n{desc.ModelDescription} ({desc.ModelNumber})") { _client = client; _description = desc; _bridge = bridge; _enableJoinMethod = new AdapterMethod("Link", "Puts the adapter into join mode", 0); _enableJoinMethod.InvokeAction = Link; _enableJoinMethod.OutputParams.Add(new AdapterValue("Result", "") { Data = "" }); Methods.Add(_enableJoinMethod); //var UpdateMethod = new AdapterMethod("Update", "Looks for any removed or added lights", 0); //UpdateMethod.InvokeAction = UpdateDeviceList; //Methods.Add(UpdateMethod); //Check if bridge is already linked and registered bool isLinked = false; var container = ApplicationData.Current.LocalSettings.CreateContainer("RegisteredHueBridges", ApplicationDataCreateDisposition.Always); if (container.Values.ContainsKey(desc.SerialNumber)) { var key = container.Values[desc.SerialNumber] as string; if (key != null) { (client as Q42.HueApi.LocalHueClient)?.Initialize(key); isLinked = true; UpdateDeviceList(); } } _isLinkedProperty = new AdapterProperty("Link", "com.dotMorten.PhilipsHueDSB.PhilipsHue"); _isLinkedProperty.Attributes.Add(new AdapterAttribute("IsLinked", isLinked, E_ACCESS_TYPE.ACCESS_READ) { COVBehavior = SignalBehavior.Always }); this.Properties.Add(_isLinkedProperty); if (desc.ModelName.EndsWith(" 2012")) //V1 bridge { Icon = new AdapterIcon("ms-appx:///AdapterLib/Icons/HueBridge1.png"); } else if (desc.ModelName.EndsWith(" 2015")) //V2 bridge { Icon = new AdapterIcon("ms-appx:///AdapterLib/Icons/HueBridge2.png"); } else //Fallback - use uri from descriptor { Icon = new AdapterIcon(desc.IconUri.OriginalString); } // change of value signal CreateSignals(); }
/* <interface name="org.alljoyn.SmartSpaces.Operation.OnControl"> <annotation name="org.alljoyn.Bus.DocString.En" value="This interface provides capability to switch on the device."/> <annotation name="org.alljoyn.Bus.Secure" value="true"/> <property name="Version" type="q" access="read"> <annotation name="org.alljoyn.Bus.DocString.En" value="The interface version."/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> <method name="SwitchOn"> <annotation name="org.alljoyn.Bus.DocString.En" value="Switch on the device."/> </method> </interface> */ private AdapterInterface CreateOnInterface(bool currentValue) { var iface = new AdapterInterface("org.alljoyn.SmartSpaces.Operation.OnControl"); iface.Properties.Add(new AdapterAttribute("Version", (ushort)1) { COVBehavior = SignalBehavior.Never }); iface.Properties[0].Annotations.Add("org.alljoyn.Bus.DocString.En", "The interface version"); var m = new AdapterMethod("SwitchOn", "Switch on the device.", (sender, input, output) => { OnOff = true; }); iface.Methods.Add(m); return iface; }
internal AdapterMethod(AdapterMethod Other) { this.Name = Other.Name; this.Description = Other.Description; this.HResult = Other.HResult; try { this.InputParams = new List <IAdapterValue>(Other.InputParams); this.OutputParams = new List <IAdapterValue>(Other.OutputParams); } catch (OutOfMemoryException ex) { throw; } }
public HueBridgeDevice(Q42.HueApi.HueClient client, HueBridgeDescription desc, Adapter bridge) : base("PhilipsHue", desc.Manufacturer, desc.ModelName, "", desc.SerialNumber, $"{desc.FriendlyName}\n{desc.ModelDescription} ({desc.ModelNumber})") { _client = client; _description = desc; _bridge = bridge; _enableJoinMethod = new AdapterMethod("Link", "Puts the adapter into join mode", 0); _enableJoinMethod.InvokeAction = Link; _enableJoinMethod.OutputParams.Add(new AdapterValue("Result", "") { Data = "" }); Methods.Add(_enableJoinMethod); //var UpdateMethod = new AdapterMethod("Update", "Looks for any removed or added lights", 0); //UpdateMethod.InvokeAction = UpdateDeviceList; //Methods.Add(UpdateMethod); //Check if bridge is already linked and registered bool isLinked = false; var container = ApplicationData.Current.LocalSettings.CreateContainer("RegisteredHueBridges", ApplicationDataCreateDisposition.Always); if(container.Values.ContainsKey(desc.SerialNumber)) { var key = container.Values[desc.SerialNumber] as string; if (key != null) { (client as Q42.HueApi.LocalHueClient)?.Initialize(key); isLinked = true; UpdateDeviceList(); } } else { Link(); } _isLinkedProperty = new AdapterProperty("Link", "com.dotMorten.PhilipsHueDSB.PhilipsHue"); _isLinkedProperty.Attributes.Add(new AdapterAttribute("IsLinked", isLinked, E_ACCESS_TYPE.ACCESS_READ) { COVBehavior = SignalBehavior.Always }); this.Properties.Add(_isLinkedProperty); //if (desc.IconUri != null) // Icon = new AdapterIcon(desc.IconUri.OriginalString); Icon = new AdapterIcon("ms-appx:///AdapterLib/Icons/PhilipsHueIcon.png"); // change of value signal CreateSignals(); }
internal AdapterMethod(AdapterMethod Other) { this.Name = Other.Name; this.Description = Other.Description; this.HResult = Other.HResult; try { this.InputParams = new List <IAdapterValue>(Other.InputParams); this.OutputParams = new List <IAdapterValue>(Other.OutputParams); } catch (OutOfMemoryException ex) { Debug.WriteLine("Out of memory while trying to allocate adapter method parameter containers." + ex.Message); throw; } }
internal AdapterMethod(AdapterMethod Other) { this.Name = Other.Name; this.Description = Other.Description; this.HResult = Other.HResult; try { this.InputParams = new List<IAdapterValue>(Other.InputParams); this.OutputParams = new List<IAdapterValue>(Other.OutputParams); } catch (OutOfMemoryException ex) { throw; } }
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); } }
public virtual string[] getKeyValue(AdapterMethod method) { return(null); }