70 lines
2.0 KiB
C#
70 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using BlubbFish.IoT.Hue.Interfaces;
|
|
using BlubbFish.IoT.Hue.lib;
|
|
using LitJson;
|
|
|
|
namespace BlubbFish.IoT.Hue.Devices.Scenes {
|
|
public class LightState : AConnector {
|
|
public override event UpdatedValue Update;
|
|
|
|
#region Properties
|
|
private Boolean _state;
|
|
public Boolean State {
|
|
get {
|
|
return this._state;
|
|
}
|
|
set {
|
|
this.SetLightScene(new Dictionary<String, Object>() { { "on", value } });
|
|
}
|
|
}
|
|
private Byte _brightness;
|
|
public Byte Brightness {
|
|
get {
|
|
return this._brightness;
|
|
}
|
|
set {
|
|
this.SetLightScene(new Dictionary<String, Object>() { { "bri", value } });
|
|
}
|
|
}
|
|
public String SceneId { get; }
|
|
public Int32 LightStateId { get; }
|
|
#endregion
|
|
|
|
#region Constructor
|
|
public LightState(JsonData json, Tuple<String, Int32> id, HttpConnection http) {
|
|
this.http = http;
|
|
this.SceneId = id.Item1;
|
|
this.LightStateId = id.Item2;
|
|
this.ComplexInit(json);
|
|
}
|
|
|
|
private void ComplexInit(JsonData json) {
|
|
if (json.ContainsKey("on") && json["on"].IsBoolean) {
|
|
this._state = (Boolean)json["on"];
|
|
}
|
|
if (json.ContainsKey("bri") && json["bri"].IsInt) {
|
|
this._brightness = (Byte)json["bri"];
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
private void SetLightScene(Dictionary<String, Object> value) {
|
|
this.PutDictionary("scenes/" + this.SceneId + "/lights/" + this.LightStateId + "/state", value);
|
|
}
|
|
|
|
#region AConnector
|
|
public override Dictionary<String, Object> ToDictionary() {
|
|
return new Dictionary<String, Object> {
|
|
{ "State", this.State.ToString() },
|
|
{ "Brightness", this.Brightness }
|
|
};
|
|
}
|
|
|
|
public override String ToString() {
|
|
return "Scene LightState " + this.SceneId + " [" + this.LightStateId + "]: On-" + this.State.ToString() + " Bri-" + this.Brightness;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|