61 lines
2.2 KiB
C#
61 lines
2.2 KiB
C#
// Decompiled with JetBrains decompiler
|
|
// Type: FritzBox.GetValue
|
|
// Assembly: FritzBox, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
|
|
// MVID: DC9FD63C-0A96-43D7-A76E-0506FEB07200
|
|
// Assembly location: \\192.168.178.26\Freigabe\FritzBox.dll
|
|
|
|
using Sensormat;
|
|
using Sensormat.Entities;
|
|
using System;
|
|
|
|
#nullable disable
|
|
namespace FritzBox
|
|
{
|
|
public class GetValue : ISensor
|
|
{
|
|
private Config cfg;
|
|
|
|
public override bool Execute()
|
|
{
|
|
try
|
|
{
|
|
this.cfg = this.getConfiguration<Config>();
|
|
string webContent = new FritzBox.API.FritzWebAccess.FritzWebAccess(this.cfg.UserName, this.cfg.Password)
|
|
{
|
|
Address = new Uri(this.Sensor.URL)
|
|
}.GetWebContent("webservices/homeautoswitch.lua", "&ain=" + this.cfg.AIN + "&switchcmd=getdeviceinfos");
|
|
if (webContent != null)
|
|
{
|
|
GetDeviceInfoResponse deviceInfoResponse = webContent.XMLDeserializeData<GetDeviceInfoResponse>();
|
|
if (deviceInfoResponse != null)
|
|
{
|
|
this.LastValueDate = new DateTime?(DateTime.Now);
|
|
switch (this.cfg.Property?.ToLower())
|
|
{
|
|
case "power":
|
|
this.LastValue = deviceInfoResponse.Powermeter?.Power.ToString();
|
|
break;
|
|
case "energy":
|
|
this.LastValue = deviceInfoResponse.Powermeter?.Energy.ToString();
|
|
break;
|
|
default:
|
|
this.LastValue = "property " + this.cfg.Property + " unknown";
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
this.ErrorMsg = "empty result";
|
|
}
|
|
else
|
|
this.ErrorMsg = "response is empty";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine((object)ex);
|
|
this.ErrorMsg = ex.Message;
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
}
|