/// <summary> /// Called when the package is started. /// </summary> public override void OnStart() { // Create the STB service this.orangeBox = new OrangeSetTopBox(PackageHost.GetSettingValue("Hostname")); // Attach the event notification this.orangeBox.EventNotificationReceived += (s, e) => { if (PackageHost.GetSettingValue <bool>("Verbose")) { PackageHost.WriteInfo($"Event from {this.orangeBox.CurrentState.MacAddress} : {e.Notification.EventType}"); } // Update the current state PackageHost.PushStateObject("State", this.orangeBox.CurrentState); }; this.orangeBox.StateUpdated += (s, e) => PackageHost.PushStateObject("State", this.orangeBox.CurrentState); // Get the current state var task = this.orangeBox.GetCurrentState(); if (task.Wait(10000) && task.IsCompleted && !task.IsFaulted) { // Listening events this.orangeBox.StartListening(async(error) => { PackageHost.WriteError(error.ToString()); await Task.Delay(2000); }); // Read! PackageHost.WriteInfo($"Connected to {task.Result.FriendlyName} ({task.Result.MacAddress})"); } else { throw new Exception("Unable to connect to your Orange set-top box! Check your configuration & network"); } }
/// <summary> /// Called when the package is started. /// </summary> public override void OnStart() { // After STB action, wait 1second and refresh the STB state this.taskAfterSTBAction = action => { Task.Delay(1000).ContinueWith(_ => this.RefreshState()); return(action.Result); }; // Create the STB service this.orangeBox = new OrangeSetTopBox(PackageHost.GetSettingValue("Hostname")); // Attach the event notification this.orangeBox.EventNotificationReceived += (s, e) => { if (PackageHost.GetSettingValue <bool>("Verbose")) { PackageHost.WriteInfo($"Event from {this.orangeBox.CurrentState.MacAddress} : {e.Notification.EventType}"); } // Update the current state PackageHost.PushStateObject("State", this.orangeBox.CurrentState); }; this.orangeBox.StateUpdated += (s, e) => PackageHost.PushStateObject("State", this.orangeBox.CurrentState); // Get the current state var task = this.orangeBox.GetCurrentState(); if (task.Wait(10000) && task.IsCompleted && !task.IsFaulted) { this.timer = new Timer(PackageHost.GetSettingValue <int>("RefreshInterval")) { AutoReset = true, Enabled = true }; this.timer.Elapsed += async(s, e) => await this.orangeBox.GetCurrentState(); this.timer.Start(); // The URI /remoteControl/notifyEvent has been removed since version 07.35.80 (July 2018). The event's listening below is now obsolete ! // this.orangeBox.StartListening(); // Ready! PackageHost.WriteInfo($"Connected to {task.Result.FriendlyName} ({task.Result.MacAddress})"); } else { throw new Exception("Unable to connect to your Orange set-top box! Check your configuration & network"); } }