Compare commits

2 Commits

Author SHA1 Message Date
Samuele Locatelli ea7a113b95 Aggiunto DTO decodifica 3EM gen1 2025-09-02 19:23:30 +02:00
Samuele Locatelli 139aaa86b8 Merge tag 'AddProxyShelly_07' into develop
Aggiunta metodo rilievo totale consumi
2025-08-07 08:41:59 +02:00
10 changed files with 427 additions and 0 deletions
@@ -0,0 +1,17 @@
using Newtonsoft.Json;
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
namespace EgwProxy.Shelly.DTO.Gen1
{
/// <summary>
/// Actions Stats
/// </summary>
public class ActionsStatsDto
{
[JsonProperty("skipped")]
public int Skipped { get; set; }
}
}
+19
View File
@@ -0,0 +1,19 @@
using Newtonsoft.Json;
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
namespace EgwProxy.Shelly.DTO.Gen1
{
/// <summary>
/// Cloud Info
/// </summary>
public class CloudInfoDto
{
[JsonProperty("enabled")]
public bool Enabled { get; set; }
[JsonProperty("connected")]
public bool Connected { get; set; }
}
}
+34
View File
@@ -0,0 +1,34 @@
using Newtonsoft.Json;
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
namespace EgwProxy.Shelly.DTO.Gen1
{
/// <summary>
/// EMeter Info
/// </summary>
public class EmeterInfoDto
{
[JsonProperty("power")]
public double PowerWatts { get; set; }
[JsonProperty("pf")]
public double PowerFactor { get; set; }
[JsonProperty("current")]
public double CurrentAmps { get; set; }
[JsonProperty("voltage")]
public double VoltageVolts { get; set; }
[JsonProperty("is_valid")]
public bool IsValid { get; set; }
[JsonProperty("total")]
public double TotalKWh { get; set; }
[JsonProperty("total_returned")]
public double TotalReturnedKWh { get; set; }
}
}
@@ -0,0 +1,26 @@
using Newtonsoft.Json;
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
namespace EgwProxy.Shelly.DTO.Gen1
{
/// <summary>
/// EMeter N Info
/// </summary>
public class EmeterNInfoDto
{
[JsonProperty("current")]
public double CurrentAmps { get; set; }
[JsonProperty("ixsum")]
public double Ixsum { get; set; }
[JsonProperty("mismatch")]
public bool Mismatch { get; set; }
[JsonProperty("is_valid")]
public bool IsValid { get; set; }
}
}
+16
View File
@@ -0,0 +1,16 @@
using Newtonsoft.Json;
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
namespace EgwProxy.Shelly.DTO.Gen1
{
/// <summary>
/// MQTT Info
/// </summary>
public class MqttInfoDto
{
[JsonProperty("connected")]
public bool Connected { get; set; }
}
}
+37
View File
@@ -0,0 +1,37 @@
using Newtonsoft.Json;
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
namespace EgwProxy.Shelly.DTO.Gen1
{
/// <summary>
/// Relay Info
/// </summary>
public class RelayInfoDto
{
[JsonProperty("ison")]
public bool IsOn { get; set; }
[JsonProperty("has_timer")]
public bool HasTimer { get; set; }
[JsonProperty("timer_started")]
public int TimerStarted { get; set; }
[JsonProperty("timer_duration")]
public int TimerDuration { get; set; }
[JsonProperty("timer_remaining")]
public int TimerRemaining { get; set; }
[JsonProperty("overpower")]
public bool Overpower { get; set; }
[JsonProperty("is_valid")]
public bool IsValid { get; set; }
[JsonProperty("source")]
public string Source { get; set; } = string.Empty;
}
}
@@ -0,0 +1,214 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
namespace EgwProxy.Shelly.DTO.Gen1
{
/// <summary>
/// Represents the status response from a Shelly 3EM device.
/// This class maps the JSON structure returned by the Shelly 3EM REST API.
/// </summary>
public class Shelly3EMStatusDto
{
/// <summary>
/// Wi-Fi station configuration (connected status, SSID, IP, RSSI)
/// </summary>
[JsonProperty("wifi_sta")]
public WifiStationInfoDto WifiStation { get; set; }
/// <summary>
/// Cloud connectivity status (enabled and connected)
/// </summary>
[JsonProperty("cloud")]
public CloudInfoDto Cloud { get; set; }
/// <summary>
/// MQTT connectivity status
/// </summary>
[JsonProperty("mqtt")]
public MqttInfoDto Mqtt { get; set; }
/// <summary>
/// Current time in HH:MM format (e.g., "15:19")
/// </summary>
[JsonProperty("time")]
public string Time { get; set; } = string.Empty;
/// <summary>
/// Unix timestamp (seconds since epoch)
/// </summary>
[JsonProperty("unixtime")]
public long UnixTime { get; set; }
/// <summary>
/// Device serial number (unique ID)
/// </summary>
[JsonProperty("serial")]
public int Serial { get; set; }
/// <summary>
/// Whether an update is available (true = update available)
/// </summary>
[JsonProperty("has_update")]
public bool HasUpdate { get; set; }
/// <summary>
/// MAC address of the device
/// </summary>
[JsonProperty("mac")]
public string Mac { get; set; } = string.Empty;
/// <summary>
/// Number of configuration changes since boot
/// </summary>
[JsonProperty("cfg_changed_cnt")]
public int CfgChangedCount { get; set; }
/// <summary>
/// Actions statistics (e.g., how many actions were skipped)
/// </summary>
[JsonProperty("actions_stats")]
public ActionsStatsDto ActionsStats { get; set; }
/// <summary>
/// Array of relay states (e.g., on/off, timer, overpower)
/// </summary>
[JsonProperty("relays")]
public List<RelayInfoDto> Relays { get; set; } = new List<RelayInfoDto>();
/// <summary>
/// Array of emeter readings (each emeter has power, current, voltage, total energy)
/// </summary>
[JsonProperty("emeters")]
public List<EmeterInfoDto> Emeters { get; set; } = new List<EmeterInfoDto>();
/// <summary>
/// Total power consumption across all emeters (in watts)
/// </summary>
[JsonProperty("total_power")]
public double TotalPower { get; set; }
/// <summary>
/// EMeter N data (e.g., current, ixsum, mismatch)
/// </summary>
[JsonProperty("emeter_n")]
public EmeterNInfoDto EmeterN { get; set; }
/// <summary>
/// Whether filesystem is mounted (true = mounted)
/// </summary>
[JsonProperty("fs_mounted")]
public bool Fsmounted { get; set; }
/// <summary>
/// Version data (v_data = 1 means normal operation)
/// </summary>
[JsonProperty("v_data")]
public int VData { get; set; }
/// <summary>
/// Calibration timestamp (0 = not set)
/// </summary>
[JsonProperty("ct_calst")]
public int CTCalst { get; set; }
/// <summary>
/// Update information (status, versions)
/// </summary>
[JsonProperty("update")]
public UpdateInfoDto Update { get; set; }
/// <summary>
/// RAM total (in KB)
/// </summary>
[JsonProperty("ram_total")]
public int RamTotal { get; set; }
/// <summary>
/// RAM free (in KB)
/// </summary>
[JsonProperty("ram_free")]
public int RamFree { get; set; }
/// <summary>
/// Filesystem size (in KB)
/// </summary>
[JsonProperty("fs_size")]
public int Fssize { get; set; }
/// <summary>
/// Filesystem free space (in KB)
/// </summary>
[JsonProperty("fs_free")]
public int FsFree { get; set; }
/// <summary>
/// Uptime in seconds (e.g., 336276 seconds = ~93.4 hours)
/// </summary>
[JsonProperty("uptime")]
public int Uptime { get; set; }
/// <summary>
/// Converts Unix timestamp to a DateTime object
/// </summary>
/// <returns>UTC DateTime</returns>
public DateTime GetDateTimeFromUnixTime()
{
return DateTimeOffset.FromUnixTimeSeconds(UnixTime).UtcDateTime;
}
/// <summary>
/// Gets total power consumption in watts (from emeters)
/// </summary>
/// <returns>Sum of all emeter powers</returns>
public double GetTotalPowerFromEmeters()
{
return Emeters.Sum(emeter => emeter.PowerWatts);
}
/// <summary>
/// Gets total energy consumption in kWh (sum of total values)
/// </summary>
/// <returns>Total kWh across all emeters</returns>
public double GetTotalEnergyKWh()
{
return Emeters.Sum(emeter => emeter.TotalKWh);
}
/// <summary>
/// Checks if the device is connected to Wi-Fi and cloud
/// </summary>
/// <returns>True if both Wi-Fi and cloud are connected</returns>
public bool IsConnected()
{
return WifiStation?.Connected == true &&
Cloud?.Connected == true &&
!string.IsNullOrEmpty(WifiStation?.Ssid);
}
/// <summary>
/// Checks if the device has an available update
/// </summary>
/// <returns>True if update is available</returns>
public bool HasAvailableUpdate()
{
return Update?.HasUpdate == true;
}
/// <summary>
/// Returns the current time as a formatted string (HH:mm)
/// </summary>
/// <returns>Formatted time string</returns>
public string GetFormattedTime()
{
if (string.IsNullOrEmpty(Time))
return "N/A";
return Time;
}
}
}
+29
View File
@@ -0,0 +1,29 @@
using Newtonsoft.Json;
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
namespace EgwProxy.Shelly.DTO.Gen1
{
/// <summary>
/// Update Info
/// </summary>
public class UpdateInfoDto
{
[JsonProperty("status")]
public string Status { get; set; } = string.Empty;
[JsonProperty("has_update")]
public bool HasUpdate { get; set; }
[JsonProperty("new_version")]
public string NewVersion { get; set; } = string.Empty;
[JsonProperty("old_version")]
public string OldVersion { get; set; } = string.Empty;
[JsonProperty("beta_version")]
public string BetaVersion { get; set; } = string.Empty;
}
}
@@ -0,0 +1,26 @@
using Newtonsoft.Json;
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
namespace EgwProxy.Shelly.DTO.Gen1
{
/// <summary>
/// Wi-Fi Station Info
/// </summary>
public class WifiStationInfoDto
{
[JsonProperty("connected")]
public bool Connected { get; set; }
[JsonProperty("ssid")]
public string Ssid { get; set; } = string.Empty;
[JsonProperty("ip")]
public string Ip { get; set; } = string.Empty;
[JsonProperty("rssi")]
public int Rssi { get; set; }
}
}
+9
View File
@@ -92,6 +92,15 @@
<Compile Include="Converters\EMDtoConverter.cs" /> <Compile Include="Converters\EMDtoConverter.cs" />
<Compile Include="DTO\BaseServiceDto.cs" /> <Compile Include="DTO\BaseServiceDto.cs" />
<Compile Include="DTO\CloudDto.cs" /> <Compile Include="DTO\CloudDto.cs" />
<Compile Include="DTO\Gen1\ActionsStatsDto.cs" />
<Compile Include="DTO\Gen1\CloudInfoDto.cs" />
<Compile Include="DTO\Gen1\EmeterInfoDto.cs" />
<Compile Include="DTO\Gen1\EmeterNInfoDto.cs" />
<Compile Include="DTO\Gen1\MqttInfoDto.cs" />
<Compile Include="DTO\Gen1\RelayInfoDto.cs" />
<Compile Include="DTO\Gen1\Shelly3EMStatusDto.cs" />
<Compile Include="DTO\Gen1\UpdateInfoDto.cs" />
<Compile Include="DTO\Gen1\WifiStationInfoDto.cs" />
<Compile Include="DTO\Gen2\EMDataDto.cs" /> <Compile Include="DTO\Gen2\EMDataDto.cs" />
<Compile Include="DTO\Gen2\EMDto.cs" /> <Compile Include="DTO\Gen2\EMDto.cs" />
<Compile Include="DTO\Gen2\EnergyDto.cs" /> <Compile Include="DTO\Gen2\EnergyDto.cs" />