This repository has been archived by the owner on Jul 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
61 additions
and
52 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
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,56 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
using System.Windows.Input; | ||
using WinHue3.Philips_Hue.HueObjects.LightObject; | ||
using Action = WinHue3.Philips_Hue.HueObjects.GroupObject.Action; | ||
|
||
namespace WinHue3.Functions.HotKeys | ||
{ | ||
public class HotkeyConverter : JsonConverter | ||
{ | ||
public override bool CanWrite { get { return false; } } | ||
|
||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | ||
{ | ||
// NOT USED. | ||
|
||
} | ||
|
||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | ||
{ | ||
HotKey hk = new HotKey(); | ||
JObject obj = serializer.Deserialize<JObject>(reader); | ||
hk.Description = obj["Description"]?.Value<string>(); | ||
hk.Name = obj["Name"]?.Value<string>(); | ||
hk.Key = obj["Key"].ToObject<Key>(); | ||
hk.Modifier = obj["Modifier"].ToObject<ModifierKeys>(); | ||
hk.id = obj["id"]?.Value<string>(); | ||
hk.objecType = obj["objecType"]?.ToObject<Type>(); | ||
hk.ProgramPath = obj["ProgramPath"]?.Value<string>(); | ||
|
||
if (obj["properties"] == null) return hk; | ||
switch (hk.objecType?.Name) | ||
{ | ||
case "Light": | ||
hk.properties = obj["properties"].ToObject<State>(); | ||
break; | ||
case "Group": | ||
hk.properties = obj["properties"].ToObject<Action>(); | ||
break; | ||
case "Scene": | ||
hk.properties = obj["properties"].ToObject<Action>(); | ||
break; | ||
default: | ||
break; | ||
|
||
} | ||
return hk; | ||
} | ||
|
||
public override bool CanConvert(Type objectType) | ||
{ | ||
return objectType == typeof(HotKey); | ||
} | ||
} | ||
} |
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
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