protected override void OnStart() { _controlPanelWatcher = new ControlPanelWatcher(this.CreateBusAttachment(ref _controlPanelBusAttachment)); _controlPanelWatcher.Added += this.controlPanelWatcher_Added; _controlPanelWatcher.Start(); _propertyWatcher = new PropertyWatcher(this.CreateBusAttachment(ref _propertyBusAttachment)); _propertyWatcher.Start(); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private async void controlPanelWatcher_Added(ControlPanelWatcher sender, AllJoynServiceInfo args) { // CONTROL PANEL if (args.ObjectPath.Contains("AirConditioner")) { var joinResult = await ControlPanelConsumer.JoinSessionAsync(args, sender); if (joinResult.Status == AllJoynStatus.Ok) { _controlPanelConsumer = joinResult.Consumer; _controlPanelConsumer.SessionLost += OnSessionLost; // PROPERTY // Get a child Property var propertyServiceInfo = new AllJoynServiceInfo( args.UniqueName, args.ObjectPath + "/en/airconSet/power", args.SessionPort); var propJoinResult = await PropertyConsumer.JoinSessionAsync(propertyServiceInfo, _propertyWatcher); if (propJoinResult.Status == AllJoynStatus.Ok) { _powerPropertyConsumer = propJoinResult.Consumer; _powerPropertyConsumer.Signals.ValueChangedReceived += this.powerPropertyConsumer_ValueChangedReceived; } propertyServiceInfo = new AllJoynServiceInfo( args.UniqueName, args.ObjectPath + "/en/set_temperature", args.SessionPort); propJoinResult = await PropertyConsumer.JoinSessionAsync(propertyServiceInfo, _propertyWatcher); if (propJoinResult.Status == AllJoynStatus.Ok) { _targetTemperaturePropertyConsumer = propJoinResult.Consumer; _targetTemperaturePropertyConsumer.Signals.ValueChangedReceived += this.targetTemperaturePropertyConsumer_ValueChangedReceived; } propertyServiceInfo = new AllJoynServiceInfo( args.UniqueName, args.ObjectPath + "/en/set_CurrentTemperature", args.SessionPort); propJoinResult = await PropertyConsumer.JoinSessionAsync(propertyServiceInfo, _propertyWatcher); if (propJoinResult.Status == AllJoynStatus.Ok) { _currentTemperaturePropertyConsumer = propJoinResult.Consumer; _currentTemperaturePropertyConsumer.Signals.ValueChangedReceived += this.targetTemperaturePropertyConsumer_ValueChangedReceived; } propertyServiceInfo = new AllJoynServiceInfo( args.UniqueName, args.ObjectPath + "/en/airconSet2/windStrength", args.SessionPort); propJoinResult = await PropertyConsumer.JoinSessionAsync(propertyServiceInfo, _propertyWatcher); if (propJoinResult.Status == AllJoynStatus.Ok) { _windStrengthPropertyConsumer = propJoinResult.Consumer; _windStrengthPropertyConsumer.Signals.ValueChangedReceived += this.windStrengthPropertyConsumer_ValueChangedReceived; } this.IsConnected = true; // jtasler: Is this really neccessary? Doesn't the device send change updates? var unusedTask = Task.Run(async() => { while (this.IsConnected) { this.powerPropertyConsumer_ValueChangedReceived(null, null); this.windStrengthPropertyConsumer_ValueChangedReceived(null, null); this.targetTemperaturePropertyConsumer_ValueChangedReceived(null, null); this.currentTemperaturePropertyConsumer_ValueChangedReceived(null, null); await Task.Delay(2000); } }); } } }