/// <summary> /// Called by HomeSeer when it needs to determine if a specific action is completely configured /// or requires additional configuration before it can be used. /// </summary> /// <param name="actInfo">The action to check</param> /// <returns> /// TRUE if the action is completely configured, /// FALSE if it is not. A call to <see cref="OnGetActionUi"/> will be called following this if FALSE is returned. /// </returns> public bool IsActionConfigured(TrigActInfo actInfo) { try { var curAct = GetObjectFromActInfo(actInfo); return(curAct.IsFullyConfigured()); } catch (Exception exception) { if (LogDebug) { Console.WriteLine(exception); } return(true); } }
/// <summary> /// Called by HomeSeer when it needs to determine if a specific device/feature is referenced by a /// particular action. /// </summary> /// <param name="devOrFeatRef">The unique <see cref="AbstractHsDevice.Ref"/> of the device/feature</param> /// <param name="actInfo">The action to check</param> /// <returns> /// TRUE if the action references the specified device/feature, /// FALSE if it does not. /// </returns> public bool ActionReferencesDeviceOrFeature(int devOrFeatRef, TrigActInfo actInfo) { try { var curAct = GetObjectFromActInfo(actInfo); return(curAct.ReferencesDeviceOrFeature(devOrFeatRef)); } catch (Exception exception) { if (LogDebug) { Console.WriteLine(exception); } return(false); } }
/// <summary> /// Called by HomeSeer when it needs to get an easy to read, formatted string that communicates what /// the action does to the user. /// </summary> /// <param name="actInfo">The action that a pretty string is needed for</param> /// <returns> /// HTML formatted text communicating what the action does /// </returns> public string OnGetActionPrettyString(TrigActInfo actInfo) { try { var curAct = GetObjectFromActInfo(actInfo); return(curAct.GetPrettyString()); } catch (Exception exception) { if (LogDebug) { Console.WriteLine(exception); } return(exception.Message); } }
private AbstractTriggerType GetObjectFromTrigInfo(TrigActInfo trigInfo) { //trigInfo.UID, trigInfo.evRef, trigInfo.SubTANumber-1, trigInfo.DataIn ?? new byte[0], _listener, LogDebug if (TypeHasConstructor(trigInfo.TANumber - 1, 0)) { return(GetObjectFromInfo(trigInfo.TANumber - 1, 0, trigInfo.UID, trigInfo.evRef, trigInfo.SubTANumber - 1, trigInfo.DataIn ?? new byte[0], _listener, LogDebug)); } //trigInfo.UID, trigInfo.evRef, trigInfo.SubTANumber-1, trigInfo.DataIn ?? new byte[0], _listener if (TypeHasConstructor(trigInfo.TANumber - 1, 1)) { return(GetObjectFromInfo(trigInfo.TANumber - 1, 1, trigInfo.UID, trigInfo.evRef, trigInfo.SubTANumber - 1, trigInfo.DataIn ?? new byte[0], _listener)); } throw new TypeLoadException("Trigger instance cannot be created because no constructor was found that takes TrigActInfo data"); }
/// <summary> /// Called by HomeSeer when it needs to determine if a specific device/feature is referenced by a /// particular trigger. /// </summary> /// <param name="devOrFeatRef">The unique <see cref="AbstractHsDevice.Ref"/> of the device/feature</param> /// <param name="trigInfo">The trigger to check</param> /// <returns> /// TRUE if the trigger references the specified device/feature, /// FALSE if it does not. /// </returns> public bool TriggerReferencesDeviceOrFeature(int devOrFeatRef, TrigActInfo trigInfo) { try { var curTrig = GetObjectFromTrigInfo(trigInfo); return(curTrig.ReferencesDeviceOrFeature(devOrFeatRef)); } catch (Exception exception) { if (LogDebug) { Console.WriteLine(exception); } return(false); } }
/// <summary> /// Called by HomeSeer when an event has been triggered and a corresponding action needs to be processed. /// </summary> /// <param name="actInfo">The action that is being executed</param> /// <returns> /// TRUE if the action executed successfully, /// FALSE if there was an error executing the action. /// </returns> public bool HandleAction(TrigActInfo actInfo) { try { var curAct = GetObjectFromActInfo(actInfo); //curAct = _listener?.BeforeRunAction(curAct) ?? curAct; return(curAct.OnRunAction()); } catch (Exception exception) { if (LogDebug) { Console.WriteLine(exception); } return(false); } }
/// <summary> /// Called by HomeSeer when it needs to display the configuration UI for an action type /// </summary> /// <param name="actInfo">The action to display as defined by <see cref="TrigActInfo"/></param> /// <returns>HTML to display on the event page for the specified action</returns> public string OnGetActionUi(TrigActInfo actInfo) { try { var curAct = GetObjectFromActInfo(actInfo); //curAct = _listener?.OnBuildActionUi(curAct) ?? curAct; return(curAct.ToHtml()); } catch (Exception exception) { if (LogDebug) { Console.WriteLine(exception); } return(exception.Message); } }
/// <summary> /// Called by HomeSeer to determine if a trigger's conditions have been met. /// </summary> /// <param name="trigInfo">The trigger to check</param> /// <param name="isCondition">TRUE if the trigger is paired with other triggers, FALSE if it is alone.</param> /// <returns> /// TRUE if the trigger's conditions have been met, /// FALSE if they haven't /// </returns> public bool IsTriggerTrue(TrigActInfo trigInfo, bool isCondition) { try { var curTrig = GetObjectFromTrigInfo(trigInfo); //curTrig = _listener?.BeforeCheckTrigger(curTrig) ?? curTrig; return(curTrig.IsTriggerTrue(isCondition)); } catch (Exception exception) { if (LogDebug) { Console.WriteLine(exception); } return(false); } }
/// <summary> /// Called by HomeSeer when it needs to display the configuration UI for a trigger type /// </summary> /// <param name="trigInfo">The trigger to display as defined by <see cref="TrigActInfo"/></param> /// <returns>HTML to display on the event page for the specified trigger</returns> public string OnGetTriggerUi(TrigActInfo trigInfo) { try { var curTrig = GetObjectFromTrigInfo(trigInfo); //curTrig = _listener?.OnBuildTriggerUi(curTrig) ?? curTrig; return(curTrig.ToHtml()); } catch (Exception exception) { if (LogDebug) { Console.WriteLine(exception); } return(exception.Message); } }
/// <summary> /// Called by HomeSeer when a user updates the configuration of an action and those changes /// are in need of processing. /// </summary> /// <param name="postData">A <see cref="Dictionary"/> of changes to the action configuration</param> /// <param name="actInfo">The action being configured</param> /// <returns> /// An <see cref="EventUpdateReturnData"/> describing the new state of the action that will be saved by HomeSeer. /// The action configuration will be saved if the result returned is an empty string. /// </returns> public EventUpdateReturnData OnUpdateActionConfig(Dictionary <string, string> postData, TrigActInfo actInfo) { var eurd = new EventUpdateReturnData { Result = "", TrigActInfo = actInfo }; try { var curAct = GetObjectFromActInfo(actInfo); var result = curAct.ProcessPostData(postData); //curAct = _listener?.OnActionConfigChange(curAct) ?? curAct; eurd.Result = result ? "" : "Unknown Plugin Error"; eurd.DataOut = curAct.Data; return(eurd); } catch (Exception exception) { if (LogDebug) { Console.WriteLine(exception); } eurd.Result = exception.Message; return(eurd); } }
/// <summary> /// Called by HomeSeer when a user updates the configuration of a trigger and those changes /// are in need of processing. /// </summary> /// <param name="postData">A <see cref="Dictionary"/> of changes to the trigger configuration</param> /// <param name="trigInfo">The trigger being configured</param> /// <returns> /// An <see cref="EventUpdateReturnData"/> describing the new state of the trigger that will be saved by HomeSeer. /// The trigger configuration will be saved if the result returned is an empty string. /// </returns> public EventUpdateReturnData OnUpdateTriggerConfig(Dictionary <string, string> postData, TrigActInfo trigInfo) { var mr = new EventUpdateReturnData { Result = "", TrigActInfo = trigInfo }; try { var curTrig = GetObjectFromTrigInfo(trigInfo); var result = curTrig.ProcessPostData(postData); //curTrig = _listener?.OnTriggerConfigChange(curTrig) ?? curTrig; mr.Result = result ? "" : "Unknown Plugin Error"; mr.DataOut = curTrig.Data; return(mr); } catch (Exception exception) { if (LogDebug) { Console.WriteLine(exception); } mr.Result = exception.Message; return(mr); } }