Merge branch 'release/AddProxyShelly_06'

This commit is contained in:
Samuele Locatelli
2025-08-06 18:40:15 +02:00
28 changed files with 852 additions and 31 deletions
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
</configuration>
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A5DDEF7B-98C3-4391-B8BC-16CFC469B77E}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>EgwProxy.Emmegi.Test</RootNamespace>
<AssemblyName>EgwProxy.Emmegi.Test</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\EgwProxy.Emmegi\EgwProxy.Emmegi.csproj">
<Project>{f3c0f746-b4fb-4cbb-92bd-9c9a686a21bb}</Project>
<Name>EgwProxy.Emmegi</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
+53
View File
@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EgwProxy.Emmegi.Test
{
internal class Program
{
static void Main(string[] args)
{
string linea = "-----------------------------";
Console.WriteLine(linea);
Console.WriteLine("Test comunicazione Emmegi");
Console.WriteLine(linea);
Console.WriteLine();
string escimi = "N";
EgwProxy.Emmegi.CallManager EmmegiMan = new CallManager("http://192.168.100.59", 8090, "C129696");
Console.WriteLine("Premere un tasto per iniziare test.");
escimi = Console.ReadLine().ToUpper();
int idxReq = 10;
// lettura
while (escimi != "E")
{
string output = "";
Console.WriteLine("Cosa vuoi fare ora? S = Status, E = Uscita");
escimi = Console.ReadLine().ToUpper();
DateTime adesso = DateTime.Now;
// invio pesata
if (escimi == "S")
{
try
{
var answ = EmmegiMan.GetCurrentStatus();
output = $"Dt: {answ.Workstation.StatusTimestamp} | WrkId: {answ.Workstation.Id.IdValue} | Operatore: {answ.Workstation.Operator} | Job: {answ.Workstation.JobId} | Status: {answ.Workstation.Status} | # Tagli Job: {answ.Workstation.Operations} | # Tot Tagli: {answ.Workstation.TotalOperations}";
Console.WriteLine(output);
Console.WriteLine();
}
catch (Exception exc)
{
Console.WriteLine($"Errore:{Environment.NewLine}{exc}");
}
}
}
}
}
}
@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("EgwProxy.Emmegi.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EgwProxy.Emmegi.Test")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a5ddef7b-98c3-4391-b8bc-16cfc469b77e")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
+31
View File
@@ -0,0 +1,31 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32630.192
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EgwProxy.Emmegi", "EgwProxy.Emmegi\EgwProxy.Emmegi.csproj", "{F3C0F746-B4FB-4CBB-92BD-9C9A686A21BB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EgwProxy.Emmegi.Test", "EgwProxy.Emmegi.Test\EgwProxy.Emmegi.Test.csproj", "{A5DDEF7B-98C3-4391-B8BC-16CFC469B77E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F3C0F746-B4FB-4CBB-92BD-9C9A686A21BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F3C0F746-B4FB-4CBB-92BD-9C9A686A21BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F3C0F746-B4FB-4CBB-92BD-9C9A686A21BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F3C0F746-B4FB-4CBB-92BD-9C9A686A21BB}.Release|Any CPU.Build.0 = Release|Any CPU
{A5DDEF7B-98C3-4391-B8BC-16CFC469B77E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A5DDEF7B-98C3-4391-B8BC-16CFC469B77E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A5DDEF7B-98C3-4391-B8BC-16CFC469B77E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A5DDEF7B-98C3-4391-B8BC-16CFC469B77E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DA96981F-F7D0-47A9-A51F-9BCC8D35619F}
EndGlobalSection
EndGlobal
+57
View File
@@ -0,0 +1,57 @@
using EgwProxy.Emmegi.DTO;
using System;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace EgwProxy.Emmegi
{
public class CallManager
{
public CallManager(string baseUrl, int port, string workstationId)
{
BaseUrl = baseUrl;
Port= port;
WorkstationId = workstationId;
}
/// <summary>
/// restituisce stato impianto nel formato specifico
/// </summary>
/// <returns></returns>
public StatusDTO GetCurrentStatus()
{
StatusDTO answ = new StatusDTO();
// chiamo
string xmlRaw = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<result_workstation_status>
<workstation>
<id id=""C129696"" />
<status>ON</status>
<status_timestamp>2025-07-10 11:30:31</status_timestamp>
<operator>unknown</operator>
<job_id>TAGLIO SINGOLO</job_id>
<operations>194312</operations>
<tot_operations>194312</tot_operations>
</workstation>
</result_workstation_status>";
// deserializzo
var serializer = new XmlSerializer(typeof(StatusDTO));
using (var reader = new StringReader(xmlRaw))
{
answ = (StatusDTO)serializer.Deserialize(reader);
}
return answ;
}
private string BaseUrl = "";
private int Port = 0;
private string WorkstationId = "";
}
}
+64
View File
@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace EgwProxy.Emmegi.DTO
{
[XmlRoot("result_workstation_status")]
public class StatusDTO
{
[XmlElement("workstation")]
public Workstation Workstation { get; set; }
}
/// <summary>
/// Obj workstation
/// </summary>
public class Workstation
{
[XmlElement("id")]
public WorkstationId Id { get; set; }
[XmlElement("status")]
public Enums.MachineStatus Status { get; set; }
[XmlElement("status_timestamp")]
public string StatusTimestampRaw { get; set; }
[XmlIgnore]
public DateTime StatusTimestamp
{
get => DateTime.ParseExact(StatusTimestampRaw, "yyyy-MM-dd HH:mm:ss", null);
}
[XmlElement("operator")]
public string Operator { get; set; }
[XmlElement("job_id")]
public string JobId { get; set; }
[XmlElement("operations")]
public int Operations { get; set; }
[XmlElement("tot_operations")]
public int TotalOperations { get; set; }
}
/// <summary>
/// Obj WorkstationId
/// </summary>
public class WorkstationId
{
[XmlAttribute("id")]
public string IdValue { get; set; }
}
}
+50
View File
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F3C0F746-B4FB-4CBB-92BD-9C9A686A21BB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>EgwProxy.Emmegi</RootNamespace>
<AssemblyName>EgwProxy.Emmegi</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CallManager.cs" />
<Compile Include="DTO\StatusDTO.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Enums.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
+22
View File
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EgwProxy.Emmegi
{
public class Enums
{
public enum MachineStatus
{
ON,
WORKING,
OFF_LINE,
OFF,
WAIT,
ERROR
}
}
}
@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("EgwProxy.Emmegi")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EgwProxy.Emmegi")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f3c0f746-b4fb-4cbb-92bd-9c9a686a21bb")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -54,6 +54,15 @@
<ItemGroup>
<None Include="App.config" />
<None Include="conf\.placeholder" />
<None Include="conf\testSetup_73.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="conf\testSetup_72.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="conf\testSetup_71.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="conf\testSetup.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
+60 -25
View File
@@ -1,10 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using EgwProxy.Shelly.Clients;
@@ -44,10 +41,15 @@ namespace EgwProxy.Shelly.Test
return answ;
}
////APC
//private string shellyAddr = "10.74.81.71";
//// caffè
//private string shellyAddr = "10.74.81.72";
//APC
private string shellyAddr = "10.74.81.71";
//private string model = "Pm1";
////3EM Trifase
//private string shellyAddr = "10.74.81.73";
//private string model = "Pro3Em";
/// <summary>
/// Programma principale
@@ -60,7 +62,7 @@ namespace EgwProxy.Shelly.Test
Console.WriteLine(separator);
Console.WriteLine();
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
string BaseDirectory = System.IO.Path.GetDirectoryName(exePath);
string BaseDirectory = Path.GetDirectoryName(exePath);
string testFile = Path.Combine(BaseDirectory, "conf", ReadSetting("testFile"));
if (!string.IsNullOrEmpty(testFile))
{
@@ -86,9 +88,25 @@ namespace EgwProxy.Shelly.Test
DefaultTimeout = TimeSpan.FromSeconds(testConf.tOutSec),
ServerUri = new Uri($"http://{testConf.devAddr}/rpc")
};
Shelly1PmClient shelly = new Shelly1PmClient(new HttpClient(), options);
// test chiamata completa
serverTest(shelly);
Shelly1PmClient shelly1PM = new Shelly1PmClient(new HttpClient(), options);
ShellyPro3EmClient shellyPro3 = new ShellyPro3EmClient(new HttpClient(), options);
switch (testConf.model)
{
case shellyModel.nd:
break;
case shellyModel.gen1:
// test chiamata completa
serverTest(shelly1PM);
break;
case shellyModel.gen2:
// test chiamata completa
serverTest(shellyPro3);
break;
default:
break;
}
bool doRepeat = true;
while (doRepeat)
{
@@ -106,25 +124,19 @@ namespace EgwProxy.Shelly.Test
switch (item.action)
{
case stepType.getFullStatus:
var respFull = Task.Run(() => shelly.GetStatus(CancellationToken.None)).Result;
var respFull = Task.Run(() => shelly1PM.GetStatus(CancellationToken.None)).Result;
if (respFull.IsSuccess)
{
esitoStep = JsonConvert.SerializeObject(respFull.Value, Formatting.Indented);
}
else
{
esitoStep = "Errore in GetStatus";
string serValFull = JsonConvert.SerializeObject(respFull.Value, Formatting.Indented);
esitoStep = respFull.IsSuccess ? serValFull : "Errore in GetStatus";
}
break;
case stepType.getSwitchStatus:
var respSwitch = Task.Run(() => shelly.GetSwitchStatus(CancellationToken.None, 0)).Result;
var respSwitch = Task.Run(() => shellyPro3.GetEmStatus(CancellationToken.None)).Result;
if (respSwitch.IsSuccess)
{
esitoStep = JsonConvert.SerializeObject(respSwitch.Value, Formatting.Indented);
}
else
{
esitoStep = "Errore in GetSwitchStatus";
string serValSwitch = JsonConvert.SerializeObject(respSwitch.Value, Formatting.Indented);
esitoStep = respSwitch.IsSuccess ? serValSwitch : "Errore in GetEmStatus";
}
break;
default:
@@ -157,17 +169,40 @@ namespace EgwProxy.Shelly.Test
// registro ed eseguo chiamata in modalità sincrona
sw.Restart();
var response = Task.Run(() => shellyClient.GetStatus(CancellationToken.None)).Result;
sw.Stop();
Console.WriteLine($"CallSuccess: {response.IsSuccess}");
if (response.Value != null)
if (response.IsSuccess)
{
string serVal = JsonConvert.SerializeObject(response.Value, Formatting.Indented);
sw.Stop();
writeResult(response.IsSuccess, serVal);
}
}
private static void writeResult(bool isSuccess, string serVal)
{
Console.WriteLine($"CallSuccess: {isSuccess}");
if (!string.IsNullOrEmpty(serVal))
{
Console.WriteLine(separator);
Console.WriteLine(JsonConvert.SerializeObject(response.Value, Formatting.Indented));
Console.WriteLine(serVal);
Console.WriteLine(separator);
Console.WriteLine($"Elapsed: {sw.Elapsed.TotalMilliseconds:N3}ms");
Console.WriteLine(separator);
Console.WriteLine();
}
}
private static void serverTest(ShellyPro3EmClient shellyClient)
{
Console.WriteLine(separator);
// registro ed eseguo chiamata in modalità sincrona
sw.Restart();
var response = Task.Run(() => shellyClient.GetStatus(CancellationToken.None)).Result;
if (response.IsSuccess)
{
string serVal = JsonConvert.SerializeObject(response.Value, Formatting.Indented);
sw.Stop();
writeResult(response.IsSuccess, serVal);
}
}
}
}
+8
View File
@@ -9,6 +9,7 @@ namespace EgwProxy.Shelly.Test
public class TestSetup
{
public string devAddr { get; set; } = "";
public shellyModel model { get; set; } = shellyModel.nd;
public int tOutSec{ get; set; } = 5;
public List<singleStep> steps { get; set; }
}
@@ -33,4 +34,11 @@ namespace EgwProxy.Shelly.Test
getSwitchStatus
}
public enum shellyModel
{
nd,
gen1,
gen2
}
}
+2 -1
View File
@@ -1,5 +1,6 @@
{
"devAddr": "10.74.81.71",
"devAddr": "10.74.81.73",
"model": "gen2",
"steps": [
{
"id": "01",
@@ -0,0 +1,14 @@
{
"devAddr": "10.74.81.71",
"model": "gen1",
"steps": [
{
"id": "01",
"description": "Test SwitchStatus",
"action": "getSwitchStatus",
"numRep": 5,
"waitTime": 500,
"paramList": []
}
]
}
@@ -0,0 +1,14 @@
{
"devAddr": "10.74.81.72",
"model": "gen1",
"steps": [
{
"id": "01",
"description": "Test SwitchStatus",
"action": "getSwitchStatus",
"numRep": 5,
"waitTime": 500,
"paramList": []
}
]
}
@@ -0,0 +1,14 @@
{
"devAddr": "10.74.81.73",
"model": "gen2",
"steps": [
{
"id": "01",
"description": "Test SwitchStatus",
"action": "getSwitchStatus",
"numRep": 5,
"waitTime": 500,
"paramList": []
}
]
}
+12
View File
@@ -0,0 +1,12 @@
using EgwProxy.Shelly.DTO;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace EgwProxy.Shelly.Clients
{
public interface IShellyPro3Em
{
Task<ShellyResult<ShellyGen2StatusDto>> GetStatus(CancellationToken cancellationToken, TimeSpan? timeout = null);
}
}
@@ -0,0 +1,55 @@
using EgwProxy.Shelly.Converters;
using EgwProxy.Shelly.DTO;
using EgwProxy.Shelly.DTO.Gen2;
using EgwProxy.Shelly.Options;
using Flurl;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
namespace EgwProxy.Shelly.Clients
{
public class ShellyPro3EmClient : ShellyClientBase, IShellyPro3Em
{
public ShellyPro3EmClient(HttpClient httpClient, Shelly1PmOptions shellyOptions) : base(httpClient, shellyOptions)
{
}
public async Task<ShellyResult<ShellyGen2StatusDto>> GetStatus(CancellationToken cancellationToken, TimeSpan? timeout = null)
{
var endpoint = ServerUri.AppendPathSegment("Shelly.GetStatus");
var requestMessage = new HttpRequestMessage(HttpMethod.Get, endpoint);
return await ExecuteRequestAsync<ShellyGen2StatusDto>(requestMessage, cancellationToken, timeout);
}
public async Task<ShellyResult<EnergyDto>> GetEmStatus(CancellationToken cancellationToken, TimeSpan? timeout = null)
{
var endpoint = ServerUri.AppendPathSegment("EM.GetStatus?id=0");
var requestMessage = new HttpRequestMessage(HttpMethod.Get, endpoint);
return await ExecuteRequestAsync<EnergyDto>(requestMessage, cancellationToken, timeout);
}
#if false
public async Task<ShellyResult<DTO.Shelly1PM.SwitchDto>> GetSwitchStatus(CancellationToken cancellationToken, int id, TimeSpan? timeout = null)
{
var endpoint = ServerUri.AppendPathSegment("Switch.GetStatus").AppendQueryParam("id", id);
var requestMessage = new HttpRequestMessage(HttpMethod.Get, endpoint);
return await ExecuteRequestAsync<DTO.Shelly1PM.SwitchDto>(requestMessage, cancellationToken, timeout);
}
#endif
protected override async Task<ShellyResult<T>> HandleOkResponse<T>(HttpResponseMessage response)
{
var readAsStringAsync = await response.Content.ReadAsStringAsync();
var settings = new JsonSerializerSettings
{
Converters = new List<JsonConverter> { new EnergyDtoConverter() }
};
var shelly1Status = JsonConvert.DeserializeObject<T>(readAsStringAsync, settings);
return ShellyResult<T>.Success(shelly1Status, readAsStringAsync);
}
}
}
@@ -0,0 +1,66 @@
using EgwProxy.Shelly.DTO.Gen2;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EgwProxy.Shelly.Converters
{
public class EnergyDtoConverter : JsonConverter<EnergyDto>
{
public override EnergyDto ReadJson(JsonReader reader, Type objectType, EnergyDto existingValue, bool hasExistingValue, JsonSerializer serializer)
{
JObject obj = JObject.Load(reader);
var dto = new EnergyDto
{
Id = (int)obj["id"],
NeutralCurrent = obj["n_current"]?.ToObject<double?>() ?? 0,
TotalCurrent = (double)obj["total_current"],
TotalActivePower = (double)obj["total_act_power"],
TotalApparentPower = (double)obj["total_aprt_power"],
UserCalibratedPhase = obj["user_calibrated_phase"]?.ToObject<List<double>>() ?? new List<double>()
};
dto.PhaseA = new PhaseDataDto
{
Current = (double)obj["a_current"],
Voltage = (double)obj["a_voltage"],
ActivePower = (double)obj["a_act_power"],
ApparentPower = (double)obj["a_aprt_power"],
PowerFactor = (double)obj["a_pf"],
Frequency = (double)obj["a_freq"]
};
dto.PhaseB = new PhaseDataDto
{
Current = (double)obj["b_current"],
Voltage = (double)obj["b_voltage"],
ActivePower = (double)obj["b_act_power"],
ApparentPower = (double)obj["b_aprt_power"],
PowerFactor = (double)obj["b_pf"],
Frequency = (double)obj["b_freq"]
};
dto.PhaseC = new PhaseDataDto
{
Current = (double)obj["c_current"],
Voltage = (double)obj["c_voltage"],
ActivePower = (double)obj["c_act_power"],
ApparentPower = (double)obj["c_aprt_power"],
PowerFactor = (double)obj["c_pf"],
Frequency = (double)obj["c_freq"]
};
return dto;
}
public override void WriteJson(JsonWriter writer, EnergyDto value, JsonSerializer serializer)
{
throw new NotImplementedException("Serialization not implemented");
}
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
using Newtonsoft.Json;
namespace EgwProxy.Shelly.DTO.Shelly1PM
namespace EgwProxy.Shelly.DTO
{
public class BaseServiceDto
{
+47
View File
@@ -0,0 +1,47 @@
using Newtonsoft.Json;
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
namespace EgwProxy.Shelly.DTO.Gen1
{
/// <summary>
/// Discover for Gen1 Shelly Dev
/// </summary>
public class DiscoverDTO
{
#region Public Properties
[JsonProperty("auth")]
public bool Auth { get; set; }
[JsonProperty("discoverable")]
public bool Discoverable { get; set; }
[JsonProperty("fw")]
public string Fw { get; set; }
[JsonProperty("longid")]
public int Longid { get; set; }
[JsonProperty("mac")]
public string Mac { get; set; }
[JsonProperty("num_emeters")]
public int NumEmeters { get; set; }
[JsonProperty("num_meters")]
public int NumMeters { get; set; }
[JsonProperty("num_outputs")]
public int NumOutputs { get; set; }
[JsonProperty("report_period")]
public int ReportPeriod { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
#endregion Public Properties
}
}
+53
View File
@@ -0,0 +1,53 @@
using Newtonsoft.Json;
// <Auto-Generated>
// This is here so CodeMaid doesn't reorganize this document
// </Auto-Generated>
namespace EgwProxy.Shelly.DTO.Gen2
{
/// <summary>
/// Discover for Gen Shelly Dev
/// </summary>
public class DiscoverDTO
{
#region Public Properties
[JsonProperty("app")]
public string App { get; set; }
[JsonProperty("auth_domain")]
public object AuthDomain { get; set; }
[JsonProperty("auth_en")]
public bool AuthEn { get; set; }
[JsonProperty("fw_id")]
public string FwId { get; set; }
[JsonProperty("gen")]
public int Gen { get; set; }
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("mac")]
public string Mac { get; set; }
[JsonProperty("model")]
public string Model { get; set; }
[JsonProperty("name")]
public object Name { get; set; }
[JsonProperty("profile")]
public string Profile { get; set; }
[JsonProperty("slot")]
public int Slot { get; set; }
[JsonProperty("ver")]
public string Ver { get; set; }
#endregion Public Properties
}
}
+57
View File
@@ -0,0 +1,57 @@
using Newtonsoft.Json;
using System.Collections.Generic;
namespace EgwProxy.Shelly.DTO.Gen2
{
/// <summary>
/// Energy Info
/// </summary>
public class EnergyDto
{
public int Id { get; set; }
/// <summary>
/// Phase A data
/// </summary>
public PhaseDataDto PhaseA { get; set; } = new PhaseDataDto();
/// <summary>
/// Phase B data
/// </summary>
public PhaseDataDto PhaseB { get; set; } = new PhaseDataDto();
/// <summary>
/// Phase C data
/// </summary>
public PhaseDataDto PhaseC { get; set; } = new PhaseDataDto();
/// <summary>
/// Corrente Neutro
/// </summary>
[JsonProperty("n_current")]
public double NeutralCurrent { get; set; } = 0;
/// <summary>
/// Corrente Totale
/// </summary>
[JsonProperty("total_current")]
public double TotalCurrent { get; set; } = 0;
/// <summary>
/// Corrente Totale Attiva
/// </summary>
[JsonProperty("total_act_power")]
public double TotalActivePower { get; set; } = 0;
/// <summary>
/// Corrente Totale Apparente
/// </summary>
[JsonProperty("total_aprt_power")]
public double TotalApparentPower { get; set; } = 0;
/// <summary>
/// Calibrazione fasi manuale
/// </summary>
[JsonProperty("user_calibrated_phase")]
public List<double> UserCalibratedPhase { get; set; } = new List<double>();
}
}
+18
View File
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EgwProxy.Shelly.DTO.Gen2
{
public class PhaseDataDto
{
public double ActivePower { get; set; } = 0;
public double ApparentPower { get; set; } = 0;
public double Current { get; set; } = 0;
public double Frequency { get; set; } = 0;
public double PowerFactor { get; set; } = 0;
public double Voltage { get; set; } = 0;
}
}
+8 -2
View File
@@ -1,4 +1,4 @@
using EgwProxy.Shelly.DTO.Shelly1PM;
using EgwProxy.Shelly.DTO.Gen2;
using Newtonsoft.Json;
namespace EgwProxy.Shelly.DTO
@@ -9,7 +9,6 @@ namespace EgwProxy.Shelly.DTO
/// </summary>
public class ShellyGen2StatusDto
{
/// <summary>
/// WiFi data
/// </summary>
@@ -22,6 +21,13 @@ namespace EgwProxy.Shelly.DTO
[JsonProperty("cloud")]
public CloudDto ShellyCloud { get; set; }
/// <summary>
/// EnergyMonitor 0 data
/// </summary>
[JsonProperty("em:0")]
public EnergyDto EmData { get; set; }
/// <summary>
/// MQTT queue state
/// </summary>
+5 -2
View File
@@ -83,13 +83,16 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Clients\IShelly1.cs" />
<Compile Include="Clients\IShellyPro3Em.cs" />
<Compile Include="Clients\IShelly1Pm.cs" />
<Compile Include="Clients\Shelly1Client.cs" />
<Compile Include="Clients\ShellyPro3EmClient.cs" />
<Compile Include="Clients\Shelly1PmClient.cs" />
<Compile Include="Clients\ShellyClientBase.cs" />
<Compile Include="Converters\EnergyDtoConverter.cs" />
<Compile Include="DTO\BaseServiceDto.cs" />
<Compile Include="DTO\CloudDto.cs" />
<Compile Include="DTO\Gen2\EnergyDto.cs" />
<Compile Include="DTO\Gen2\PhaseDataDto.cs" />
<Compile Include="DTO\Shelly1PmStatusDto.cs" />
<Compile Include="DTO\Shelly1PM\EnergyDto.cs" />
<Compile Include="DTO\Shelly1PM\InputDto.cs" />
File diff suppressed because one or more lines are too long