Server/Actions/ActionHarmonyCommand.cs
author StephaneLenclud
Wed, 17 Aug 2016 13:41:26 +0200
changeset 236 6ba20e02d04f
child 238 c92587ddabcd
permissions -rw-r--r--
Updating HarmonyHub to v0.3.0.
Adding untested Harmony command action.
     1 using Ear = SharpLib.Ear;
     2 using SharpLib.Ear;
     3 using System;
     4 using System.Collections.Generic;
     5 using System.Linq;
     6 using System.Text;
     7 using System.Threading.Tasks;
     8 using System.Runtime.Serialization;
     9 
    10 namespace SharpDisplayManager
    11 {
    12     [DataContract]
    13     [AttributeObject(Id = "Harmony.Command", Name = "Harmony Command", Description = "Send a command to your Logitech Harmony Hub.")]
    14     class ActionHarmonyCommand : Ear.Action
    15     {
    16         [DataMember]
    17         [AttributeObjectProperty(
    18             Id = "Harmony.Command.DeviceId",
    19             Name = "Device ID",
    20             Description = "The ID of the device this command is associated with."
    21         )]
    22         public string DeviceId { get; set; } = "";
    23 
    24 
    25         [DataMember]
    26         [AttributeObjectProperty(
    27         Id = "Harmony.Command.FunctionName",
    28         Name = "Function Name",
    29         Description = "The name of the function defining this command."
    30         )]
    31         public string FunctionName { get; set; } = "";
    32 
    33         /// <summary>
    34         /// 
    35         /// </summary>
    36         /// <returns></returns>
    37         public override string Brief()
    38         {
    39             string brief="";
    40 
    41             if (Program.HarmonyConfig != null)
    42             {
    43                 //What if the device ID is not there anymore?
    44                 brief += Program.HarmonyConfig.DeviceNameFromId(DeviceId);
    45             }
    46             else
    47             {
    48                 //No config found just show the device ID then.
    49                 brief += DeviceId;
    50             }
    51 
    52             brief += " do " + FunctionName;
    53 
    54             return brief;
    55         }
    56 
    57         /// <summary>
    58         /// 
    59         /// </summary>
    60         protected override void DoExecute()
    61         {
    62             //Fire and forget our command
    63             //TODO: check if the harmony client connection is opened
    64             if (Program.HarmonyClient!=null)
    65             {
    66                 Program.HarmonyClient.SendCommandAsync(DeviceId, FunctionName);
    67             }
    68             else
    69             {
    70                 Console.WriteLine("WARNING: No Harmony client connection.");
    71             }
    72             
    73         }
    74 
    75     }
    76 }