Skip to content

Commit

Permalink
Genemars patch 1 (#414)
Browse files Browse the repository at this point in the history
Fixes #413
  • Loading branch information
genemars authored Jun 23, 2020
1 parent ca5fea8 commit 1d95ce0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 4 additions & 5 deletions HomeGenie/Automation/ProgramDynamicApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public static void UnRegister(string request)

public static object TryApiCall(MigInterfaceCommand command)
{
object response = "";
// Dynamic Interface API
var registeredApi = command.Domain + "/" + command.Address + "/" + command.Command;
var handler = Find(registeredApi);
Expand All @@ -84,7 +83,7 @@ public static object TryApiCall(MigInterfaceCommand command)
// explicit command API handlers registered in the form <domain>/<address>/<command>
// receives only the remaining part of the request after the <command>
var args = command.OriginalRequest.Substring(registeredApi.Length).Trim('/');
response = handler(args);
return handler(args);
}
else
{
Expand All @@ -95,17 +94,17 @@ public static object TryApiCall(MigInterfaceCommand command)
if (command.Data == null || (command.Data is byte[] && (command.Data as byte[]).Length == 0))
{
// receives the full request as string if there is no `request.Data` payload
handler(command.OriginalRequest.Trim('/'));
return handler(command.OriginalRequest.Trim('/'));
}
else
{
// receives the original MigInterfaceCommand if `request.Data` actually holds some data
// TODO: this might be be the only entry point in future releases (line #98 and #87 cases will be deprecated)
handler(command);
return handler(command);
}
}
}
return response;
return null;
}

}
Expand Down
12 changes: 7 additions & 5 deletions HomeGenie/Service/HomeGenieService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public object InterfaceControl(MigInterfaceCommand cmd)
//
// Route command to Automation Programs' Dynamic API
var r = ProgramDynamicApi.TryApiCall(cmd);
if (r != null && !String.IsNullOrWhiteSpace(r.ToString()))
if (r != null)
{
// Automation Programs can eventually override MIG response
response = r;
Expand Down Expand Up @@ -633,10 +633,12 @@ private void migService_ServiceRequestPostProcess(object sender, ProcessRequestE
systemConfiguration.Update();
}

// Let automation programs process the request; we append eventual POST data (RequestText) to the MigInterfaceCommand
if (!String.IsNullOrWhiteSpace(args.Request.RequestText))
command = new MigInterfaceCommand(command.OriginalRequest, args.Request.RequestData);
args.Request.ResponseData = ProgramDynamicApi.TryApiCall(command);
// Let automation programs process this request too
var response = ProgramDynamicApi.TryApiCall(command);
if (response != null)
{
args.Request.ResponseData = response;
}

// Macro Recording
if (masterControlProgram != null && masterControlProgram.MacroRecorder.IsRecordingEnabled && command != null && command.Command != null && (command.Command.StartsWith("Control.") || (command.Command.StartsWith("AvMedia.") && command.Command != "AvMedia.Browse" && command.Command != "AvMedia.GetUri")))
Expand Down

0 comments on commit 1d95ce0

Please sign in to comment.