C# Class HarmonyHub.HarmonyClient

Client to interrogate and control Logitech Harmony Hub.
Show file Open project: hdurdle/harmony Class Usage Examples

Public Methods

Method Description
Create ( string host, string token, int port = 5222 ) : HarmonyClient

Create a HarmonyClient with pre-authenticated token

Create ( string host, string username, string password, int port = 5222 ) : Task

Create a harmony client via myharmony.com authenification

Dispose ( ) : void

Cleanup and close

GetConfigAsync ( ) : Task

Request the configuration from the hub

GetCurrentActivityAsync ( ) : Task

Send message to HarmonyHub to request current activity Result is parsed by OnIq based on ClientCommandType

SendCommandAsync ( string deviceId, string command, bool press = true, int timestamp = null ) : System.Threading.Task

Send message to HarmonyHub to request to press a button Result is parsed by OnIq based on ClientCommandType

SendKeyPressAsync ( string deviceId, string command, int timespan = 100 ) : System.Threading.Task

Send a message that a button was pressed Result is parsed by OnIq based on ClientCommandType

StartActivityAsync ( string activityId ) : System.Threading.Task

Send message to HarmonyHub to start a given activity Result is parsed by OnIq based on ClientCommandType

SwapAuthToken ( string userAuthToken ) : Task

Send message to HarmonyHub with UserAuthToken, wait for SessionToken

TurnOffAsync ( ) : System.Threading.Task

Send message to HarmonyHub to request to turn off all devices

Private Methods

Method Description
ErrorHandler ( object sender, Exception ex ) : void

Help with login errors

FireAndForgetAsync ( Document document, int waitTimeout = 50 ) : System.Threading.Task

Send a document, ignore the response (but wait shortly for a possible error)

GenerateIq ( Document document ) : agsXMPP.protocol.client.IQ

Generate an IQ for the supplied Document

GetData ( agsXMPP.protocol.client.IQ iq ) : string

Get the data from the IQ response object

HarmonyClient ( string host, string token, int port = 5222 ) : System

Constructor with standard settings for a new HarmonyClient

OnIqResponseHandler ( object sender, agsXMPP.protocol.client.IQ iq ) : void

Lookup the TaskCompletionSource for the IQ message and try to set the result.

OnLoginHandler ( object sender ) : void

Handle login by completing the _loginTaskCompletionSource

OnMessage ( object sender, agsXMPP.protocol.client.Message message ) : void

Handle incomming messages

RequestResponseAsync ( Document document, int timeout = 2000 ) : Task

Send a document, await the response and return it

SaslStartHandler ( object sender, SaslEventArgs saslEventArgs ) : void

Configure Sasl not to use auto and PLAIN for authentication

Method Details

Create() public static method

Create a HarmonyClient with pre-authenticated token
public static Create ( string host, string token, int port = 5222 ) : HarmonyClient
host string IP or hostname
token string token which is created via an authentication via myharmony.com
port int Port to connect to, 5222 is the default
return HarmonyClient

Create() public static method

Create a harmony client via myharmony.com authenification
public static Create ( string host, string username, string password, int port = 5222 ) : Task
host string IP or hostname
username string myharmony.com username (email)
password string myharmony.com password
port int Port to connect to, default 5222
return Task

Dispose() public method

Cleanup and close
public Dispose ( ) : void
return void

GetConfigAsync() public method

Request the configuration from the hub
public GetConfigAsync ( ) : Task
return Task

GetCurrentActivityAsync() public method

Send message to HarmonyHub to request current activity Result is parsed by OnIq based on ClientCommandType
public GetCurrentActivityAsync ( ) : Task
return Task

SendCommandAsync() public method

Send message to HarmonyHub to request to press a button Result is parsed by OnIq based on ClientCommandType
public SendCommandAsync ( string deviceId, string command, bool press = true, int timestamp = null ) : System.Threading.Task
deviceId string string with the ID of the device
command string string with the command for the device
press bool true for press, false for release
timestamp int Timestamp for the command, e.g. send a press with 0 and a release with 100
return System.Threading.Task

SendKeyPressAsync() public method

Send a message that a button was pressed Result is parsed by OnIq based on ClientCommandType
public SendKeyPressAsync ( string deviceId, string command, int timespan = 100 ) : System.Threading.Task
deviceId string string with the ID of the device
command string string with the command for the device
timespan int The time between the press and release, default 100ms
return System.Threading.Task

StartActivityAsync() public method

Send message to HarmonyHub to start a given activity Result is parsed by OnIq based on ClientCommandType
public StartActivityAsync ( string activityId ) : System.Threading.Task
activityId string string
return System.Threading.Task

SwapAuthToken() public method

Send message to HarmonyHub with UserAuthToken, wait for SessionToken
public SwapAuthToken ( string userAuthToken ) : Task
userAuthToken string
return Task

TurnOffAsync() public method

Send message to HarmonyHub to request to turn off all devices
public TurnOffAsync ( ) : System.Threading.Task
return System.Threading.Task