2017-09-26 20:21:42 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
2017-10-02 18:32:06 +02:00
|
|
|
|
using BlubbFish.Utils.IoT.Connector;
|
2017-09-26 20:21:42 +02:00
|
|
|
|
using LitJson;
|
|
|
|
|
|
2017-10-02 18:32:06 +02:00
|
|
|
|
namespace BlubbFish.Utils.IoT.Sensor {
|
2017-09-26 20:21:42 +02:00
|
|
|
|
class Flex4gridpower : ASensor {
|
|
|
|
|
private String id;
|
|
|
|
|
|
|
|
|
|
public Flex4gridpower(Dictionary<String, String> settings, String name, ADataBackend backend) : base(settings, name, backend) {
|
|
|
|
|
this.Datatypes = Types.Float;
|
|
|
|
|
this.id = settings["id"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Boolean UpdateValue(MqttEventArgs e) {
|
|
|
|
|
CultureInfo info = new CultureInfo("de-DE");
|
|
|
|
|
info.NumberFormat.NumberDecimalSeparator = ".";
|
|
|
|
|
CultureInfo.DefaultThreadCurrentCulture = info;
|
|
|
|
|
CultureInfo.DefaultThreadCurrentUICulture = info;
|
|
|
|
|
System.Threading.Thread.CurrentThread.CurrentCulture = info;
|
|
|
|
|
System.Threading.Thread.CurrentThread.CurrentUICulture = info;
|
|
|
|
|
try {
|
|
|
|
|
JsonData data = JsonMapper.ToObject(e.Message);
|
|
|
|
|
if(data["id"].ToString() == this.id) {
|
|
|
|
|
this.GetFloat = Single.Parse(data["power"].ToString());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception) {
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|