StephaneLenclud@236: using Ear = SharpLib.Ear;
StephaneLenclud@236: using SharpLib.Ear;
StephaneLenclud@236: using System;
StephaneLenclud@236: using System.Collections.Generic;
StephaneLenclud@236: using System.Linq;
StephaneLenclud@236: using System.Text;
StephaneLenclud@236: using System.Threading.Tasks;
StephaneLenclud@236: using System.Runtime.Serialization;
StephaneLenclud@236:
StephaneLenclud@236: namespace SharpDisplayManager
StephaneLenclud@236: {
StephaneLenclud@236: [DataContract]
StephaneLenclud@236: [AttributeObject(Id = "Harmony.Command", Name = "Harmony Command", Description = "Send a command to your Logitech Harmony Hub.")]
StephaneLenclud@236: class ActionHarmonyCommand : Ear.Action
StephaneLenclud@236: {
StephaneLenclud@236: [DataMember]
StephaneLenclud@236: [AttributeObjectProperty(
StephaneLenclud@236: Id = "Harmony.Command.DeviceId",
StephaneLenclud@236: Name = "Device ID",
StephaneLenclud@236: Description = "The ID of the device this command is associated with."
StephaneLenclud@236: )]
StephaneLenclud@236: public string DeviceId { get; set; } = "";
StephaneLenclud@236:
StephaneLenclud@236:
StephaneLenclud@236: [DataMember]
StephaneLenclud@236: [AttributeObjectProperty(
StephaneLenclud@236: Id = "Harmony.Command.FunctionName",
StephaneLenclud@236: Name = "Function Name",
StephaneLenclud@236: Description = "The name of the function defining this command."
StephaneLenclud@236: )]
StephaneLenclud@236: public string FunctionName { get; set; } = "";
StephaneLenclud@236:
StephaneLenclud@236: ///
StephaneLenclud@236: ///
StephaneLenclud@236: ///
StephaneLenclud@236: ///
StephaneLenclud@236: public override string Brief()
StephaneLenclud@236: {
StephaneLenclud@238: string brief="Harmony: ";
StephaneLenclud@236:
StephaneLenclud@236: if (Program.HarmonyConfig != null)
StephaneLenclud@236: {
StephaneLenclud@236: //What if the device ID is not there anymore?
StephaneLenclud@236: brief += Program.HarmonyConfig.DeviceNameFromId(DeviceId);
StephaneLenclud@236: }
StephaneLenclud@236: else
StephaneLenclud@236: {
StephaneLenclud@236: //No config found just show the device ID then.
StephaneLenclud@236: brief += DeviceId;
StephaneLenclud@236: }
StephaneLenclud@236:
StephaneLenclud@236: brief += " do " + FunctionName;
StephaneLenclud@236:
StephaneLenclud@236: return brief;
StephaneLenclud@236: }
StephaneLenclud@236:
StephaneLenclud@236: ///
StephaneLenclud@236: ///
StephaneLenclud@236: ///
StephaneLenclud@236: protected override void DoExecute()
StephaneLenclud@236: {
StephaneLenclud@236: //Fire and forget our command
StephaneLenclud@236: //TODO: check if the harmony client connection is opened
StephaneLenclud@236: if (Program.HarmonyClient!=null)
StephaneLenclud@236: {
StephaneLenclud@236: Program.HarmonyClient.SendCommandAsync(DeviceId, FunctionName);
StephaneLenclud@236: }
StephaneLenclud@236: else
StephaneLenclud@236: {
StephaneLenclud@236: Console.WriteLine("WARNING: No Harmony client connection.");
StephaneLenclud@236: }
StephaneLenclud@236:
StephaneLenclud@236: }
StephaneLenclud@236:
StephaneLenclud@236: }
StephaneLenclud@236: }