[NF] Huebot fertig

[NF] Huebot nutzt nun die lokale litjosn und mqtt library
This commit is contained in:
2018-05-02 16:21:34 +00:00
parent bc694f2fd9
commit dc418934e2
12 changed files with 33 additions and 13 deletions
+6
View File
@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConnectorDataMqtt", "..\Uti
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils-IoT", "..\Utils\IoT\Utils-IoT.csproj", "{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "M2Mqtt", "..\Librarys\mqtt\M2Mqtt\M2Mqtt.csproj", "{A11AEF5A-B246-4FE8-8330-06DB73CC8074}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -45,6 +47,10 @@ Global
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B870E4D5-6806-4A0B-B233-8907EEDC5AFC}.Release|Any CPU.Build.0 = Release|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A11AEF5A-B246-4FE8-8330-06DB73CC8074}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
-3
View File
@@ -74,9 +74,6 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
+21 -10
View File
@@ -41,15 +41,26 @@ namespace BlubbFish.IoT.Bot.HueBot.Moduls {
private void Mqtt_MessageIncomming(Object sender, MqttEventArgs e) {
if (e.Topic.StartsWith("/hue/") && (e.Topic.EndsWith("/set") || e.Topic.EndsWith("/get"))) {
/*Match m = new Regex("^/zwavebot/devices/(\\d+)/(\\d+)/(\\d+)/[gs]et$|^/zwavebot/devices/(\\d+)/(\\d+)/(\\d+)/(\\d+)/[gs]et$").Match(e.Topic);
//return "sensor/" + this.SensorId; (Int32)
//return "scene/" + this.SceneId; (String)
//return "light/" + this.LightId; (Int32)
//return "group/" + this.GroupId; (Int32)
//return "config";
Match m = new Regex("^/hue/(config)/[gs]et$|^/hue/(scene)/([^/]+)/[gs]et$|^/hue/(sensor|light|group)/(\\d+)/[gs]et$").Match(e.Topic);
String type = "";
String id = "";
if (m.Groups[1].Success) {
id = m.Groups[1].Value + "-" + m.Groups[2].Value + "-" + m.Groups[3].Value;
type = m.Groups[1].Value;
}
if (m.Groups[2].Success) {
type = m.Groups[2].Value;
id = m.Groups[3].Value;
}
if (m.Groups[4].Success) {
id = m.Groups[4].Value + "-" + m.Groups[5].Value + "-" + m.Groups[6].Value + "-" + m.Groups[7].Value;
type = m.Groups[4].Value;
id = m.Groups[5].Value;
}
ACommandClass c = this.zw.GetCommandClass(id);
AConnector c = this.hue.GetConnector(type, id);
if (c == null) {
return;
}
@@ -60,18 +71,18 @@ namespace BlubbFish.IoT.Bot.HueBot.Moduls {
String key = item.ToUpperLower();
if (c.HasProperty(key)) {
c.SetProperty(key, a[item].ToString());
this.Update?.Invoke(this, new MqttEvent(c.Id, a[item].ToString()));
this.Update?.Invoke(this, new MqttEvent(type + " " + id, a[item].ToString()));
}
}
} catch (Exception) { }
} else if (e.Topic.EndsWith("/get")) {
c.PollOnce = true;
this.mqtt.Send("/zwavebot/devices/" + c.MqttTopic(), c.ToJson());
this.mqtt.Send("/hue/" + ((IMqtt)c).MqttTopic(), ((IMqtt)c).ToJson());
this.Update?.Invoke(this, new MqttEvent(e.Topic, "Dataget"));
}*/
}
if (e.Topic.StartsWith("/hue/config/") && (e.Topic.EndsWith("/set") || e.Topic.EndsWith("/get"))) {
Match m = new Regex("^/hue/config/(\\w+)/[gs]et$|").Match(e.Topic);
}
if (e.Topic.StartsWith("/huebot/config/") && (e.Topic.EndsWith("/set") || e.Topic.EndsWith("/get"))) {
Match m = new Regex("^/huebot/config/(\\w+)/[gs]et$|").Match(e.Topic);
if (!m.Groups[1].Success) {
return;
}
@@ -85,7 +96,7 @@ namespace BlubbFish.IoT.Bot.HueBot.Moduls {
return;
}
if (e.Topic.EndsWith("/get") && modul.HasConfig && modul.ConfigPublic) {
String topic = "/hue/config/" + m.Groups[1].Value;
String topic = "/huebot/config/" + m.Groups[1].Value;
String data = JsonMapper.ToJson(modul.GetConfig()).ToString();
this.mqtt.Send(topic, data);
this.Update?.Invoke(this, new MqttEvent(topic, data));
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+6
View File
@@ -8,6 +8,8 @@ namespace BlubbFish.IoT.Bot.HueBot.lib {
if (prop.CanWrite) {
if (prop.PropertyType == typeof(Boolean) && Boolean.TryParse(value, out Boolean vb)) {
prop.SetValue(o, vb);
} else if (prop.PropertyType == typeof(Byte) && Byte.TryParse(value, out Byte v8)) {
prop.SetValue(o, v8);
} else if (prop.PropertyType == typeof(Int32) && Int32.TryParse(value, out Int32 v32)) {
prop.SetValue(o, v32);
} else if (prop.PropertyType == typeof(Single) && Single.TryParse(value, out Single vs)) {
@@ -16,6 +18,10 @@ namespace BlubbFish.IoT.Bot.HueBot.lib {
prop.SetValue(o, vd);
} else if (prop.PropertyType == typeof(Int64) && Int64.TryParse(value, out Int64 v64)) {
prop.SetValue(o, v64);
} else if (prop.PropertyType.BaseType == typeof(Enum)) {
try {
prop.SetValue(o, Enum.Parse(prop.PropertyType, value));
} catch (Exception) { }
}
}
}