-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Action for playing url on chromecast
- Loading branch information
Showing
7 changed files
with
374 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using HomeSeerAPI; | ||
using Hspi.Utils; | ||
using NullGuard; | ||
using System; | ||
using System.Collections.Specialized; | ||
using System.Text; | ||
|
||
namespace Hspi.Pages | ||
{ | ||
internal class ActionPage : PageHelper | ||
{ | ||
public ActionPage(IHSApplication HS, PluginConfig pluginConfig) : base(HS, pluginConfig, "Events") | ||
{ | ||
} | ||
|
||
public IPlugInAPI.strMultiReturn GetRefreshActionPostUI([AllowNull] NameValueCollection postData, IPlugInAPI.strTrigActInfo actionInfo) | ||
{ | ||
IPlugInAPI.strMultiReturn result = default; | ||
result.DataOut = actionInfo.DataIn; | ||
result.TrigActInfo = actionInfo; | ||
result.sResult = string.Empty; | ||
if (postData != null && postData.Count > 0) | ||
{ | ||
var action = (actionInfo.DataIn != null) ? | ||
(ChromecastCastAction)ObjectSerialize.DeSerializeFromBytes(actionInfo.DataIn) : | ||
new ChromecastCastAction(); | ||
|
||
foreach (var pair in postData) | ||
{ | ||
string text = Convert.ToString(pair); | ||
if (!string.IsNullOrWhiteSpace(text)) | ||
{ | ||
if (text.StartsWith(nameof(ChromecastCastAction.ChromecastDeviceId))) | ||
{ | ||
action.ChromecastDeviceId = postData[text]; | ||
} | ||
else if (text.StartsWith(nameof(ChromecastCastAction.Url))) | ||
{ | ||
action.Url = postData[text]; | ||
} | ||
else if (text.StartsWith(nameof(ChromecastCastAction.ContentType))) | ||
{ | ||
action.ContentType = postData[text]; | ||
} | ||
else if (text.StartsWith(nameof(ChromecastCastAction.Live))) | ||
{ | ||
action.Live = postData[text] == "checked"; | ||
} | ||
} | ||
} | ||
|
||
if (string.IsNullOrWhiteSpace(action.Url)) | ||
{ | ||
result.sResult += "<BR>Url is not valid"; | ||
} | ||
|
||
if (string.IsNullOrWhiteSpace(action.ChromecastDeviceId)) | ||
{ | ||
result.sResult += "<BR>Chromecast device is not valid"; | ||
} | ||
result.DataOut = ObjectSerialize.SerializeToBytes(action); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public string GetRefreshActionUI(string uniqueControlId, IPlugInAPI.strTrigActInfo actionInfo) | ||
{ | ||
StringBuilder stb = new StringBuilder(); | ||
var action = ObjectSerialize.DeSerializeFromBytes(actionInfo.DataIn) as ChromecastCastAction; | ||
|
||
var chromecastDevices = new NameValueCollection(); | ||
foreach (var device in pluginConfig.Devices) | ||
{ | ||
chromecastDevices.Add(device.Key, device.Value.Name); | ||
} | ||
|
||
stb.Append(FormDropDown(nameof(ChromecastCastAction.ChromecastDeviceId) + uniqueControlId, chromecastDevices, action?.ChromecastDeviceId, 250, string.Empty, false)); | ||
stb.Append("<p> Url:"); | ||
stb.Append(HtmlTextBox(nameof(ChromecastCastAction.Url) + uniqueControlId, action?.Url, 100)); | ||
stb.Append("</p><p> Content mime type:"); | ||
stb.Append(HtmlTextBox(nameof(ChromecastCastAction.ContentType) + uniqueControlId, action?.ContentType, 50)); | ||
stb.Append("</p><p> Live:"); | ||
stb.Append(FormCheckBox(nameof(ChromecastCastAction.Live) + uniqueControlId, string.Empty, action?.Live ?? false)); | ||
stb.Append("</p>"); | ||
stb.Append(FormPageButton(SaveButtonName + uniqueControlId, "Save")); | ||
return stb.ToString(); | ||
} | ||
|
||
private NameValueCollection CreateNameValueCreation<T>() where T : Enum | ||
{ | ||
var collection = new NameValueCollection(); | ||
|
||
foreach (var value in EnumUtil.GetValues<T>()) | ||
{ | ||
collection.Add(value.ToString(), value.ToString()); | ||
} | ||
|
||
return collection; | ||
} | ||
|
||
private const string SaveButtonName = "SaveButton"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
|
||
namespace Hspi.Pages | ||
{ | ||
[Serializable] | ||
internal sealed class ChromecastCastAction | ||
{ | ||
public string ChromecastDeviceId = null; | ||
public string Url = null; | ||
public string ContentType = null; | ||
public bool Live = false; | ||
|
||
public bool IsValid() | ||
{ | ||
return !string.IsNullOrWhiteSpace(ChromecastDeviceId) && | ||
!string.IsNullOrWhiteSpace(Url); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.