1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Server/Actions/ActionHarmonyCommand.cs Wed Aug 17 13:41:26 2016 +0200
1.3 @@ -0,0 +1,76 @@
1.4 +using Ear = SharpLib.Ear;
1.5 +using SharpLib.Ear;
1.6 +using System;
1.7 +using System.Collections.Generic;
1.8 +using System.Linq;
1.9 +using System.Text;
1.10 +using System.Threading.Tasks;
1.11 +using System.Runtime.Serialization;
1.12 +
1.13 +namespace SharpDisplayManager
1.14 +{
1.15 + [DataContract]
1.16 + [AttributeObject(Id = "Harmony.Command", Name = "Harmony Command", Description = "Send a command to your Logitech Harmony Hub.")]
1.17 + class ActionHarmonyCommand : Ear.Action
1.18 + {
1.19 + [DataMember]
1.20 + [AttributeObjectProperty(
1.21 + Id = "Harmony.Command.DeviceId",
1.22 + Name = "Device ID",
1.23 + Description = "The ID of the device this command is associated with."
1.24 + )]
1.25 + public string DeviceId { get; set; } = "";
1.26 +
1.27 +
1.28 + [DataMember]
1.29 + [AttributeObjectProperty(
1.30 + Id = "Harmony.Command.FunctionName",
1.31 + Name = "Function Name",
1.32 + Description = "The name of the function defining this command."
1.33 + )]
1.34 + public string FunctionName { get; set; } = "";
1.35 +
1.36 + /// <summary>
1.37 + ///
1.38 + /// </summary>
1.39 + /// <returns></returns>
1.40 + public override string Brief()
1.41 + {
1.42 + string brief="";
1.43 +
1.44 + if (Program.HarmonyConfig != null)
1.45 + {
1.46 + //What if the device ID is not there anymore?
1.47 + brief += Program.HarmonyConfig.DeviceNameFromId(DeviceId);
1.48 + }
1.49 + else
1.50 + {
1.51 + //No config found just show the device ID then.
1.52 + brief += DeviceId;
1.53 + }
1.54 +
1.55 + brief += " do " + FunctionName;
1.56 +
1.57 + return brief;
1.58 + }
1.59 +
1.60 + /// <summary>
1.61 + ///
1.62 + /// </summary>
1.63 + protected override void DoExecute()
1.64 + {
1.65 + //Fire and forget our command
1.66 + //TODO: check if the harmony client connection is opened
1.67 + if (Program.HarmonyClient!=null)
1.68 + {
1.69 + Program.HarmonyClient.SendCommandAsync(DeviceId, FunctionName);
1.70 + }
1.71 + else
1.72 + {
1.73 + Console.WriteLine("WARNING: No Harmony client connection.");
1.74 + }
1.75 +
1.76 + }
1.77 +
1.78 + }
1.79 +}