[NF] Hue-Lib fertig
[DW] Hue-Bot beginn Arbeit
This commit is contained in:
parent
62c3c5815c
commit
4178079f4d
368
Hue/Devices/Configs/Config.cs
Normal file
368
Hue/Devices/Configs/Config.cs
Normal file
@ -0,0 +1,368 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using BlubbFish.IoT.Hue.Events;
|
||||
using BlubbFish.IoT.Hue.Interfaces;
|
||||
using BlubbFish.IoT.Hue.lib;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Hue.Devices.Configs {
|
||||
public class Config : AConfig {
|
||||
#region Properties
|
||||
private String _name;
|
||||
public String Name {
|
||||
get {
|
||||
return this._name;
|
||||
}
|
||||
set {
|
||||
if(this.SetConfig(new Dictionary<String, Object>() { { "name", value } })) {
|
||||
this._name = value;
|
||||
this.NotifyClient<ConfigUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
private Boolean _linkbutton;
|
||||
public Boolean Linkbutton {
|
||||
get {
|
||||
return this._linkbutton;
|
||||
}
|
||||
set {
|
||||
if (this.SetConfig(new Dictionary<String, Object>() { { "linkbutton", value } })) {
|
||||
this._linkbutton = value;
|
||||
this.NotifyClient<ConfigUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
private String _ipaddress;
|
||||
public String Ipaddress {
|
||||
get {
|
||||
return this._ipaddress;
|
||||
}
|
||||
set {
|
||||
if (this.SetConfig(new Dictionary<String, Object>() { { "ipaddress", value } })) {
|
||||
this._ipaddress = value;
|
||||
this.NotifyClient<ConfigUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
private String _netmask;
|
||||
public String Netmask {
|
||||
get {
|
||||
return this._netmask;
|
||||
}
|
||||
set {
|
||||
if (this.SetConfig(new Dictionary<String, Object>() { { "netmask", value } })) {
|
||||
this._netmask = value;
|
||||
this.NotifyClient<ConfigUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
private String _gateway;
|
||||
public String Gateway {
|
||||
get {
|
||||
return this._gateway;
|
||||
}
|
||||
set {
|
||||
if (this.SetConfig(new Dictionary<String, Object>() { { "gateway", value } })) {
|
||||
this._gateway = value;
|
||||
this.NotifyClient<ConfigUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
private Boolean _dhcp;
|
||||
public Boolean Dhcp {
|
||||
get {
|
||||
return this._dhcp;
|
||||
}
|
||||
set {
|
||||
if (this.SetConfig(new Dictionary<String, Object>() { { "dhcp", value } })) {
|
||||
this._dhcp = value;
|
||||
this.NotifyClient<ConfigUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
private DateTime _utc;
|
||||
public DateTime Utc {
|
||||
get {
|
||||
return this._utc;
|
||||
}
|
||||
set {
|
||||
if (this.SetConfig(new Dictionary<String, Object>() { { "UTC", value } })) {
|
||||
this._utc = value;
|
||||
this.NotifyClient<ConfigUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
private String _timezone;
|
||||
public String Timezone {
|
||||
get {
|
||||
return this._timezone;
|
||||
}
|
||||
set {
|
||||
if (this.SetConfig(new Dictionary<String, Object>() { { "timezone", value } })) {
|
||||
this._timezone = value;
|
||||
this.NotifyClient<ConfigUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
private Byte _zigbeechannel;
|
||||
public Byte Zigbeechannel {
|
||||
get {
|
||||
return this._zigbeechannel;
|
||||
}
|
||||
set {
|
||||
if (this.SetConfig(new Dictionary<String, Object>() { { "zigbeechannel", value } })) {
|
||||
this._zigbeechannel = value;
|
||||
this.NotifyClient<ConfigUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public String Apiversion { get; private set; }
|
||||
public String Swversion { get; private set; }
|
||||
public String Mac { get; private set; }
|
||||
public Boolean Portalservices { get; private set; }
|
||||
public DateTime Localtime { get; private set; }
|
||||
public String Modelid { get; private set; }
|
||||
public String Bridgeid { get; private set; }
|
||||
public String Replacesbridgeid { get; private set; }
|
||||
public Boolean Factorynew { get; private set; }
|
||||
public String Datastoreversion { get; private set; }
|
||||
public String Starterkitid { get; private set; }
|
||||
public SwUpdate SwUpdate2 { get; private set; }
|
||||
public Portalstate Portalstate { get; private set; }
|
||||
public ReadOnlyDictionary<String, Whitelist> Whitelist { get; private set; }
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public Config(JsonData json, HttpConnection http, Boolean polling) : base(json, http, polling) {
|
||||
this.ComplexInit(json);
|
||||
}
|
||||
|
||||
private void ComplexInit(JsonData json) {
|
||||
if (json.ContainsKey("name") && json["name"].IsString) {
|
||||
this._name = json["name"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("apiversion") && json["apiversion"].IsString) {
|
||||
this.Apiversion = json["apiversion"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("swversion") && json["swversion"].IsString) {
|
||||
this.Swversion = json["swversion"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("linkbutton") && json["linkbutton"].IsBoolean) {
|
||||
this._linkbutton = (Boolean)json["linkbutton"];
|
||||
}
|
||||
if (json.ContainsKey("ipaddress") && json["ipaddress"].IsString) {
|
||||
this._ipaddress = json["ipaddress"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("mac") && json["mac"].IsString) {
|
||||
this.Mac = json["mac"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("netmask") && json["netmask"].IsString) {
|
||||
this._netmask = json["netmask"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("gateway") && json["gateway"].IsString) {
|
||||
this._gateway = json["gateway"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("dhcp") && json["dhcp"].IsBoolean) {
|
||||
this._dhcp = (Boolean)json["dhcp"];
|
||||
}
|
||||
if (json.ContainsKey("portalservices") && json["portalservices"].IsBoolean) {
|
||||
this.Portalservices = (Boolean)json["portalservices"];
|
||||
}
|
||||
if (json.ContainsKey("UTC") && json["UTC"].IsString) {
|
||||
this._utc = DateTime.Parse(json["UTC"].ToString());
|
||||
}
|
||||
if (json.ContainsKey("localtime") && json["localtime"].IsString) {
|
||||
this.Localtime = DateTime.Parse(json["localtime"].ToString());
|
||||
}
|
||||
if (json.ContainsKey("timezone") && json["timezone"].IsString) {
|
||||
this._timezone = json["timezone"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("zigbeechannel") && json["zigbeechannel"].IsInt) {
|
||||
this._zigbeechannel = (Byte)json["zigbeechannel"];
|
||||
}
|
||||
if (json.ContainsKey("modelid") && json["modelid"].IsString) {
|
||||
this.Modelid = json["modelid"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("bridgeid") && json["bridgeid"].IsString) {
|
||||
this.Bridgeid = json["bridgeid"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("replacesbridgeid") && json["replacesbridgeid"] != null && json["replacesbridgeid"].IsString) {
|
||||
this.Replacesbridgeid = json["replacesbridgeid"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("factorynew") && json["factorynew"].IsBoolean) {
|
||||
this.Factorynew = (Boolean)json["factorynew"];
|
||||
}
|
||||
if (json.ContainsKey("datastoreversion") && json["datastoreversion"].IsString) {
|
||||
this.Datastoreversion = json["datastoreversion"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("starterkitid") && json["starterkitid"].IsString) {
|
||||
this.Starterkitid = json["starterkitid"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("swupdate2") && json["swupdate2"].IsObject) {
|
||||
this.SwUpdate2 = new SwUpdate(json["swupdate2"], this.http, this.Polling);
|
||||
this.SwUpdate2.Update += this.NotifyClientChildren;
|
||||
}
|
||||
if (json.ContainsKey("whitelist") && json["whitelist"].IsObject) {
|
||||
this.CreateWhitelist(json["whitelist"]);
|
||||
}
|
||||
if (json.ContainsKey("portalstate") && json["portalstate"].IsObject) {
|
||||
this.Portalstate = new Portalstate(json["portalstate"], this.http, this.Polling);
|
||||
this.Portalstate.Update += this.NotifyClientChildren;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateWhitelist(JsonData json) {
|
||||
Dictionary<String, Whitelist> whitelists = new Dictionary<String, Whitelist>();
|
||||
foreach (String item in json.Keys) {
|
||||
Whitelist w = new Whitelist(json[item], new Tuple<String>(item), this.http, this.Polling);
|
||||
w.Update += this.NotifyClientChildren;
|
||||
whitelists.Add(item, w);
|
||||
}
|
||||
this.Whitelist = new ReadOnlyDictionary<String, Whitelist>(whitelists);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AConnector
|
||||
public override String ToString() {
|
||||
return "Config: " + this.Name + " Ip-" + this.Ipaddress + " DHCP-" + this.Dhcp + " Time-" + this.Localtime + " User-" + this.Whitelist.Count;
|
||||
}
|
||||
|
||||
public override void SetUpdate(JsonData json) {
|
||||
if (json.ContainsKey("name") && json["name"].IsString) {
|
||||
if (this.Name != json["name"].ToString()) {
|
||||
this._name = json["name"].ToString();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Name);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("apiversion") && json["apiversion"].IsString) {
|
||||
if (this.Apiversion != json["apiversion"].ToString()) {
|
||||
this.Apiversion = json["apiversion"].ToString();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Apiversion);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("swversion") && json["swversion"].IsString) {
|
||||
if (this.Swversion != json["swversion"].ToString()) {
|
||||
this.Swversion = json["swversion"].ToString();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Swversion);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("linkbutton") && json["linkbutton"].IsBoolean) {
|
||||
if (this.Linkbutton != (Boolean)json["linkbutton"]) {
|
||||
this._linkbutton = (Boolean)json["linkbutton"];
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Linkbutton);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("ipaddress") && json["ipaddress"].IsString) {
|
||||
if (this.Ipaddress != json["ipaddress"].ToString()) {
|
||||
this._ipaddress = json["ipaddress"].ToString();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Ipaddress);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("mac") && json["mac"].IsString) {
|
||||
if (this.Mac != json["mac"].ToString()) {
|
||||
this.Mac = json["mac"].ToString();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Mac);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("netmask") && json["netmask"].IsString) {
|
||||
if (this.Netmask != json["netmask"].ToString()) {
|
||||
this._netmask = json["netmask"].ToString();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Netmask);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("gateway") && json["gateway"].IsString) {
|
||||
if (this.Gateway != json["gateway"].ToString()) {
|
||||
this._gateway = json["gateway"].ToString();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Gateway);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("dhcp") && json["dhcp"].IsBoolean) {
|
||||
if (this.Dhcp != (Boolean)json["dhcp"]) {
|
||||
this._dhcp = (Boolean)json["dhcp"];
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Dhcp);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("portalservices") && json["portalservices"].IsBoolean) {
|
||||
if (this.Portalservices != (Boolean)json["portalservices"]) {
|
||||
this.Portalservices = (Boolean)json["portalservices"];
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Portalservices);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("UTC") && json["UTC"].IsString) {
|
||||
if (this.Utc != DateTime.Parse(json["UTC"].ToString())) {
|
||||
this._utc = DateTime.Parse(json["UTC"].ToString());
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Utc);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("localtime") && json["localtime"].IsString) {
|
||||
if (this.Localtime != DateTime.Parse(json["localtime"].ToString())) {
|
||||
this.Localtime = DateTime.Parse(json["localtime"].ToString());
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Localtime);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("timezone") && json["timezone"].IsString) {
|
||||
if (this.Timezone != json["timezone"].ToString()) {
|
||||
this._timezone = json["timezone"].ToString();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Timezone);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("zigbeechannel") && json["zigbeechannel"].IsInt) {
|
||||
if (this.Zigbeechannel != (Byte)json["zigbeechannel"]) {
|
||||
this._zigbeechannel = (Byte)json["zigbeechannel"];
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Zigbeechannel);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("modelid") && json["modelid"].IsString) {
|
||||
if (this.Modelid != json["modelid"].ToString()) {
|
||||
this.Modelid = json["modelid"].ToString();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Modelid);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("bridgeid") && json["bridgeid"].IsString) {
|
||||
if (this.Bridgeid != json["bridgeid"].ToString()) {
|
||||
this.Bridgeid = json["bridgeid"].ToString();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Bridgeid);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("replacesbridgeid") && json["replacesbridgeid"] != null && json["replacesbridgeid"].IsString) {
|
||||
if (this.Replacesbridgeid != json["replacesbridgeid"].ToString()) {
|
||||
this.Replacesbridgeid = json["replacesbridgeid"].ToString();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Replacesbridgeid);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("factorynew") && json["factorynew"].IsBoolean) {
|
||||
if (this.Factorynew != (Boolean)json["factorynew"]) {
|
||||
this.Factorynew = (Boolean)json["factorynew"];
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Factorynew);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("datastoreversion") && json["datastoreversion"].IsString) {
|
||||
if (this.Datastoreversion != json["datastoreversion"].ToString()) {
|
||||
this.Datastoreversion = json["datastoreversion"].ToString();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Datastoreversion);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("starterkitid") && json["starterkitid"].IsString) {
|
||||
if (this.Starterkitid != json["starterkitid"].ToString()) {
|
||||
this.Starterkitid = json["starterkitid"].ToString();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Starterkitid);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("swupdate2") && json["swupdate2"].IsObject) {
|
||||
this.SwUpdate2?.SetUpdate(json["swupdate2"]);
|
||||
}
|
||||
if (json.ContainsKey("whitelist") && json["whitelist"].IsObject) {
|
||||
foreach (String item in json["whitelist"].Keys) {
|
||||
if(this.Whitelist.ContainsKey(item)) {
|
||||
this.Whitelist[item].SetUpdate(json["whitelist"][item]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("portalstate") && json["portalstate"].IsObject) {
|
||||
this.Portalstate?.SetUpdate(json["portalstate"]);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
71
Hue/Devices/Configs/Portalstate.cs
Normal file
71
Hue/Devices/Configs/Portalstate.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using BlubbFish.IoT.Hue.Events;
|
||||
using BlubbFish.IoT.Hue.Interfaces;
|
||||
using BlubbFish.IoT.Hue.lib;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Hue.Devices.Configs {
|
||||
public class Portalstate : AConfig {
|
||||
|
||||
#region Properties
|
||||
public Boolean Signedon { get; private set; }
|
||||
public Boolean Incoming { get; private set; }
|
||||
public Boolean Outgoing { get; private set; }
|
||||
public String Communication { get; private set; }
|
||||
#endregion
|
||||
|
||||
#region Constrctor
|
||||
public Portalstate(JsonData json, HttpConnection http, Boolean polling) : base(json, http, polling) {
|
||||
this.ComplexInit(json);
|
||||
}
|
||||
|
||||
private void ComplexInit(JsonData json) {
|
||||
if (json.ContainsKey("signedon") && json["signedon"].IsBoolean) {
|
||||
this.Signedon = (Boolean)json["signedon"];
|
||||
}
|
||||
if (json.ContainsKey("incoming") && json["incoming"].IsBoolean) {
|
||||
this.Incoming = (Boolean)json["incoming"];
|
||||
}
|
||||
if (json.ContainsKey("outgoing") && json["outgoing"].IsBoolean) {
|
||||
this.Outgoing = (Boolean)json["outgoing"];
|
||||
}
|
||||
if (json.ContainsKey("communication") && json["communication"].IsString) {
|
||||
this.Communication = json["communication"].ToString();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AConnector
|
||||
public override String ToString() {
|
||||
return "Portalstate: On-" + this.Signedon + " In-" + this.Incoming + " Out-" + this.Outgoing + " Communication-" + this.Communication;
|
||||
}
|
||||
|
||||
public override void SetUpdate(JsonData json) {
|
||||
if (json.ContainsKey("signedon") && json["signedon"].IsBoolean) {
|
||||
if (this.Signedon != (Boolean)json["signedon"]) {
|
||||
this.Signedon = (Boolean)json["signedon"];
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Signedon);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("incoming") && json["incoming"].IsBoolean) {
|
||||
if (this.Incoming != (Boolean)json["incoming"]) {
|
||||
this.Incoming = (Boolean)json["incoming"];
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Incoming);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("outgoing") && json["outgoing"].IsBoolean) {
|
||||
if (this.Outgoing != (Boolean)json["outgoing"]) {
|
||||
this.Outgoing = (Boolean)json["outgoing"];
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Outgoing);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("communication") && json["communication"].IsString) {
|
||||
if (this.Communication != json["communication"].ToString()) {
|
||||
this.Communication = json["communication"].ToString();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Communication);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
108
Hue/Devices/Configs/SwUpdate.cs
Normal file
108
Hue/Devices/Configs/SwUpdate.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BlubbFish.IoT.Hue.Events;
|
||||
using BlubbFish.IoT.Hue.Interfaces;
|
||||
using BlubbFish.IoT.Hue.lib;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Hue.Devices.Configs {
|
||||
public class SwUpdate : AConfig {
|
||||
#region Properties
|
||||
public Boolean Checkforupdate { get; private set; }
|
||||
public DateTime Lastchange { get; private set; }
|
||||
public String Bridgestate { get; private set; }
|
||||
public DateTime Bridgelastinstall { get; private set; }
|
||||
public String State { get; private set; }
|
||||
public String Autoinstallupdatetime { get; private set; }
|
||||
public Boolean Autoinstallon { get; private set; }
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public SwUpdate(JsonData json, HttpConnection http, Boolean polling) : base(json, http, polling) {
|
||||
this.ComplexInit(json);
|
||||
}
|
||||
|
||||
private void ComplexInit(JsonData json) {
|
||||
if(json.ContainsKey("checkforupdate") && json["checkforupdate"].IsBoolean) {
|
||||
this.Checkforupdate = (Boolean)json["checkforupdate"];
|
||||
}
|
||||
if (json.ContainsKey("lastchange") && json["lastchange"].IsString) {
|
||||
this.Lastchange = DateTime.Parse(json["lastchange"].ToString()).ToLocalTime();
|
||||
}
|
||||
if (json.ContainsKey("bridge") && json["bridge"].IsObject) {
|
||||
if (json["bridge"].ContainsKey("state") && json["bridge"]["state"].IsString) {
|
||||
this.Bridgestate = json["bridge"]["state"].ToString();
|
||||
}
|
||||
if (json["bridge"].ContainsKey("lastinstall") && json["bridge"]["lastinstall"].IsString) {
|
||||
this.Bridgelastinstall = DateTime.Parse(json["bridge"]["lastinstall"].ToString()).ToLocalTime();
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("state") && json["state"].IsString) {
|
||||
this.State = json["state"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("autoinstall") && json["autoinstall"].IsObject) {
|
||||
if (json["autoinstall"].ContainsKey("updatetime") && json["autoinstall"]["updatetime"].IsString) {
|
||||
this.Autoinstallupdatetime = json["autoinstall"]["updatetime"].ToString();
|
||||
}
|
||||
if (json["autoinstall"].ContainsKey("on") && json["autoinstall"]["on"].IsBoolean) {
|
||||
this.Autoinstallon = (Boolean)json["autoinstall"]["on"];
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AConnector
|
||||
public override String ToString() {
|
||||
return "Updates: Check-" + this.Checkforupdate + " LatestCheck-" + this.Lastchange + " Updates-" + this.Bridgestate + " Installed-" + this.Bridgelastinstall + " State-" + this.State + " AutoTime-" + this.Autoinstallupdatetime + " AutoOn-" + this.Autoinstallon;
|
||||
}
|
||||
|
||||
public override void SetUpdate(JsonData json) {
|
||||
if (json.ContainsKey("checkforupdate") && json["checkforupdate"].IsBoolean) {
|
||||
if (this.Checkforupdate != (Boolean)json["checkforupdate"]) {
|
||||
this.Checkforupdate = (Boolean)json["checkforupdate"];
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Checkforupdate);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("lastchange") && json["lastchange"].IsString) {
|
||||
if (this.Lastchange != DateTime.Parse(json["lastchange"].ToString()).ToLocalTime()) {
|
||||
this.Lastchange = DateTime.Parse(json["lastchange"].ToString()).ToLocalTime();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Lastchange);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("bridge") && json["bridge"].ContainsKey("state") && json["bridge"]["state"].IsString) {
|
||||
if (this.Bridgestate != json["bridge"]["state"].ToString()) {
|
||||
this.Bridgestate = json["bridge"]["state"].ToString();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Bridgestate);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("bridge") && json["bridge"].ContainsKey("lastinstall") && json["bridge"]["lastinstall"].IsString) {
|
||||
if (this.Bridgelastinstall != DateTime.Parse(json["bridge"]["lastinstall"].ToString()).ToLocalTime()) {
|
||||
this.Bridgelastinstall = DateTime.Parse(json["bridge"]["lastinstall"].ToString()).ToLocalTime();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Bridgelastinstall);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("state") && json["state"].IsString) {
|
||||
if (this.State != json["state"].ToString()) {
|
||||
this.State = json["state"].ToString();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.State);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("autoinstall") && json["autoinstall"].ContainsKey("updatetime") && json["autoinstall"]["updatetime"].IsString) {
|
||||
if (this.Autoinstallupdatetime != json["autoinstall"]["updatetime"].ToString()) {
|
||||
this.Autoinstallupdatetime = json["autoinstall"]["updatetime"].ToString();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Autoinstallupdatetime);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("autoinstall") && json["autoinstall"].ContainsKey("on") && json["autoinstall"]["on"].IsBoolean) {
|
||||
if (this.Autoinstallon != (Boolean)json["autoinstall"]["on"]) {
|
||||
this.Autoinstallon = (Boolean)json["autoinstall"]["on"];
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Autoinstallon);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
62
Hue/Devices/Configs/Whitelist.cs
Normal file
62
Hue/Devices/Configs/Whitelist.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using BlubbFish.IoT.Hue.Events;
|
||||
using BlubbFish.IoT.Hue.Interfaces;
|
||||
using BlubbFish.IoT.Hue.lib;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Hue.Devices.Configs {
|
||||
public class Whitelist : AConfig {
|
||||
#region Properties
|
||||
public DateTime Lastusedate { get; private set; }
|
||||
public DateTime Createdate { get; private set; }
|
||||
public String Name { get; private set; }
|
||||
public String UserId { get; }
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public Whitelist(JsonData json, Tuple<String> id, HttpConnection http, Boolean polling) : base(json, http, polling) {
|
||||
this.UserId = id.Item1;
|
||||
this.ComplexInit(json);
|
||||
}
|
||||
|
||||
private void ComplexInit(JsonData json) {
|
||||
if (json.ContainsKey("last use date") && json["last use date"].IsString) {
|
||||
this.Lastusedate = DateTime.Parse(json["last use date"].ToString()).ToLocalTime();
|
||||
}
|
||||
if (json.ContainsKey("create date") && json["create date"].IsString) {
|
||||
this.Createdate = DateTime.Parse(json["create date"].ToString()).ToLocalTime();
|
||||
}
|
||||
if (json.ContainsKey("name") && json["name"].IsString) {
|
||||
this.Name = json["name"].ToString();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AConnector
|
||||
public override String ToString() {
|
||||
return "User [" + this.UserId + "]: " + this.Name + " (Create-" + this.Createdate + " LastOn-" + this.Lastusedate + ")";
|
||||
}
|
||||
|
||||
public override void SetUpdate(JsonData json) {
|
||||
if (json.ContainsKey("last use date") && json["last use date"].IsString) {
|
||||
if (this.Lastusedate != DateTime.Parse(json["last use date"].ToString()).ToLocalTime()) {
|
||||
this.Lastusedate = DateTime.Parse(json["last use date"].ToString()).ToLocalTime();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Lastusedate);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("create date") && json["create date"].IsString) {
|
||||
if (this.Createdate != DateTime.Parse(json["create date"].ToString()).ToLocalTime()) {
|
||||
this.Createdate = DateTime.Parse(json["create date"].ToString()).ToLocalTime();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Createdate);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("name") && json["name"].IsString) {
|
||||
if (this.Name != json["name"].ToString()) {
|
||||
this.Name = json["name"].ToString();
|
||||
this.NotifyClient<ConfigUpdateEvent>(this.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,28 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using BlubbFish.IoT.Hue.Events;
|
||||
using BlubbFish.IoT.Hue.Interfaces;
|
||||
using BlubbFish.IoT.Hue.lib;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Hue.Devices.Groups {
|
||||
public class Room : AGroup {
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
#region Properties
|
||||
private AlertEffect _alert;
|
||||
public enum AlertEffect {
|
||||
none,
|
||||
select,
|
||||
lselect
|
||||
}
|
||||
|
||||
#region Properties
|
||||
private AlertEffect _alert;
|
||||
|
||||
private Boolean _state;
|
||||
public Boolean State {
|
||||
get {
|
||||
return this._state;
|
||||
}
|
||||
set {
|
||||
this.SetGroupAction(new Dictionary<String, Object>() { { "on", value } });
|
||||
if(this.SetGroupAction(new Dictionary<String, Object>() { { "on", value } })) {
|
||||
this._state = value;
|
||||
this.NotifyClient<GroupUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
private Byte _brightness;
|
||||
@ -31,7 +35,10 @@ namespace BlubbFish.IoT.Hue.Devices.Groups {
|
||||
return this._brightness;
|
||||
}
|
||||
set {
|
||||
this.SetGroupAction(new Dictionary<String, Object>() { { "bri", value } });
|
||||
if(this.SetGroupAction(new Dictionary<String, Object>() { { "bri", value } })) {
|
||||
this._brightness = value;
|
||||
this.NotifyClient<GroupUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public AlertEffect Alert {
|
||||
@ -39,7 +46,10 @@ namespace BlubbFish.IoT.Hue.Devices.Groups {
|
||||
return this._alert;
|
||||
}
|
||||
set {
|
||||
this.SetGroupAction(new Dictionary<String, Object>() { { "alert", value } });
|
||||
if(this.SetGroupAction(new Dictionary<String, Object>() { { "alert", value } })) {
|
||||
this._alert = value;
|
||||
this.NotifyClient<GroupUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@ -66,14 +76,6 @@ namespace BlubbFish.IoT.Hue.Devices.Groups {
|
||||
#endregion
|
||||
|
||||
#region AConnector
|
||||
public override Dictionary<String, Object> ToDictionary() {
|
||||
return new Dictionary<String, Object> {
|
||||
{ "State", this.State },
|
||||
{ "Brightness", this.Brightness },
|
||||
{ "Alert", this.Alert.ToString() }
|
||||
};
|
||||
}
|
||||
|
||||
public override String ToString() {
|
||||
List<String> lid = new List<String>();
|
||||
foreach (KeyValuePair<Int32, ALight> item in this.Lights) {
|
||||
@ -81,6 +83,28 @@ namespace BlubbFish.IoT.Hue.Devices.Groups {
|
||||
}
|
||||
return "Group " + this.Name + " [" + this.GroupId + "]: (Class-"+ Helper.GetEnumDescription(this.Class) + ", ["+String.Join(",",lid.ToArray())+"]) On-" + this.State.ToString() + " Bri-" + this.Brightness + " Alert-" + this.Alert.ToString() + " AllOn-" + this.StateAllOn.ToString() + " AnyOn-" + this.StateAnyOn.ToString();
|
||||
}
|
||||
|
||||
public override void SetUpdate(JsonData json) {
|
||||
base.SetUpdate(json);
|
||||
if (json.ContainsKey("on") && json["on"].IsBoolean) {
|
||||
if (this.State != (Boolean)json["on"]) {
|
||||
this._state = (Boolean)json["on"];
|
||||
this.NotifyClient<GroupUpdateEvent>(this.State);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("bri") && json["bri"].IsInt) {
|
||||
if (this.Brightness != (Byte)json["bri"]) {
|
||||
this._brightness = (Byte)json["bri"];
|
||||
this.NotifyClient<GroupUpdateEvent>(this.Brightness);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("alert") && json["alert"].IsString) {
|
||||
if (this.Alert != (AlertEffect)Enum.Parse(typeof(AlertEffect), json["alert"].ToString())) {
|
||||
this._alert = (AlertEffect)Enum.Parse(typeof(AlertEffect), json["alert"].ToString());
|
||||
this.NotifyClient<GroupUpdateEvent>(this.Alert);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BlubbFish.IoT.Hue.Events;
|
||||
using BlubbFish.IoT.Hue.Interfaces;
|
||||
using BlubbFish.IoT.Hue.lib;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Hue.Devices.Lights {
|
||||
public class Dimmablelight : ALight {
|
||||
public override event UpdatedValue Update;
|
||||
public enum AlertEffect {
|
||||
none,
|
||||
select,
|
||||
@ -20,7 +20,10 @@ namespace BlubbFish.IoT.Hue.Devices.Lights {
|
||||
return this._state;
|
||||
}
|
||||
set {
|
||||
this.SetLightState(new Dictionary<String, Object>() { { "on", value } });
|
||||
if(this.SetLightStateAttribute(new Dictionary<String, Object>() { { "on", value } })) {
|
||||
this._state = value;
|
||||
this.NotifyClient<LightUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
private Byte _brightness;
|
||||
@ -29,7 +32,10 @@ namespace BlubbFish.IoT.Hue.Devices.Lights {
|
||||
return this._brightness;
|
||||
}
|
||||
set {
|
||||
this.SetLightState(new Dictionary<String, Object>() { { "bri", value } });
|
||||
if(this.SetLightStateAttribute(new Dictionary<String, Object>() { { "bri", value } })) {
|
||||
this._brightness = value;
|
||||
this.NotifyClient<LightUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
private AlertEffect _alert;
|
||||
@ -38,7 +44,10 @@ namespace BlubbFish.IoT.Hue.Devices.Lights {
|
||||
return this._alert;
|
||||
}
|
||||
set {
|
||||
this.SetLightState(new Dictionary<String, Object>() { { "alert", value } });
|
||||
if(this.SetLightStateAttribute(new Dictionary<String, Object>() { { "alert", value } })) {
|
||||
this._alert = value;
|
||||
this.NotifyClient<LightUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public Boolean Reachable { get; private set; }
|
||||
@ -72,14 +81,32 @@ namespace BlubbFish.IoT.Hue.Devices.Lights {
|
||||
public override String ToString() {
|
||||
return "Light " + this.Name + " [" + this.LightId + "]: On-" + this.State.ToString() + " Bri-" + this.Brightness + " Alert-" + this.Alert.ToString() + " Reachable-" + this.Reachable.ToString();
|
||||
}
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() {
|
||||
return new Dictionary<String, Object> {
|
||||
{ "State", this.State },
|
||||
{ "Brightness", this.Brightness },
|
||||
{ "Alert", this.Alert.ToString() },
|
||||
{ "Reachable", this.Reachable }
|
||||
};
|
||||
public override void SetUpdate(JsonData json) {
|
||||
base.SetUpdate(json);
|
||||
if (json.ContainsKey("state") && json["state"].ContainsKey("on") && json["state"]["on"].IsBoolean) {
|
||||
if (this.State != (Boolean)json["state"]["on"]) {
|
||||
this._state = (Boolean)json["state"]["on"];
|
||||
this.NotifyClient<LightUpdateEvent>(this.State);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("state") && json["state"].ContainsKey("bri") && json["state"]["bri"].IsInt) {
|
||||
if (this.Brightness != (Byte)json["state"]["bri"]) {
|
||||
this._brightness = (Byte)json["state"]["bri"];
|
||||
this.NotifyClient<LightUpdateEvent>(this.Brightness);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("state") && json["state"].ContainsKey("alert") && json["state"]["alert"].IsString) {
|
||||
if (this.Alert != (AlertEffect)Enum.Parse(typeof(AlertEffect), json["state"]["alert"].ToString())) {
|
||||
this._alert = (AlertEffect)Enum.Parse(typeof(AlertEffect), json["state"]["alert"].ToString());
|
||||
this.NotifyClient<LightUpdateEvent>(this.Alert);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("state") && json["state"].ContainsKey("reachable") && json["state"]["reachable"].IsBoolean) {
|
||||
if (this.Reachable != (Boolean)json["state"]["reachable"]) {
|
||||
this.Reachable = (Boolean)json["state"]["reachable"];
|
||||
this.NotifyClient<LightUpdateEvent>(this.Reachable);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using BlubbFish.IoT.Hue.Events;
|
||||
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;
|
||||
|
||||
public class LightState : AScene {
|
||||
#region Properties
|
||||
private Boolean _state;
|
||||
public Boolean State {
|
||||
@ -15,7 +15,10 @@ namespace BlubbFish.IoT.Hue.Devices.Scenes {
|
||||
return this._state;
|
||||
}
|
||||
set {
|
||||
this.SetLightScene(new Dictionary<String, Object>() { { "on", value } });
|
||||
if (this.SetLightSceneAttribute(new Dictionary<String, Object>() { { "on", value } })) {
|
||||
this._state = value;
|
||||
this.NotifyClient<SceneUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
private Byte _brightness;
|
||||
@ -24,18 +27,16 @@ namespace BlubbFish.IoT.Hue.Devices.Scenes {
|
||||
return this._brightness;
|
||||
}
|
||||
set {
|
||||
this.SetLightScene(new Dictionary<String, Object>() { { "bri", value } });
|
||||
if(this.SetLightSceneAttribute(new Dictionary<String, Object>() { { "bri", value } })) {
|
||||
this._brightness = value;
|
||||
this.NotifyClient<SceneUpdateEvent>(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;
|
||||
public LightState(JsonData json, Tuple<String, Int32> id, HttpConnection http, Boolean polling, ReadOnlyDictionary<Int32, ALight> lights) : base(json, id, http, polling, lights){
|
||||
this.ComplexInit(json);
|
||||
}
|
||||
|
||||
@ -49,21 +50,25 @@ namespace BlubbFish.IoT.Hue.Devices.Scenes {
|
||||
}
|
||||
#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;
|
||||
}
|
||||
|
||||
public override void SetUpdate(JsonData json) {
|
||||
if (json.ContainsKey("on") && json["on"].IsBoolean) {
|
||||
if (this.State != (Boolean)json["on"]) {
|
||||
this._state = (Boolean)json["on"];
|
||||
this.NotifyClient<SceneUpdateEvent>(this.State);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("bri") && json["bri"].IsInt) {
|
||||
if (this.Brightness != (Byte)json["bri"]) {
|
||||
this._brightness = (Byte)json["bri"];
|
||||
this.NotifyClient<SceneUpdateEvent>(this.Brightness);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -1,30 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using BlubbFish.IoT.Hue.Events;
|
||||
using BlubbFish.IoT.Hue.Interfaces;
|
||||
using BlubbFish.IoT.Hue.lib;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Hue.Devices.Scenes {
|
||||
class Scene : AScene {
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
#region Properties
|
||||
private String _name;
|
||||
public String Name {
|
||||
get {
|
||||
return this._name;
|
||||
}
|
||||
set {
|
||||
if (this.SetSceneAttribute(new Dictionary<String, Object>() { { "name", value } })) {
|
||||
this._name = value;
|
||||
this.NotifyClient<SceneUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public String Owner { get; private set; }
|
||||
public Boolean Recycle { get; private set; }
|
||||
public Boolean Locked { get; private set; }
|
||||
public String Picture { get; private set; }
|
||||
public DateTime Lastupdated { get; private set; }
|
||||
public Int32 Version { get; private set; }
|
||||
public ReadOnlyDictionary<Int32, ALight> Lights { get; private set; }
|
||||
public ReadOnlyDictionary<Int32, LightState> LightStates { get; private set; }
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public Scene(JsonData json, Tuple<String> id, HttpConnection http, Boolean polling, ReadOnlyDictionary<Int32, ALight> lights) : base(json, id, http, polling, lights) {
|
||||
this.ComplexInit(json);
|
||||
public Scene(JsonData json, Tuple<String> id, HttpConnection http, Boolean polling, ReadOnlyDictionary<Int32, ALight> lights) : base(json, new Tuple<String, Int32>(id.Item1, 0), http, polling, lights) {
|
||||
this.ComplexInit(json, lights);
|
||||
}
|
||||
|
||||
private void ComplexInit(JsonData json) {
|
||||
if(json.ContainsKey("owner") && json["owner"].IsString) {
|
||||
private void ComplexInit(JsonData json, ReadOnlyDictionary<Int32, ALight> lights) {
|
||||
if (json.ContainsKey("name") && json["name"].IsString) {
|
||||
this._name = json["name"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("owner") && json["owner"].IsString) {
|
||||
this.Owner = json["owner"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("recycle") && json["recycle"].IsBoolean) {
|
||||
@ -42,21 +58,30 @@ namespace BlubbFish.IoT.Hue.Devices.Scenes {
|
||||
if (json.ContainsKey("version") && json["version"].IsInt) {
|
||||
this.Version = (Int32)json["version"];
|
||||
}
|
||||
if (json.ContainsKey("lights") && json["lights"].IsArray) {
|
||||
Dictionary<Int32, ALight> lightdict = new Dictionary<Int32, ALight>();
|
||||
foreach (JsonData item in json["lights"]) {
|
||||
if (Int32.TryParse(item.ToString(), out Int32 lampid)) {
|
||||
if (lights.ContainsKey(lampid)) {
|
||||
lightdict.Add(lampid, lights[lampid]);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Lights = new ReadOnlyDictionary<Int32, ALight>(lightdict);
|
||||
}
|
||||
if (json.ContainsKey("lightstates") && json["lightstates"].IsObject) {
|
||||
Dictionary<Int32, LightState> lightstates = new Dictionary<Int32, LightState>();
|
||||
foreach (String item in json["lightstates"].Keys) {
|
||||
LightState l = new LightState(json["lightstates"][item], new Tuple<String, Int32>(this.SceneId, Int32.Parse(item)), this.http, this.Polling, lights);
|
||||
l.Update += this.NotifyClientChildren;
|
||||
lightstates.Add(Int32.Parse(item), l);
|
||||
}
|
||||
this.LightStates = new ReadOnlyDictionary<Int32, LightState>(lightstates);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AConnector
|
||||
public override Dictionary<String, Object> ToDictionary() {
|
||||
return new Dictionary<String, Object> {
|
||||
{ "owner", this.Owner },
|
||||
{ "recycle", this.Recycle },
|
||||
{ "locked", this.Locked },
|
||||
{ "picture", this.Picture },
|
||||
{ "lastupdated", this.Lastupdated },
|
||||
{ "version", this.Version }
|
||||
};
|
||||
}
|
||||
|
||||
public override String ToString() {
|
||||
List<String> lid = new List<String>();
|
||||
foreach (KeyValuePair<Int32, ALight> item in this.Lights) {
|
||||
@ -68,6 +93,58 @@ namespace BlubbFish.IoT.Hue.Devices.Scenes {
|
||||
}
|
||||
return "Scene " + this.Name + " [" + this.SceneId + "]: (["+ String.Join(",", lid.ToArray()) +"]) Light-States ["+ String.Join(",", lst.ToArray())+"]";
|
||||
}
|
||||
|
||||
public override void SetUpdate(JsonData json) {
|
||||
if (json.ContainsKey("name") && json["name"].IsString) {
|
||||
if (this.Name != json["name"].ToString()) {
|
||||
this._name = json["name"].ToString();
|
||||
this.NotifyClient<SceneUpdateEvent>(this.Name);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("owner") && json["owner"].IsString) {
|
||||
if (this.Owner != json["owner"].ToString()) {
|
||||
this.Owner = json["owner"].ToString();
|
||||
this.NotifyClient<SceneUpdateEvent>(this.Owner);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("recycle") && json["recycle"].IsBoolean) {
|
||||
if (this.Recycle != (Boolean)json["recycle"]) {
|
||||
this.Recycle = (Boolean)json["recycle"];
|
||||
this.NotifyClient<SceneUpdateEvent>(this.Recycle);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("locked") && json["locked"].IsBoolean) {
|
||||
if (this.Locked != (Boolean)json["locked"]) {
|
||||
this.Locked = (Boolean)json["locked"];
|
||||
this.NotifyClient<SceneUpdateEvent>(this.Locked);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("picture") && json["picture"].IsString) {
|
||||
if (this.Picture != json["picture"].ToString()) {
|
||||
this.Picture = json["picture"].ToString();
|
||||
this.NotifyClient<SceneUpdateEvent>(this.Picture);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("lastupdated") && json["lastupdated"].IsString) {
|
||||
if (this.Lastupdated != DateTime.Parse(json["lastupdated"].ToString())) {
|
||||
this.Lastupdated = DateTime.Parse(json["lastupdated"].ToString());
|
||||
this.NotifyClient<SceneUpdateEvent>(this.Lastupdated);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("version") && json["version"].IsInt) {
|
||||
if (this.Version != (Int32)json["version"]) {
|
||||
this.Version = (Int32)json["version"];
|
||||
this.NotifyClient<SceneUpdateEvent>(this.Version);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("lightstates") && json["lightstates"].IsObject) {
|
||||
foreach (String item in json["lightstates"].Keys) {
|
||||
if(this.LightStates.ContainsKey(Int32.Parse(item))) {
|
||||
this.LightStates[Int32.Parse(item)].SetUpdate(json["lightstates"][Int32.Parse(item)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
121
Hue/Devices/Sensors/Daylight.cs
Normal file
121
Hue/Devices/Sensors/Daylight.cs
Normal file
@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BlubbFish.IoT.Hue.Events;
|
||||
using BlubbFish.IoT.Hue.Interfaces;
|
||||
using BlubbFish.IoT.Hue.lib;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Hue.Devices.Sensors {
|
||||
class Daylight : ASensor {
|
||||
#region Properties
|
||||
private Boolean _on;
|
||||
public Boolean On {
|
||||
get {
|
||||
return this._on;
|
||||
}
|
||||
set {
|
||||
if(this.SetSensorConfig(new Dictionary<String, Object>() { { "on", value } })) {
|
||||
this._on = value;
|
||||
this.NotifyClient<SensorUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public Boolean Configured { get; private set; }
|
||||
private Int32 _sunriseoffset;
|
||||
public Int32 Sunriseoffset {
|
||||
get {
|
||||
return this._sunriseoffset;
|
||||
}
|
||||
set {
|
||||
if(this.SetSensorConfig(new Dictionary<String, Object>() { { "sunriseoffset", value } })) {
|
||||
this._sunriseoffset = value;
|
||||
this.NotifyClient<SensorUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
private Int32 _sunsetoffset;
|
||||
public Int32 Sunsetoffset {
|
||||
get {
|
||||
return this._sunsetoffset;
|
||||
}
|
||||
set {
|
||||
if(this.SetSensorConfig(new Dictionary<String, Object>() { { "sunsetoffset", value } })) {
|
||||
this._sunsetoffset = value;
|
||||
this.NotifyClient<SensorUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public Boolean IsDaylight { get; private set; }
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public Daylight(JsonData json, Tuple<Int32, Types> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
this.ComplexInit(json);
|
||||
}
|
||||
|
||||
private void ComplexInit(JsonData json) {
|
||||
if(json.ContainsKey("config")) {
|
||||
JsonData config = json["config"];
|
||||
if(config.ContainsKey("on") && config["on"].IsBoolean) {
|
||||
this._on = (Boolean)config["on"];
|
||||
}
|
||||
if(config.ContainsKey("configured") && config["configured"].IsBoolean) {
|
||||
this.Configured = (Boolean)config["configured"];
|
||||
}
|
||||
if(config.ContainsKey("sunriseoffset") && config["sunriseoffset"].IsInt) {
|
||||
this._sunriseoffset = (Int32)config["sunriseoffset"];
|
||||
}
|
||||
if(config.ContainsKey("sunsetoffset") && config["sunsetoffset"].IsInt) {
|
||||
this._sunsetoffset = (Int32)config["sunsetoffset"];
|
||||
}
|
||||
}
|
||||
if(json.ContainsKey("state")) {
|
||||
JsonData state = json["state"];
|
||||
if(state.ContainsKey("daylight") && state["daylight"].IsBoolean) {
|
||||
this.IsDaylight = (Boolean)state["daylight"];
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AConnector
|
||||
public override String ToString() {
|
||||
return "Daylight " + this.Name + " [" + this.SensorId + "]: IsDaylight-" + this.IsDaylight.ToString() + " On-" + this.On.ToString() + " Configured-" + this.Configured.ToString() + " Sunriseoffset-" + this.Sunriseoffset.ToString() + " Sunsetoffset-" + this.Sunsetoffset.ToString();
|
||||
}
|
||||
|
||||
public override void SetUpdate(JsonData json) {
|
||||
base.SetUpdate(json);
|
||||
if (json.ContainsKey("config") && json["config"].ContainsKey("on") && json["config"]["on"].IsBoolean) {
|
||||
if (this.On != (Boolean)json["config"]["on"]) {
|
||||
this._on = (Boolean)json["config"]["on"];
|
||||
this.NotifyClient<SensorUpdateEvent>(this.On);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("config") && json["config"].ContainsKey("configured") && json["config"]["configured"].IsBoolean) {
|
||||
if (this.Configured != (Boolean)json["config"]["configured"]) {
|
||||
this.Configured = (Boolean)json["config"]["configured"];
|
||||
this.NotifyClient<SensorUpdateEvent>(this.Configured);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("config") && json["config"].ContainsKey("sunriseoffset") && json["config"]["sunriseoffset"].IsInt) {
|
||||
if (this.Sunriseoffset != (Int32)json["config"]["sunriseoffset"]) {
|
||||
this._sunriseoffset = (Int32)json["config"]["sunriseoffset"];
|
||||
this.NotifyClient<SensorUpdateEvent>(this.Sunriseoffset);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("config") && json["config"].ContainsKey("sunsetoffset") && json["config"]["sunsetoffset"].IsInt) {
|
||||
if (this.Sunsetoffset != (Int32)json["config"]["sunsetoffset"]) {
|
||||
this._sunsetoffset = (Int32)json["config"]["sunsetoffset"];
|
||||
this.NotifyClient<SensorUpdateEvent>(this.Sunsetoffset);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("state") && json["state"].ContainsKey("daylight") && json["state"]["daylight"].IsBoolean) {
|
||||
if (this.IsDaylight != (Boolean)json["state"]["daylight"]) {
|
||||
this.IsDaylight = (Boolean)json["state"]["daylight"];
|
||||
this.NotifyClient<SensorUpdateEvent>(this.IsDaylight);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -42,4 +42,18 @@ namespace BlubbFish.IoT.Hue.Events {
|
||||
public SceneUpdateEvent(Object value, DateTime time, Object parent) : base(value, time, parent) {
|
||||
}
|
||||
}
|
||||
public class SensorUpdateEvent : AllUpdateEvent {
|
||||
public SensorUpdateEvent() {
|
||||
}
|
||||
|
||||
public SensorUpdateEvent(Object value, DateTime time, Object parent) : base(value, time, parent) {
|
||||
}
|
||||
}
|
||||
public class ConfigUpdateEvent : AllUpdateEvent {
|
||||
public ConfigUpdateEvent() {
|
||||
}
|
||||
|
||||
public ConfigUpdateEvent(Object value, DateTime time, Object parent) : base(value, time, parent) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,8 +41,14 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Devices\Configs\Config.cs" />
|
||||
<Compile Include="Devices\Configs\Portalstate.cs" />
|
||||
<Compile Include="Devices\Configs\SwUpdate.cs" />
|
||||
<Compile Include="Devices\Configs\Whitelist.cs" />
|
||||
<Compile Include="Devices\Scenes\LightState.cs" />
|
||||
<Compile Include="Devices\Scenes\Scene.cs" />
|
||||
<Compile Include="Devices\Sensors\Daylight.cs" />
|
||||
<Compile Include="Interfaces\AConfig.cs" />
|
||||
<Compile Include="Interfaces\AGroup.cs" />
|
||||
<Compile Include="Devices\Groups\Room.cs" />
|
||||
<Compile Include="Devices\Lights\Dimmablelight.cs" />
|
||||
@ -51,6 +57,7 @@
|
||||
<Compile Include="Exceptions\HueExceptions.cs" />
|
||||
<Compile Include="Interfaces\AScene.cs" />
|
||||
<Compile Include="Interfaces\AConnector.cs" />
|
||||
<Compile Include="Interfaces\ASensor.cs" />
|
||||
<Compile Include="Interfaces\IMqtt.cs" />
|
||||
<Compile Include="HueController.cs" />
|
||||
<Compile Include="lib\Helper.cs" />
|
||||
|
@ -21,6 +21,8 @@ namespace BlubbFish.IoT.Hue {
|
||||
public ReadOnlyDictionary<Int32, ALight> Lights { get; private set; }
|
||||
public ReadOnlyDictionary<Int32, AGroup> Groups { get; private set; }
|
||||
public ReadOnlyDictionary<String, AScene> Scenes { get; private set; }
|
||||
public ReadOnlyDictionary<Int32, ASensor> Sensors { get; private set; }
|
||||
public AConfig Config { get; private set; }
|
||||
|
||||
public HueController(Dictionary<String,String> settings, Boolean enablePoll = true) {
|
||||
this.polling = enablePoll;
|
||||
@ -50,10 +52,10 @@ namespace BlubbFish.IoT.Hue {
|
||||
foreach (KeyValuePair<String, AScene> item in this.Scenes) {
|
||||
item.Value.Update += this.AllUpdate;
|
||||
}
|
||||
/*foreach (KeyValuePair<Int32, Sensor> item in this.Sensors) {
|
||||
foreach (KeyValuePair<Int32, ASensor> item in this.Sensors) {
|
||||
item.Value.Update += this.AllUpdate;
|
||||
}
|
||||
this.Config.Update += this.AllUpdate;*/
|
||||
this.Config.Update += this.AllUpdate;
|
||||
}
|
||||
|
||||
private void Poll() {
|
||||
@ -65,25 +67,59 @@ namespace BlubbFish.IoT.Hue {
|
||||
}
|
||||
|
||||
private void Updater() {
|
||||
//throw new NotImplementedException();
|
||||
while (true) {
|
||||
Thread.Sleep(1000 * 10); //Every Minute
|
||||
JsonData update = this.http.GetJson("");
|
||||
Helper.SetUpdate(this.Lights, update, "lights");
|
||||
Helper.SetUpdate(this.Groups, update, "groups");
|
||||
Helper.SetUpdate(this.Sensors, update, "sensors");
|
||||
Helper.SetUpdate(this.Scenes, update, "scenes");
|
||||
if (update.ContainsKey("config")) {
|
||||
this.Config.SetUpdate(update);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void CreateAll(JsonData json) {
|
||||
if(json.ContainsKey("lights")) {
|
||||
this.CreateLights(json["lights"]);
|
||||
this.Lights = new ReadOnlyDictionary<Int32, ALight>(this.CreateItemsInt32<ALight>(json["lights"], false));
|
||||
}
|
||||
if(json.ContainsKey("groups")) {
|
||||
this.CreateGroups(json["groups"]);
|
||||
this.Groups = new ReadOnlyDictionary<Int32, AGroup>(this.CreateItemsInt32<AGroup>(json["groups"]));
|
||||
}
|
||||
if(json.ContainsKey("scenes")) {
|
||||
if (json.ContainsKey("sensors")) {
|
||||
this.Sensors = new ReadOnlyDictionary<Int32, ASensor>(this.CreateItemsInt32<ASensor>(json["sensors"], false));
|
||||
}
|
||||
if (json.ContainsKey("scenes")) {
|
||||
this.CreateScenes(json["scenes"]);
|
||||
}
|
||||
if(json.ContainsKey("config")) {
|
||||
this.Config = AConfig.CreateInstanceConcrete(json["config"], this.http, this.polling);
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<Int32, T> CreateItemsInt32<T>(JsonData json, Boolean withLights = true) {
|
||||
Dictionary<Int32, T> items = new Dictionary<Int32, T>();
|
||||
foreach (String itemid in json.Keys) {
|
||||
T item = default(T);
|
||||
if (withLights) {
|
||||
item = (T)AConnector.CreateInstance(typeof(T), json[itemid], new Tuple<Int32>(Int32.Parse(itemid)), this.http, this.polling, this.Lights);
|
||||
} else {
|
||||
item = (T)AConnector.CreateInstance(typeof(T), json[itemid], new Tuple<Int32>(Int32.Parse(itemid)), this.http, this.polling);
|
||||
}
|
||||
if(item != null) {
|
||||
items.Add(Int32.Parse(itemid), item);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private void CreateScenes(JsonData json) {
|
||||
Dictionary<String, AScene> scenes = new Dictionary<String, AScene>();
|
||||
foreach (String sceneid in json.Keys) {
|
||||
AScene s = AScene.CreateScene(json[sceneid], new Tuple<String>(sceneid), this.http, this.polling, this.Lights);
|
||||
AScene s = AScene.CreateInstanceConcrete(json[sceneid], new Tuple<String>(sceneid), this.http, this.polling, this.Lights);
|
||||
if (s != null) {
|
||||
scenes.Add(sceneid, s);
|
||||
}
|
||||
@ -91,28 +127,6 @@ namespace BlubbFish.IoT.Hue {
|
||||
this.Scenes = new ReadOnlyDictionary<String, AScene>(scenes);
|
||||
}
|
||||
|
||||
private void CreateGroups(JsonData json) {
|
||||
Dictionary<Int32, AGroup> groups = new Dictionary<Int32, AGroup>();
|
||||
foreach (String groupid in json.Keys) {
|
||||
AGroup g = AGroup.CreateGroup(json[groupid], new Tuple<Int32>(Int32.Parse(groupid)), this.http, this.polling, this.Lights);
|
||||
if (g != null) {
|
||||
groups.Add(Int32.Parse(groupid), g);
|
||||
}
|
||||
}
|
||||
this.Groups = new ReadOnlyDictionary<Int32, AGroup>(groups);
|
||||
}
|
||||
|
||||
private void CreateLights(JsonData json) {
|
||||
Dictionary<Int32, ALight> lights = new Dictionary<Int32, ALight>();
|
||||
foreach (String lightid in json.Keys) {
|
||||
ALight l = ALight.CreateLight(json[lightid], new Tuple<Int32>(Int32.Parse(lightid)), this.http, this.polling);
|
||||
if(l != null) {
|
||||
lights.Add(Int32.Parse(lightid), l);
|
||||
}
|
||||
}
|
||||
this.Lights = new ReadOnlyDictionary<Int32, ALight>(lights);
|
||||
}
|
||||
|
||||
private void CreateKey(String server) {
|
||||
this.http = new HttpConnection(server);
|
||||
JsonData json = this.http.PostJson("", "{\"devicetype\": \"Huelib#BlubbFish\"}");
|
||||
@ -148,8 +162,8 @@ namespace BlubbFish.IoT.Hue {
|
||||
this.Lights = null;
|
||||
this.Groups = null;
|
||||
this.Scenes = null;
|
||||
/*this.Sensors = null;
|
||||
this.Config = null;*/
|
||||
this.Sensors = null;
|
||||
this.Config = null;
|
||||
this.disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
34
Hue/Interfaces/AConfig.cs
Normal file
34
Hue/Interfaces/AConfig.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BlubbFish.IoT.Hue.Devices.Configs;
|
||||
using BlubbFish.IoT.Hue.lib;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Hue.Interfaces {
|
||||
public abstract class AConfig : AConnector, IMqtt {
|
||||
#region Constructor
|
||||
public AConfig(JsonData json, HttpConnection http, Boolean polling) : base(http, polling){
|
||||
}
|
||||
|
||||
internal static AConfig CreateInstanceConcrete(JsonData json, HttpConnection http, Boolean polling) {
|
||||
return new Config(json, http, polling);
|
||||
}
|
||||
#endregion
|
||||
|
||||
protected Boolean SetConfig(Dictionary<String, Object> dictionary) {
|
||||
return this.PutDictionary("config", dictionary);
|
||||
}
|
||||
|
||||
#region IMqtt
|
||||
public String MqttTopic() {
|
||||
return "config";
|
||||
}
|
||||
public String ToJson() {
|
||||
return JsonMapper.ToJson(this.ToDictionary());
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Reflection;
|
||||
using BlubbFish.IoT.Hue.Events;
|
||||
using BlubbFish.IoT.Hue.lib;
|
||||
using LitJson;
|
||||
@ -7,14 +10,75 @@ using LitJson;
|
||||
namespace BlubbFish.IoT.Hue.Interfaces {
|
||||
public abstract class AConnector {
|
||||
protected HttpConnection http;
|
||||
public delegate void UpdatedValue(Object sender, AllUpdateEvent e);
|
||||
public event UpdatedValue Update;
|
||||
|
||||
protected void PutDictionary(String address, Dictionary<String, Object> value) {
|
||||
this.http.PutJson(address, JsonMapper.ToJson(value));
|
||||
#region Properties
|
||||
public DateTime LastUpdate { get; private set; }
|
||||
public Boolean Polling { get; set; }
|
||||
public Boolean PollOnce { get; set; }
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public AConnector(HttpConnection http, Boolean polling) {
|
||||
this.http = http;
|
||||
this.Polling = polling;
|
||||
this.LastUpdate = DateTime.Now;
|
||||
}
|
||||
|
||||
public delegate void UpdatedValue(Object sender, AllUpdateEvent e);
|
||||
internal static Object CreateInstance(Type type, JsonData json, Tuple<Int32> id, HttpConnection http, Boolean polling, ReadOnlyDictionary<Int32, ALight> lights) {
|
||||
return type.GetMethod("CreateInstanceConcrete", new Type[] { typeof(JsonData), typeof(Tuple<Int32>), typeof(HttpConnection), typeof(Boolean), typeof(ReadOnlyDictionary<Int32, ALight>) }).Invoke(null, new Object[] { json, id, http, polling, lights });
|
||||
}
|
||||
|
||||
internal static Object CreateInstance(Type type, JsonData json, Tuple<Int32> id, HttpConnection http, Boolean polling) {
|
||||
return type.GetMethod("CreateInstanceConcrete", new Type[] { typeof(JsonData), typeof(Tuple<Int32>), typeof(HttpConnection), typeof(Boolean) }).Invoke(null, new Object[] { json, id, http, polling });
|
||||
}
|
||||
#endregion
|
||||
|
||||
protected Boolean PutDictionary(String address, Dictionary<String, Object> value) {
|
||||
JsonData json = this.http.PutJson(address, JsonMapper.ToJson(value));
|
||||
if (json.IsArray) {
|
||||
return json[0].ContainsKey("success");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual Dictionary<String, Object> ToDictionary() {
|
||||
Dictionary<String, Object> dictionary = new Dictionary<String, Object>();
|
||||
foreach (PropertyInfo item in this.GetType().GetProperties()) {
|
||||
if (item.CanRead && item.GetValue(this) != null) {
|
||||
if (item.GetValue(this).GetType().GetMethod("ToDictionary") != null) {
|
||||
dictionary.Add(item.Name, item.GetValue(this).GetType().GetMethod("ToDictionary").Invoke(item.GetValue(this), null));
|
||||
} else if (Helper.HasInterface(item.GetValue(this).GetType(), "IDictionary")) {
|
||||
Dictionary<String, Object> subdict = new Dictionary<String, Object>();
|
||||
foreach (DictionaryEntry subitem in (IDictionary)item.GetValue(this)) {
|
||||
if (subitem.Value.GetType().GetMethod("ToDictionary") != null) {
|
||||
subdict.Add(subitem.Key.ToString(), subitem.Value.GetType().GetMethod("ToDictionary").Invoke(subitem.Value, null));
|
||||
}
|
||||
}
|
||||
dictionary.Add(item.Name, subdict);
|
||||
} else if (item.GetValue(this).GetType().BaseType == typeof(Enum)) {
|
||||
dictionary.Add(item.Name, Helper.GetEnumDescription((Enum)item.GetValue(this)));
|
||||
} else {
|
||||
dictionary.Add(item.Name, item.GetValue(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
return dictionary;
|
||||
}
|
||||
|
||||
protected void NotifyClient<T>(Object value) {
|
||||
this.LastUpdate = DateTime.Now;
|
||||
this.Update?.Invoke(this, (AllUpdateEvent)Activator.CreateInstance(typeof(T), new Object[] { value, this.LastUpdate, this }));
|
||||
}
|
||||
|
||||
protected void NotifyClientChildren(Object sender, AllUpdateEvent e) {
|
||||
this.Update?.Invoke(sender, e);
|
||||
}
|
||||
|
||||
#region Abstracts
|
||||
public abstract override String ToString();
|
||||
public abstract Dictionary<String, Object> ToDictionary();
|
||||
public abstract event UpdatedValue Update;
|
||||
public abstract void SetUpdate(JsonData json);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using BlubbFish.IoT.Hue.Events;
|
||||
using BlubbFish.IoT.Hue.lib;
|
||||
using LitJson;
|
||||
|
||||
@ -45,42 +46,67 @@ namespace BlubbFish.IoT.Hue.Interfaces {
|
||||
}
|
||||
|
||||
#region Properties
|
||||
public DateTime LastUpdate { get; protected set; }
|
||||
public Boolean Polling { get; set; }
|
||||
public String Name { get {
|
||||
return this._name;
|
||||
} set {
|
||||
this._name = value;
|
||||
this.SetGroupAttribute(new Dictionary<String, Object>() { { "name", value } });
|
||||
if(this.SetGroupAttribute(new Dictionary<String, Object>() { { "name", value } })) {
|
||||
this._name = value;
|
||||
this.NotifyClient<GroupUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
public Int32 GroupId { get; }
|
||||
public Types Groupclass { get; }
|
||||
public Boolean StateAnyOn { get; protected set; }
|
||||
public Boolean StateAllOn { get; protected set; }
|
||||
public Dictionary<Int32, ALight> Lights { get; protected set; }
|
||||
public ReadOnlyDictionary<Int32, ALight> Lights { get; protected set; }
|
||||
public GroupClass Class {
|
||||
get {
|
||||
return this._class;
|
||||
}
|
||||
set {
|
||||
this._class = value;
|
||||
this.SetGroupAttribute(new Dictionary<String, Object>() { { "class", Helper.GetEnumDescription(value) } });
|
||||
if(this.SetGroupAttribute(new Dictionary<String, Object>() { { "class", Helper.GetEnumDescription(value) } })) {
|
||||
this._class = value;
|
||||
this.NotifyClient<GroupUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
protected AGroup(JsonData json, Tuple<Int32, Types> id, HttpConnection http, Boolean polling, ReadOnlyDictionary<Int32, ALight> lights) {
|
||||
protected AGroup(JsonData json, Tuple<Int32, Types> id, HttpConnection http, Boolean polling, ReadOnlyDictionary<Int32, ALight> lights) : base(http, polling) {
|
||||
this.GroupId = id.Item1;
|
||||
this.Groupclass = id.Item2;
|
||||
this.http = http;
|
||||
this.LastUpdate = DateTime.Now;
|
||||
this.Polling = polling;
|
||||
this.ComplexInit(json, lights);
|
||||
}
|
||||
|
||||
internal static AGroup CreateGroup(JsonData json, Tuple<Int32> id, HttpConnection http, Boolean polling, ReadOnlyDictionary<Int32, ALight> lights) {
|
||||
private void ComplexInit(JsonData json, ReadOnlyDictionary<Int32, ALight> lights) {
|
||||
if (json.ContainsKey("lights") && json["lights"].IsArray) {
|
||||
Dictionary<Int32, ALight> lightdict = new Dictionary<Int32, ALight>();
|
||||
foreach (JsonData item in json["lights"]) {
|
||||
if (Int32.TryParse(item.ToString(), out Int32 lampid)) {
|
||||
if (lights.ContainsKey(lampid)) {
|
||||
lightdict.Add(lampid, lights[lampid]);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.Lights = new ReadOnlyDictionary<Int32, ALight>(lightdict);
|
||||
}
|
||||
if (json.ContainsKey("name") && json["name"].IsString) {
|
||||
this._name = json["name"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("state") && json["state"].ContainsKey("any_on") && json["state"]["any_on"].IsBoolean) {
|
||||
this.StateAnyOn = (Boolean)json["state"]["any_on"];
|
||||
}
|
||||
if (json.ContainsKey("state") && json["state"].ContainsKey("all_on") && json["state"]["all_on"].IsBoolean) {
|
||||
this.StateAllOn = (Boolean)json["state"]["all_on"];
|
||||
}
|
||||
if (json.ContainsKey("class") && json["class"].IsString) {
|
||||
this._class = (GroupClass)Enum.Parse(typeof(GroupClass), json["class"].ToString().ToEnumString());
|
||||
}
|
||||
}
|
||||
|
||||
public static AGroup CreateInstanceConcrete(JsonData json, Tuple<Int32> id, HttpConnection http, Boolean polling, ReadOnlyDictionary<Int32, ALight> lights) {
|
||||
String type = "";
|
||||
if (json.ContainsKey("type")) {
|
||||
type = json["type"].ToString().ToEnumString();
|
||||
@ -107,54 +133,46 @@ namespace BlubbFish.IoT.Hue.Interfaces {
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void ComplexInit(JsonData json, ReadOnlyDictionary<Int32, ALight> lights) {
|
||||
if (json.ContainsKey("lights") && json["lights"].IsArray) {
|
||||
this.Lights = new Dictionary<Int32, ALight>();
|
||||
foreach (JsonData item in json["lights"]) {
|
||||
if (Int32.TryParse(item.ToString(), out Int32 lampid)) {
|
||||
if (lights.ContainsKey(lampid)) {
|
||||
this.Lights.Add(lampid, lights[lampid]);
|
||||
}
|
||||
}
|
||||
protected Boolean SetGroupAttribute(Dictionary<String, Object> value) {
|
||||
return this.PutDictionary("groups/" + this.GroupId, value);
|
||||
}
|
||||
|
||||
protected Boolean SetGroupAction(Dictionary<String, Object> value) {
|
||||
return this.PutDictionary("groups/" + this.GroupId + "/action", value);
|
||||
}
|
||||
|
||||
#region AConnector
|
||||
public override void SetUpdate(JsonData json) {
|
||||
if (json.ContainsKey("name") && json["name"].IsString) {
|
||||
if (this.Name != json["name"].ToString()) {
|
||||
this._name = json["name"].ToString();
|
||||
this.NotifyClient<GroupUpdateEvent>(this.Name);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("name")) {
|
||||
this._name = json["name"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("state") && json["state"].ContainsKey("any_on") && json["state"]["any_on"].IsBoolean) {
|
||||
this.StateAnyOn = (Boolean)json["state"]["any_on"];
|
||||
if (this.StateAnyOn != (Boolean)json["state"]["any_on"]) {
|
||||
this.StateAnyOn = (Boolean)json["state"]["any_on"];
|
||||
this.NotifyClient<GroupUpdateEvent>(this.StateAnyOn);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("state") && json["state"].ContainsKey("all_on") && json["state"]["all_on"].IsBoolean) {
|
||||
this.StateAllOn = (Boolean)json["state"]["all_on"];
|
||||
if (this.StateAllOn != (Boolean)json["state"]["all_on"]) {
|
||||
this.StateAllOn = (Boolean)json["state"]["all_on"];
|
||||
this.NotifyClient<GroupUpdateEvent>(this.StateAllOn);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("class")) {
|
||||
this._class = (GroupClass)Enum.Parse(typeof(GroupClass), json["class"].ToString().ToEnumString());
|
||||
if (json.ContainsKey("class") && json["class"].IsString) {
|
||||
if (this.Class != (GroupClass)Enum.Parse(typeof(GroupClass), json["class"].ToString().ToEnumString())) {
|
||||
this._class = (GroupClass)Enum.Parse(typeof(GroupClass), json["class"].ToString().ToEnumString());
|
||||
this.NotifyClient<GroupUpdateEvent>(this.Class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void SetGroupAttribute(Dictionary<String, Object> value) {
|
||||
this.PutDictionary("groups/" + this.GroupId, value);
|
||||
}
|
||||
|
||||
protected void SetGroupAction(Dictionary<String, Object> value) {
|
||||
this.PutDictionary("groups/" + this.GroupId + "/action", value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IMqtt
|
||||
public String ToJson() {
|
||||
Dictionary<String, Object> json = this.ToDictionary();
|
||||
json.Add("StateAnyOn", this.StateAnyOn.ToString());
|
||||
json.Add("StateAllOn", this.StateAllOn.ToString());
|
||||
json.Add("Class", Helper.GetEnumDescription(this.Class));
|
||||
json.Add("LastUpdate", this.LastUpdate.ToString());
|
||||
json.Add("Name", this.Name);
|
||||
json.Add("Lightclass", this.Groupclass.ToString());
|
||||
Dictionary<String, Object> lights = new Dictionary<String, Object>();
|
||||
foreach (KeyValuePair<Int32, ALight> item in this.Lights) {
|
||||
lights.Add(item.Key.ToString(), item.Value.ToDictionary());
|
||||
}
|
||||
json.Add("lights", lights);
|
||||
return JsonMapper.ToJson(json);
|
||||
return JsonMapper.ToJson(this.ToDictionary());
|
||||
}
|
||||
|
||||
public String MqttTopic() {
|
||||
|
@ -17,23 +17,33 @@ namespace BlubbFish.IoT.Hue.Interfaces {
|
||||
#region Properties
|
||||
public Int32 LightId { get; }
|
||||
public Types Lightclass { get; }
|
||||
public DateTime LastUpdate { get; protected set; }
|
||||
public String Name { get; protected set; }
|
||||
public Boolean Polling { get; set; }
|
||||
public Boolean PollOnce { get; set; }
|
||||
private String _name;
|
||||
public String Name {
|
||||
get {
|
||||
return this._name;
|
||||
}
|
||||
set {
|
||||
if (this.SetLightAttribute(new Dictionary<String, Object>() { { "name", value } })) {
|
||||
this._name = value;
|
||||
this.NotifyClient<LightUpdateEvent>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
protected ALight(JsonData json, Tuple<Int32, Types> id, HttpConnection http, Boolean polling) {
|
||||
protected ALight(JsonData json, Tuple<Int32, Types> id, HttpConnection http, Boolean polling): base(http, polling) {
|
||||
this.LightId = id.Item1;
|
||||
this.Lightclass = id.Item2;
|
||||
this.http = http;
|
||||
this.LastUpdate = DateTime.Now;
|
||||
this.Polling = polling;
|
||||
this.ComplexInit(json);
|
||||
}
|
||||
private void ComplexInit(JsonData json) {
|
||||
if (json.ContainsKey("name")) {
|
||||
this._name = json["name"].ToString();
|
||||
}
|
||||
}
|
||||
|
||||
internal static ALight CreateLight(JsonData json, Tuple<Int32> id, HttpConnection http, Boolean polling) {
|
||||
public static ALight CreateInstanceConcrete(JsonData json, Tuple<Int32> id, HttpConnection http, Boolean polling) {
|
||||
String type = "";
|
||||
if (json.ContainsKey("type")) {
|
||||
type = json["type"].ToString().ToEnumString();
|
||||
@ -60,14 +70,11 @@ namespace BlubbFish.IoT.Hue.Interfaces {
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void ComplexInit(JsonData json) {
|
||||
if (json.ContainsKey("name")) {
|
||||
this.Name = json["name"].ToString();
|
||||
}
|
||||
protected Boolean SetLightStateAttribute(Dictionary<String, Object> value) {
|
||||
return this.PutDictionary("lights/" + this.LightId + "/state", value);
|
||||
}
|
||||
|
||||
protected void SetLightState(Dictionary<String, Object> value) {
|
||||
this.PutDictionary("lights/" + this.LightId + "/state", value);
|
||||
protected Boolean SetLightAttribute(Dictionary<String, Object> value) {
|
||||
return this.PutDictionary("lights/" + this.LightId, value);
|
||||
}
|
||||
|
||||
#region IMqtt
|
||||
@ -76,11 +83,18 @@ namespace BlubbFish.IoT.Hue.Interfaces {
|
||||
}
|
||||
|
||||
public String ToJson() {
|
||||
Dictionary<String, Object> json = this.ToDictionary();
|
||||
json.Add("LastUpdate", this.LastUpdate.ToString());
|
||||
json.Add("Name", this.Name);
|
||||
json.Add("Lightclass", this.Lightclass.ToString());
|
||||
return JsonMapper.ToJson(json);
|
||||
return JsonMapper.ToJson(this.ToDictionary());
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region AConnector
|
||||
public override void SetUpdate(JsonData json) {
|
||||
if(json.ContainsKey("name") && json["name"].IsString) {
|
||||
if(this.Name != json["name"].ToString()) {
|
||||
this._name = json["name"].ToString();
|
||||
this.NotifyClient<LightUpdateEvent>(this.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
@ -7,94 +7,32 @@ using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Hue.Interfaces {
|
||||
public abstract class AScene : AConnector, IMqtt {
|
||||
private Boolean Polling;
|
||||
private String _name;
|
||||
|
||||
#region Properties
|
||||
public String SceneId { get; }
|
||||
public DateTime LastUpdate { get; }
|
||||
public Dictionary<Int32, ALight> Lights { get; private set; }
|
||||
public Dictionary<Int32, LightState> LightStates { get; private set; }
|
||||
public String Name {
|
||||
get {
|
||||
return this._name;
|
||||
}
|
||||
set {
|
||||
this._name = value;
|
||||
this.SetSceneAttribute(new Dictionary<String, Object>() { { "name", value } });
|
||||
}
|
||||
}
|
||||
public Int32 LightStateId { get; }
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
protected AScene(JsonData json, Tuple<String> id, HttpConnection http, Boolean polling, ReadOnlyDictionary<Int32, ALight> lights) {
|
||||
protected AScene(JsonData json, Tuple<String, Int32> id, HttpConnection http, Boolean polling, ReadOnlyDictionary<Int32, ALight> lights) : base(http, polling) {
|
||||
this.SceneId = id.Item1;
|
||||
this.http = http;
|
||||
this.LastUpdate = DateTime.Now;
|
||||
this.Polling = polling;
|
||||
this.ComplexInit(json, lights);
|
||||
this.LightStateId = id.Item2;
|
||||
}
|
||||
|
||||
internal static AScene CreateScene(JsonData json, Tuple<String> id, HttpConnection http, Boolean polling, ReadOnlyDictionary<Int32, ALight> lights) {
|
||||
String name = "BlubbFish.IoT.Hue.Devices.Scenes.Scene";
|
||||
JsonData scenedata = http.GetJson("scenes/" + id.Item1);
|
||||
return GetInstanceConcrete(name, scenedata, id, http, polling, lights);
|
||||
}
|
||||
|
||||
private static AScene GetInstanceConcrete(String name, JsonData json, Tuple<String> id, HttpConnection http, Boolean polling, ReadOnlyDictionary<Int32, ALight> lights) {
|
||||
Type t = null;
|
||||
try {
|
||||
t = Type.GetType(name, true);
|
||||
} catch (TypeLoadException) {
|
||||
Helper.WriteError("Konnte Type " + name + " nicht laden!");
|
||||
return null;
|
||||
}
|
||||
return (AScene)t.GetConstructor(new Type[] { typeof(JsonData), typeof(Tuple<String>), typeof(HttpConnection), typeof(Boolean), typeof(ReadOnlyDictionary<Int32, ALight>) }).Invoke(new Object[] { json, id, http, polling, lights });
|
||||
public static AScene CreateInstanceConcrete(JsonData json, Tuple<String> id, HttpConnection http, Boolean polling, ReadOnlyDictionary<Int32, ALight> lights) {
|
||||
return new Scene(http.GetJson("scenes/" + id.Item1), id, http, polling, lights);
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void ComplexInit(JsonData json, ReadOnlyDictionary<Int32, ALight> lights) {
|
||||
if (json.ContainsKey("lights") && json["lights"].IsArray) {
|
||||
this.Lights = new Dictionary<Int32, ALight>();
|
||||
foreach (JsonData item in json["lights"]) {
|
||||
if (Int32.TryParse(item.ToString(), out Int32 lampid)) {
|
||||
if (lights.ContainsKey(lampid)) {
|
||||
this.Lights.Add(lampid, lights[lampid]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("name")) {
|
||||
this._name = json["name"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("lightstates")) {
|
||||
this.LightStates = new Dictionary<Int32, LightState>();
|
||||
foreach (String item in json["lightstates"].Keys) {
|
||||
this.LightStates.Add(Int32.Parse(item), new LightState(json["lightstates"][item], new Tuple<String, Int32>(this.SceneId, Int32.Parse(item)), this.http));
|
||||
}
|
||||
}
|
||||
protected Boolean SetSceneAttribute(Dictionary<String, Object> dictionary) {
|
||||
return this.PutDictionary("scenes/" + this.SceneId, dictionary);
|
||||
}
|
||||
|
||||
protected void SetSceneAttribute(Dictionary<String, Object> dictionary) {
|
||||
this.PutDictionary("scenes/" + this.SceneId, dictionary);
|
||||
protected Boolean SetLightSceneAttribute(Dictionary<String, Object> value) {
|
||||
return this.PutDictionary("scenes/" + this.SceneId + "/lights/" + this.LightStateId + "/state", value);
|
||||
}
|
||||
|
||||
#region IMqtt
|
||||
public String ToJson() {
|
||||
Dictionary<String, Object> json = this.ToDictionary();
|
||||
json.Add("LastUpdate", this.LastUpdate.ToString());
|
||||
json.Add("Name", this.Name);
|
||||
Dictionary<String, Object> lights = new Dictionary<String, Object>();
|
||||
foreach (KeyValuePair<Int32, ALight> item in this.Lights) {
|
||||
lights.Add(item.Key.ToString(), item.Value.ToDictionary());
|
||||
}
|
||||
json.Add("lights", lights);
|
||||
Dictionary<String, Object> states = new Dictionary<String, Object>();
|
||||
foreach (KeyValuePair<Int32, LightState> item in this.LightStates) {
|
||||
states.Add(item.Key.ToString(), item.Value.ToDictionary());
|
||||
}
|
||||
json.Add("lightstates", states);
|
||||
return JsonMapper.ToJson(json);
|
||||
return JsonMapper.ToJson(this.ToDictionary());
|
||||
}
|
||||
|
||||
public String MqttTopic() {
|
||||
|
127
Hue/Interfaces/ASensor.cs
Normal file
127
Hue/Interfaces/ASensor.cs
Normal file
@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using BlubbFish.IoT.Hue.Events;
|
||||
using BlubbFish.IoT.Hue.lib;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Hue.Interfaces {
|
||||
public abstract class ASensor : AConnector, IMqtt {
|
||||
|
||||
|
||||
public enum Types {
|
||||
Daylight
|
||||
}
|
||||
public enum TypesIgnore {
|
||||
Zgpswitch,
|
||||
Zllswitch,
|
||||
Zllpresence,
|
||||
Zlltemperature,
|
||||
Clipswitch,
|
||||
Clipopenclose,
|
||||
Clippresence,
|
||||
Cliptemperature,
|
||||
Cliphumidity,
|
||||
Cliplightlevel,
|
||||
Zlllightlevel,
|
||||
Clipgenericflag,
|
||||
Clipgenericstatus
|
||||
}
|
||||
|
||||
#region Properties
|
||||
public Int32 SensorId { get; }
|
||||
public Types Sensorclass { get; }
|
||||
public DateTime Lastupdated { get; protected set; }
|
||||
private String _name;
|
||||
public String Name {
|
||||
get {
|
||||
return this._name;
|
||||
}
|
||||
set {
|
||||
this._name = value;
|
||||
this.SetSensorAttribute(new Dictionary<String, Object>() { { "name", value } });
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
protected ASensor(JsonData json, Tuple<Int32, Types> id, HttpConnection http, Boolean polling) : base(http, polling) {
|
||||
this.SensorId = id.Item1;
|
||||
this.Sensorclass = id.Item2;
|
||||
this.ComplexInit(json);
|
||||
}
|
||||
|
||||
private void ComplexInit(JsonData json) {
|
||||
if (json.ContainsKey("name")) {
|
||||
this._name = json["name"].ToString();
|
||||
}
|
||||
if (json.ContainsKey("state")) {
|
||||
JsonData state = json["state"];
|
||||
if (state.ContainsKey("lastupdated") && state["lastupdated"].IsString) {
|
||||
this.Lastupdated = DateTime.Parse(state["lastupdated"].ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ASensor CreateInstanceConcrete(JsonData json, Tuple<Int32> id, HttpConnection http, Boolean polling) {
|
||||
String type = "";
|
||||
if (json.ContainsKey("type")) {
|
||||
type = json["type"].ToString().ToEnumString();
|
||||
}
|
||||
if (type != "" && !Enum.IsDefined(typeof(TypesIgnore), type) && Enum.IsDefined(typeof(Types), type)) {
|
||||
String name = "BlubbFish.IoT.Hue.Devices.Sensors." + type;
|
||||
return GetInstanceConcrete(name, json, new Tuple<Int32, Types>(id.Item1, (Types)Enum.Parse(typeof(Types), type)), http, polling);
|
||||
}
|
||||
if (!Enum.IsDefined(typeof(TypesIgnore), type) && !Enum.IsDefined(typeof(Types), type)) {
|
||||
Helper.WriteError("Sensorclass " + type + " not exist.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ASensor GetInstanceConcrete(String name, JsonData json, Tuple<Int32, Types> id, HttpConnection http, Boolean polling) {
|
||||
Type t = null;
|
||||
try {
|
||||
t = Type.GetType(name, true);
|
||||
} catch (TypeLoadException) {
|
||||
Helper.WriteError("Konnte Type " + name + " nicht laden!");
|
||||
return null;
|
||||
}
|
||||
return (ASensor)t.GetConstructor(new Type[] { typeof(JsonData), typeof(Tuple<Int32, Types>), typeof(HttpConnection), typeof(Boolean) }).Invoke(new Object[] { json, id, http, polling });
|
||||
}
|
||||
#endregion
|
||||
|
||||
protected void SetSensorAttribute(Dictionary<String, Object> dictionary) {
|
||||
this.PutDictionary("sensors/" + this.SensorId, dictionary);
|
||||
}
|
||||
|
||||
protected Boolean SetSensorConfig(Dictionary<String, Object> dictionary) {
|
||||
return this.PutDictionary("sensors/" + this.SensorId + "/config", dictionary);
|
||||
}
|
||||
|
||||
#region AConnector
|
||||
public override void SetUpdate(JsonData json) {
|
||||
if (json.ContainsKey("name") && json["name"].IsString) {
|
||||
if (this.Name != json["name"].ToString()) {
|
||||
this._name = json["name"].ToString();
|
||||
this.NotifyClient<SensorUpdateEvent>(this.Name);
|
||||
}
|
||||
}
|
||||
if (json.ContainsKey("state") && json["state"].ContainsKey("lastupdated") && json["state"]["lastupdated"].IsString) {
|
||||
if (this.Lastupdated != DateTime.Parse(json["state"]["lastupdated"].ToString())) {
|
||||
this.Lastupdated = DateTime.Parse(json["state"]["lastupdated"].ToString());
|
||||
this.NotifyClient<SensorUpdateEvent>(this.Lastupdated);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IMqtt
|
||||
public String MqttTopic() {
|
||||
return "groups/" + this.SensorId + "/" + this.Sensorclass.ToString();
|
||||
}
|
||||
|
||||
public String ToJson() {
|
||||
return JsonMapper.ToJson(this.ToDictionary());
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -5,8 +5,16 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BlubbFish.IoT.Hue.Interfaces {
|
||||
interface IMqtt {
|
||||
public interface IMqtt {
|
||||
/// <summary>
|
||||
/// Gibt einen JSON-String der Eigenschaften eines Objekts zurück
|
||||
/// </summary>
|
||||
/// <returns>JSON-String</returns>
|
||||
String ToJson();
|
||||
/// <summary>
|
||||
/// Gibt das MQTT-Topic als String zurück unter dem die Daten des Objekts Publiziert werden sollen
|
||||
/// </summary>
|
||||
/// <returns>MQTT-Topic</returns>
|
||||
String MqttTopic();
|
||||
}
|
||||
}
|
||||
|
BIN
Hue/bin/Release/Hue.dll
Normal file
BIN
Hue/bin/Release/Hue.dll
Normal file
Binary file not shown.
BIN
Hue/bin/Release/litjson.dll
Normal file
BIN
Hue/bin/Release/litjson.dll
Normal file
Binary file not shown.
@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Hue.lib {
|
||||
class Helper {
|
||||
@ -20,6 +22,34 @@ namespace BlubbFish.IoT.Hue.lib {
|
||||
return value.ToString();
|
||||
}
|
||||
}
|
||||
internal static Boolean HasInterface(Type o, String type) {
|
||||
foreach (Type item in o.GetInterfaces()) {
|
||||
if (item.Name == type) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void SetUpdate<T>(ReadOnlyDictionary<Int32, T> list, JsonData json, String key) {
|
||||
if (json.ContainsKey(key)) {
|
||||
foreach (String item in json[key].Keys) {
|
||||
if (list.ContainsKey(Int32.Parse(item))) {
|
||||
list[Int32.Parse(item)].GetType().GetMethod("SetUpdate").Invoke(list[Int32.Parse(item)], new Object[] { json[key][item] });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetUpdate<T>(ReadOnlyDictionary<String, T> list, JsonData json, String key) {
|
||||
if (json.ContainsKey(key)) {
|
||||
foreach (String item in json[key].Keys) {
|
||||
if (list.ContainsKey(item)) {
|
||||
list[item].GetType().GetMethod("SetUpdate").Invoke(list[item], new Object[] { json[key][item] });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static class StringHelper {
|
||||
public static String ToEnumString(this String text) {
|
||||
|
Loading…
Reference in New Issue
Block a user