Aggiunta progetto Proxy Shelly (preliminare), ok test locale in .net framework dopo test .net core
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
|
||||
</startup>
|
||||
<appSettings>
|
||||
<add key="testFile" value="testSetup.json" />
|
||||
</appSettings>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
@@ -0,0 +1,69 @@
|
||||
<?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>{081AB7E7-4C36-49D7-9343-2C567F324B74}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>EgwProxy.Shelly.Test</RootNamespace>
|
||||
<AssemblyName>EgwProxy.Shelly.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="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<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" />
|
||||
<Compile Include="TestSetup.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="conf\.placeholder" />
|
||||
<None Include="conf\testSetup.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\EgwProxy.Shelly\EgwProxy.Shelly.csproj">
|
||||
<Project>{69b1068b-e53f-4e54-9a3d-1031f84889ba}</Project>
|
||||
<Name>EgwProxy.Shelly</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,172 @@
|
||||
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;
|
||||
using System.Net.Http;
|
||||
using EgwProxy.Shelly.Options;
|
||||
using System.Threading;
|
||||
|
||||
namespace EgwProxy.Shelly.Test
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Helper separatore dash
|
||||
/// </summary>
|
||||
private const string separator = "------------------------";
|
||||
|
||||
private static Stopwatch sw = new Stopwatch();
|
||||
/// <summary>
|
||||
/// legge conf in formato stringa
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
protected static string ReadSetting(string key)
|
||||
{
|
||||
string answ = "";
|
||||
try
|
||||
{
|
||||
answ = $"{ConfigurationManager.AppSettings[key]}" ?? "";
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
Console.Write("Eccezione in ReadSettings");
|
||||
Console.Write(exc.Message);
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
//// caffè
|
||||
//private string shellyAddr = "10.74.81.72";
|
||||
//APC
|
||||
private string shellyAddr = "10.74.81.71";
|
||||
|
||||
/// <summary>
|
||||
/// Programma principale
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(separator);
|
||||
Console.WriteLine("Test Shelly Client");
|
||||
Console.WriteLine(separator);
|
||||
Console.WriteLine();
|
||||
string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
||||
string BaseDirectory = System.IO.Path.GetDirectoryName(exePath);
|
||||
string testFile = Path.Combine(BaseDirectory, "conf", ReadSetting("testFile"));
|
||||
if (!string.IsNullOrEmpty(testFile))
|
||||
{
|
||||
Console.WriteLine(separator);
|
||||
Console.WriteLine($"Mode json ({testFile})");
|
||||
Console.WriteLine(separator);
|
||||
Console.WriteLine();
|
||||
if (File.Exists(testFile))
|
||||
{
|
||||
var rawData = File.ReadAllText(testFile);
|
||||
if (!string.IsNullOrEmpty(rawData))
|
||||
{
|
||||
TestSetup testConf = new TestSetup();
|
||||
try
|
||||
{
|
||||
testConf = JsonConvert.DeserializeObject<TestSetup>(rawData);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
// setup devAddr
|
||||
Shelly1PmOptions options = new Shelly1PmOptions()
|
||||
{
|
||||
DefaultTimeout = TimeSpan.FromSeconds(testConf.tOutSec),
|
||||
ServerUri = new Uri($"http://{testConf.devAddr}/rpc")
|
||||
};
|
||||
Shelly1PmClient shelly = new Shelly1PmClient(new HttpClient(), options);
|
||||
// test chiamata completa
|
||||
serverTest(shelly);
|
||||
bool doRepeat = true;
|
||||
while (doRepeat)
|
||||
{
|
||||
// eseguo per ogni step
|
||||
foreach (var item in testConf.steps)
|
||||
{
|
||||
// ripeto per il num di volte richieste...
|
||||
for (int i = 0; i < item.numRep; i++)
|
||||
{
|
||||
Console.WriteLine(separator);
|
||||
Console.WriteLine($"Rep: {i + 1}");
|
||||
Console.WriteLine(separator);
|
||||
string esitoStep = "";
|
||||
sw.Restart();
|
||||
switch (item.action)
|
||||
{
|
||||
case stepType.getFullStatus:
|
||||
var respFull = Task.Run(() => shelly.GetStatus(CancellationToken.None)).Result;
|
||||
if (respFull.IsSuccess)
|
||||
{
|
||||
esitoStep = JsonConvert.SerializeObject(respFull.Value, Formatting.Indented);
|
||||
}
|
||||
else
|
||||
{
|
||||
esitoStep = "Errore in GetStatus";
|
||||
}
|
||||
break;
|
||||
case stepType.getSwitchStatus:
|
||||
var respSwitch = Task.Run(() => shelly.GetSwitchStatus(CancellationToken.None, 0)).Result;
|
||||
if (respSwitch.IsSuccess)
|
||||
{
|
||||
esitoStep = JsonConvert.SerializeObject(respSwitch.Value, Formatting.Indented);
|
||||
}
|
||||
else
|
||||
{
|
||||
esitoStep = "Errore in GetSwitchStatus";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
esitoStep = "Action not managed: skipping";
|
||||
break;
|
||||
}
|
||||
sw.Stop();
|
||||
Console.WriteLine(esitoStep);
|
||||
Console.WriteLine(separator);
|
||||
Console.WriteLine($"Elapsed: {sw.Elapsed.TotalMilliseconds:N3}ms");
|
||||
Console.WriteLine(separator);
|
||||
Console.WriteLine();
|
||||
Thread.Sleep(item.waitTime);
|
||||
}
|
||||
Console.WriteLine($"------ Done Step {item.id} ------");
|
||||
}
|
||||
|
||||
Console.WriteLine("Do you want to repeat from the beginnning? esc to close");
|
||||
ConsoleKeyInfo answ = Console.ReadKey();
|
||||
doRepeat = answ.Key != ConsoleKey.Escape;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void serverTest(Shelly1PmClient shellyClient)
|
||||
{
|
||||
Console.WriteLine(separator);
|
||||
// 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)
|
||||
{
|
||||
Console.WriteLine(separator);
|
||||
Console.WriteLine(JsonConvert.SerializeObject(response.Value, Formatting.Indented));
|
||||
Console.WriteLine(separator);
|
||||
Console.WriteLine($"Elapsed: {sw.Elapsed.TotalMilliseconds:N3}ms");
|
||||
Console.WriteLine(separator);
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.Shelly.Test")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("EgwProxy.Shelly.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("081ab7e7-4c36-49d7-9343-2c567f324b74")]
|
||||
|
||||
// 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")]
|
||||
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EgwProxy.Shelly.Test
|
||||
{
|
||||
public class TestSetup
|
||||
{
|
||||
public string devAddr { get; set; } = "";
|
||||
public int tOutSec{ get; set; } = 5;
|
||||
public List<singleStep> steps { get; set; }
|
||||
}
|
||||
|
||||
public class singleStep
|
||||
{
|
||||
public string id { get; set; } = "00";
|
||||
public string description { get; set; } = "00";
|
||||
public stepType action { get; set; } = stepType.none;
|
||||
|
||||
public int numRep { get; set; } = 1;
|
||||
|
||||
public int waitTime { get; set; } = 1000;
|
||||
|
||||
public List<string> paramList { get; set; } = new List<string>();
|
||||
}
|
||||
|
||||
public enum stepType
|
||||
{
|
||||
none,
|
||||
getFullStatus,
|
||||
getSwitchStatus
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"devAddr": "10.74.81.71",
|
||||
"steps": [
|
||||
{
|
||||
"id": "01",
|
||||
"description": "Test SwitchStatus",
|
||||
"action": "getSwitchStatus",
|
||||
"numRep": 5,
|
||||
"waitTime": 500,
|
||||
"paramList": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net462" />
|
||||
</packages>
|
||||
@@ -0,0 +1,12 @@
|
||||
using EgwProxy.Shelly.DTO;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EgwProxy.Shelly.Clients
|
||||
{
|
||||
public interface IShelly1
|
||||
{
|
||||
Task<ShellyResult<ShellyGen2StatusDto>> GetStatus(CancellationToken cancellationToken, TimeSpan? timeout = null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using EgwProxy.Shelly.DTO;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EgwProxy.Shelly.Clients
|
||||
{
|
||||
public interface IShelly1Pm
|
||||
{
|
||||
Task<ShellyResult<Shelly1PmStatusDto>> GetStatus(CancellationToken cancellationToken, TimeSpan? timeout = null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using EgwProxy.Shelly.DTO;
|
||||
using EgwProxy.Shelly.Options;
|
||||
using Flurl;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EgwProxy.Shelly.Clients
|
||||
{
|
||||
public class Shelly1Client : ShellyClientBase, IShelly1
|
||||
{
|
||||
public Shelly1Client(HttpClient httpClient, Shelly1Options shelly1Options) : base(httpClient, shelly1Options)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<ShellyResult<ShellyGen2StatusDto>> GetStatus(CancellationToken cancellationToken, TimeSpan? timeout = null)
|
||||
{
|
||||
var endpoint = ServerUri.AppendPathSegment("status");
|
||||
var requestMessage = new HttpRequestMessage(HttpMethod.Get, endpoint);
|
||||
return await ExecuteRequestAsync<ShellyGen2StatusDto>(requestMessage, cancellationToken, timeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using EgwProxy.Shelly.DTO;
|
||||
using EgwProxy.Shelly.Options;
|
||||
using Flurl;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EgwProxy.Shelly.Clients
|
||||
{
|
||||
public class Shelly1PmClient : ShellyClientBase, IShelly1Pm
|
||||
{
|
||||
public Shelly1PmClient(HttpClient httpClient, Shelly1PmOptions shellyOptions) : base(httpClient, shellyOptions)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<ShellyResult<Shelly1PmStatusDto>> GetStatus(CancellationToken cancellationToken, TimeSpan? timeout = null)
|
||||
{
|
||||
var endpoint = ServerUri.AppendPathSegment("Shelly.GetStatus");
|
||||
var requestMessage = new HttpRequestMessage(HttpMethod.Get, endpoint);
|
||||
return await ExecuteRequestAsync<Shelly1PmStatusDto>(requestMessage, cancellationToken, timeout);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
using EgwProxy.Shelly.Options;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EgwProxy.Shelly.Clients
|
||||
{
|
||||
public abstract class ShellyClientBase
|
||||
{
|
||||
protected readonly HttpClient ShellyHttpClient;
|
||||
private readonly IShellyCommonOptions _shellyCommonOptions;
|
||||
protected readonly Uri ServerUri;
|
||||
|
||||
protected TimeSpan DefaultTimeout = TimeSpan.FromSeconds(5);
|
||||
|
||||
public ShellyClientBase(HttpClient httpClient, IShellyCommonOptions shellyCommonOptions)
|
||||
{
|
||||
if (httpClient == null) throw new ArgumentNullException(nameof(httpClient));
|
||||
if (shellyCommonOptions == null) throw new ArgumentNullException(nameof(shellyCommonOptions));
|
||||
|
||||
|
||||
ShellyHttpClient = httpClient;
|
||||
_shellyCommonOptions = shellyCommonOptions;
|
||||
ServerUri = shellyCommonOptions.ServerUri;
|
||||
|
||||
if (shellyCommonOptions.DefaultTimeout.HasValue)
|
||||
{
|
||||
DefaultTimeout = shellyCommonOptions.DefaultTimeout.Value;
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task<ShellyResult<T>> ExecuteRequestAsync<T>(HttpRequestMessage httpRequestMessage,
|
||||
CancellationToken cancellationToken, TimeSpan? timeout = null)
|
||||
{
|
||||
timeout = timeout ?? DefaultTimeout;
|
||||
|
||||
using (var timeoutTokenSource = new CancellationTokenSource(timeout.Value))
|
||||
{
|
||||
var authenticationString = $"{_shellyCommonOptions.UserName}:{_shellyCommonOptions.Password}";
|
||||
var base64EncodedAuthenticationString = Convert.ToBase64String(Encoding.ASCII.GetBytes(authenticationString));
|
||||
|
||||
httpRequestMessage.Headers.Authorization = new AuthenticationHeaderValue("Basic", base64EncodedAuthenticationString);
|
||||
|
||||
var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(timeoutTokenSource.Token, cancellationToken);
|
||||
var response = await ShellyHttpClient.SendAsync(httpRequestMessage, linkedTokenSource.Token);
|
||||
|
||||
if (response.StatusCode == 0)
|
||||
{
|
||||
// Status code of 0 means timeout reached
|
||||
return ShellyResult<T>.TransientFailure("Device did not respond within timeout period");
|
||||
}
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.ServiceUnavailable)
|
||||
{
|
||||
return ShellyResult<T>.TransientFailure("Device responded with ServiceUnavailable");
|
||||
}
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
return ShellyResult<T>.Success(default, "Device responded with NotFound");
|
||||
}
|
||||
|
||||
if (response.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
return ShellyResult<T>.Failure($"Device responded with http status code {response.StatusCode}");
|
||||
}
|
||||
|
||||
return await HandleOkResponse<T>(response);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual async Task<ShellyResult<T>> HandleOkResponse<T>(HttpResponseMessage response)
|
||||
{
|
||||
var readAsStringAsync = await response.Content.ReadAsStringAsync();
|
||||
var shelly1Status = JsonConvert.DeserializeObject<T>(readAsStringAsync);
|
||||
return ShellyResult<T>.Success(shelly1Status);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace EgwProxy.Shelly.DTO.Shelly1PM
|
||||
{
|
||||
public class BaseServiceDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Connection State
|
||||
/// </summary>
|
||||
[JsonProperty("connected")]
|
||||
public bool Connected { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using EgwProxy.Shelly.DTO.Shelly1PM;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace EgwProxy.Shelly.DTO
|
||||
{
|
||||
public class CloudDto :BaseServiceDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Define if service is enabled
|
||||
/// </summary>
|
||||
[JsonProperty("enabled")]
|
||||
public bool Enabled { get; set; } = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace EgwProxy.Shelly.DTO.Shelly1PM
|
||||
{
|
||||
/// <summary>
|
||||
/// Energy Info
|
||||
/// </summary>
|
||||
public class EnergyDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Total returned energy consumed in Watt-hours
|
||||
/// </summary>
|
||||
[JsonProperty("total")]
|
||||
public double Total { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returned energy in Milliwatt-hours for the last three complete minutes. The 0-th element indicates the counts accumulated during the minute preceding minute_ts. Present only if the device clock is synced.
|
||||
/// </summary>
|
||||
[JsonProperty("by_minute")]
|
||||
public double[] LastByMinute { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Unix timestamp marking the start of the current minute (in UTC).
|
||||
/// </summary>
|
||||
[JsonProperty("minute_ts")]
|
||||
public long TimeStamp { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace EgwProxy.Shelly.DTO.Shelly1PM
|
||||
{
|
||||
/// <summary>
|
||||
/// Input info
|
||||
/// </summary>
|
||||
public class InputDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Id of the Input component instance
|
||||
/// </summary>
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Current State(only for type switch, button) State of the input (null if the input instance is stateless, i.e. for type button)
|
||||
/// </summary>
|
||||
[JsonProperty("state")]
|
||||
public bool State { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace EgwProxy.Shelly.DTO.Shelly1PM
|
||||
{
|
||||
public class SwitchDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Id of the Switch component instance
|
||||
/// </summary>
|
||||
[JsonProperty("id")]
|
||||
public int Id { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Source of the last command, for example: init, WS_in, http, ...
|
||||
/// </summary>
|
||||
[JsonProperty("source")]
|
||||
public string Source { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Output status: rue if the output channel is currently on, false otherwise
|
||||
/// </summary>
|
||||
[JsonProperty("output")]
|
||||
public bool Output { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Last measured instantaneous active power(in Watts) delivered to the attached load(shown if applicable)
|
||||
/// </summary>
|
||||
[JsonProperty("apower")]
|
||||
public double Power { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Last measured voltage in Volts (shown if applicable)
|
||||
/// </summary>
|
||||
[JsonProperty("voltage")]
|
||||
public double Voltage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Last measured current in Amperes (shown if applicable)
|
||||
/// </summary>
|
||||
[JsonProperty("current")]
|
||||
public double Current { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Information about the active energy counter (shown if applicable)
|
||||
/// </summary>
|
||||
[JsonProperty("aenergy")]
|
||||
public EnergyDto ActEnergy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Information about the returned active energy counter * (shown if applicable)
|
||||
/// </summary>
|
||||
[JsonProperty("ret_aenergy")]
|
||||
public EnergyDto RetEnergy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Information about the temperature (shown if applicable)
|
||||
/// </summary>
|
||||
[JsonProperty("temperature")]
|
||||
public TemperatureDto Temperature { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Error conditions occurred. May contain overtemp, overpower, overvoltage, undervoltage, (shown if at least one error is present)
|
||||
/// </summary>
|
||||
[JsonProperty("errors")]
|
||||
public string[] Errors { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using EgwProxy.Shelly.DTO.Shelly1PM;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace EgwProxy.Shelly.DTO
|
||||
{
|
||||
/// <summary>
|
||||
/// Extended information for the Shelly1PM
|
||||
/// https://shelly-api-docs.shelly.cloud/gen2/Devices/Gen3/Shelly1PMG3
|
||||
/// </summary>
|
||||
public class Shelly1PmStatusDto : ShellyGen2StatusDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Input channel
|
||||
/// </summary>
|
||||
[JsonProperty("input:0")]
|
||||
public InputDto Input { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Switch 0 data
|
||||
/// </summary>
|
||||
[JsonProperty("switch:0")]
|
||||
public SwitchDto Switch { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using EgwProxy.Shelly.DTO.Shelly1PM;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace EgwProxy.Shelly.DTO
|
||||
{
|
||||
/// <summary>
|
||||
/// Shelly Gen2 device status data
|
||||
/// https://shelly-api-docs.shelly.cloud/gen2/#status
|
||||
/// </summary>
|
||||
public class ShellyGen2StatusDto
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// WiFi data
|
||||
/// </summary>
|
||||
[JsonProperty("wifi")]
|
||||
public WifiDto WiFiStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Shelly Cloud state
|
||||
/// </summary>
|
||||
[JsonProperty("cloud")]
|
||||
public CloudDto ShellyCloud { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// MQTT queue state
|
||||
/// </summary>
|
||||
[JsonProperty("mqtt")]
|
||||
public BaseServiceDto MQTT { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Sys Info data
|
||||
/// </summary>
|
||||
[JsonProperty("sys")]
|
||||
public SysDto SysInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// WS state
|
||||
/// </summary>
|
||||
[JsonProperty("ws")]
|
||||
public BaseServiceDto WebSocket { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace EgwProxy.Shelly.DTO
|
||||
{
|
||||
/// <summary>
|
||||
/// System Info
|
||||
/// </summary>
|
||||
public class SysDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Mac address of the device
|
||||
/// </summary>
|
||||
[JsonProperty("mac")]
|
||||
public string Mac { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// True if restart is required, false otherwise
|
||||
/// </summary>
|
||||
[JsonProperty("restart_required")]
|
||||
public bool RestartRequired { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// Current time in the format HH:MM (24-hour time format in the current timezone with leading zero). null when time is not synced from NTP server.
|
||||
/// </summary>
|
||||
[JsonProperty("time")]
|
||||
public string Time { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Unix timestamp (in UTC), null when time is not synced from NTP server.
|
||||
/// </summary>
|
||||
[JsonProperty("unixtime")]
|
||||
public int UnixTime { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Time in seconds since last reboot
|
||||
/// </summary>
|
||||
[JsonProperty("uptime")]
|
||||
public int Uptime { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Total size of the RAM in the system in Bytes
|
||||
/// </summary>
|
||||
[JsonProperty("ram_size")]
|
||||
public int RamSize { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Size of the free RAM in the system in Bytes
|
||||
/// </summary>
|
||||
[JsonProperty("ram_free")]
|
||||
public int RamFree { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Total size of the file system in Bytes
|
||||
/// </summary>
|
||||
[JsonProperty("fs_size")]
|
||||
public int FSSize { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Size of the free file system in Bytes
|
||||
/// </summary>
|
||||
[JsonProperty("fs_free")]
|
||||
public int FSFree { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Configuration revision number
|
||||
/// </summary>
|
||||
[JsonProperty("cfg_rev")]
|
||||
public int CfgRev { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// KVS (Key-Value Store) revision number
|
||||
/// </summary>
|
||||
[JsonProperty("kvs_rev")]
|
||||
public int KvsRev { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Schedules revision number, present if schedules are enabled
|
||||
/// </summary>
|
||||
[JsonProperty("schedule_rev")]
|
||||
public int ScheduleRev { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Webhooks revision number, present if webhooks are enabled
|
||||
/// </summary>
|
||||
[JsonProperty("webhook_rev")]
|
||||
public int WebhookRev { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Webhooks revision number, present if webhooks are enabled
|
||||
/// </summary>
|
||||
[JsonProperty("available_updates")]
|
||||
public UpdateDto AvailUpdates { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Information about reset type and cause
|
||||
/// </summary>
|
||||
[JsonProperty("reset_reason")]
|
||||
public int ResetReason { get; set; } = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace EgwProxy.Shelly.DTO
|
||||
{
|
||||
public class TemperatureDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Temperature in Celsius (null if the temperature is out of the measurement range)
|
||||
/// </summary>
|
||||
[JsonProperty("tC")]
|
||||
public double? Celsius { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Temperature in Fahrenheit (null if the temperature is out of the measurement range)
|
||||
/// </summary>
|
||||
[JsonProperty("tF")]
|
||||
public double? Fahrenheit { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace EgwProxy.Shelly.DTO
|
||||
{
|
||||
/// <summary>
|
||||
/// Info about sw update
|
||||
/// </summary>
|
||||
public class UpdateDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Shown only if beta update is available
|
||||
/// </summary>
|
||||
[JsonProperty("beta")]
|
||||
public VersDto Beta { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Shown only if beta update is available
|
||||
/// </summary>
|
||||
[JsonProperty("stable")]
|
||||
public VersDto Stable { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace EgwProxy.Shelly.DTO
|
||||
{
|
||||
public class VersDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Version of the new firmware
|
||||
/// </summary>
|
||||
[JsonProperty("version")]
|
||||
public string Version { get; set; } = "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace EgwProxy.Shelly.DTO
|
||||
{
|
||||
/// <summary>
|
||||
/// WiFi status info
|
||||
/// </summary>
|
||||
public class WifiDto
|
||||
{
|
||||
/// <summary>
|
||||
/// Ip of the device in the network (null if disconnected)
|
||||
/// </summary>
|
||||
[JsonProperty("sta_ip")]
|
||||
public string StaIp { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Status of the connection. Range of values: disconnected, connecting, connected, got ip
|
||||
/// </summary>
|
||||
[JsonProperty("status")]
|
||||
public string Status { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// SSID of the network (null in case of hidden network)
|
||||
/// </summary>
|
||||
[JsonProperty("ssid")]
|
||||
public string SSID { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Strength of the signal in dBms
|
||||
/// </summary>
|
||||
[JsonProperty("rssi")]
|
||||
public int RSSI { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Number of clients connected to the access point. Present only when AP is enabled and range extender functionality is present and enabled.
|
||||
/// </summary>
|
||||
[JsonProperty("ap_client_count")]
|
||||
public int NumClients { get; set; } = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
<?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>{69B1068B-E53F-4E54-9A3D-1031F84889BA}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>EgwProxy.Shelly</RootNamespace>
|
||||
<AssemblyName>EgwProxy.Shelly</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</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="Flurl, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Flurl.4.0.0\lib\net461\Flurl.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Flurl.Http, Version=4.0.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Flurl.Http.4.0.2\lib\net461\Flurl.Http.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.6.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Text.Encodings.Web, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Text.Encodings.Web.6.0.0\lib\net461\System.Text.Encodings.Web.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Text.Json, Version=6.0.0.4, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Text.Json.6.0.4\lib\net461\System.Text.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<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="Clients\IShelly1.cs" />
|
||||
<Compile Include="Clients\IShelly1Pm.cs" />
|
||||
<Compile Include="Clients\Shelly1Client.cs" />
|
||||
<Compile Include="Clients\Shelly1PmClient.cs" />
|
||||
<Compile Include="Clients\ShellyClientBase.cs" />
|
||||
<Compile Include="DTO\BaseServiceDto.cs" />
|
||||
<Compile Include="DTO\CloudDto.cs" />
|
||||
<Compile Include="DTO\Shelly1PmStatusDto.cs" />
|
||||
<Compile Include="DTO\Shelly1PM\EnergyDto.cs" />
|
||||
<Compile Include="DTO\Shelly1PM\InputDto.cs" />
|
||||
<Compile Include="DTO\Shelly1PM\SwitchDto.cs" />
|
||||
<Compile Include="DTO\ShellyGen2StatusDto.cs" />
|
||||
<Compile Include="DTO\SysDto.cs" />
|
||||
<Compile Include="DTO\TemperatureDto.cs" />
|
||||
<Compile Include="DTO\UpdateDto.cs" />
|
||||
<Compile Include="DTO\VersDto.cs" />
|
||||
<Compile Include="DTO\WifiDto.cs" />
|
||||
<Compile Include="Options\IShellyAuthOptions.cs" />
|
||||
<Compile Include="Options\IShellyCommonOptions.cs" />
|
||||
<Compile Include="Options\Shelly1Options.cs" />
|
||||
<Compile Include="Options\Shelly1PmOptions.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ShellyResult.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="..\packages\System.Text.Json.6.0.4\build\System.Text.Json.targets" Condition="Exists('..\packages\System.Text.Json.6.0.4\build\System.Text.Json.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\System.Text.Json.6.0.4\build\System.Text.Json.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Text.Json.6.0.4\build\System.Text.Json.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EgwProxy.Shelly.Options
|
||||
{
|
||||
/// <summary>
|
||||
/// Common authentication options across all shelly devices
|
||||
/// </summary>
|
||||
public interface IShellyAuthOptions
|
||||
{
|
||||
string UserName { get; }
|
||||
string Password { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EgwProxy.Shelly.Options
|
||||
{
|
||||
/// <summary>
|
||||
/// Common options across all shelly devices
|
||||
/// </summary>
|
||||
public interface IShellyCommonOptions : IShellyAuthOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// URI for the Shelly device
|
||||
/// </summary>
|
||||
Uri ServerUri { get; }
|
||||
/// <summary>
|
||||
/// Default timeout for HTTP requests if a specific timeout is not supplied
|
||||
/// </summary>
|
||||
TimeSpan? DefaultTimeout { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EgwProxy.Shelly.Options
|
||||
{
|
||||
public class Shelly1Options : IShellyCommonOptions
|
||||
{
|
||||
public Uri ServerUri { get; set; }
|
||||
public TimeSpan? DefaultTimeout { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
|
||||
public Shelly1Options()
|
||||
{
|
||||
DefaultTimeout = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EgwProxy.Shelly.Options
|
||||
{
|
||||
public class Shelly1PmOptions : IShellyCommonOptions
|
||||
{
|
||||
public Uri ServerUri { get; set; }
|
||||
public TimeSpan? DefaultTimeout { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string Password { get; set; }
|
||||
|
||||
public Shelly1PmOptions()
|
||||
{
|
||||
DefaultTimeout = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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.Shelly")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("EgwProxy.Shelly")]
|
||||
[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("69b1068b-e53f-4e54-9a3d-1031f84889ba")]
|
||||
|
||||
// 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")]
|
||||
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EgwProxy.Shelly
|
||||
{
|
||||
public class ShellyResult<T>
|
||||
{
|
||||
public T Value
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_successChecked)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot access value of result without checking success first");
|
||||
}
|
||||
|
||||
return _value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the client request has completed successfully
|
||||
/// </summary>
|
||||
public bool IsSuccess
|
||||
{
|
||||
get
|
||||
{
|
||||
_successChecked = true;
|
||||
return _success;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the client request has failed
|
||||
/// </summary>
|
||||
public bool IsFailure => !IsSuccess;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the reason for failure is transient
|
||||
/// </summary>
|
||||
public bool IsTransient { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Any message that accompanies this result
|
||||
/// </summary>
|
||||
public string Message { get; }
|
||||
|
||||
private T _value;
|
||||
private bool _successChecked = false;
|
||||
private bool _success = false;
|
||||
|
||||
private ShellyResult(T value, bool success, bool isTransient, string message = null)
|
||||
{
|
||||
_value = value;
|
||||
_success = success;
|
||||
IsTransient = isTransient;
|
||||
Message = message;
|
||||
}
|
||||
|
||||
public static ShellyResult<T> Success(T value, string message = null)
|
||||
{
|
||||
return new ShellyResult<T>(value, true, false, message);
|
||||
}
|
||||
|
||||
public static ShellyResult<T> Failure(string message = null)
|
||||
{
|
||||
return new ShellyResult<T>(default, success: false, isTransient: false, message);
|
||||
}
|
||||
|
||||
public static ShellyResult<T> TransientFailure(string message = null)
|
||||
{
|
||||
return new ShellyResult<T>(default, success: false, isTransient: true, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
@@ -0,0 +1,69 @@
|
||||
{
|
||||
"metadata": [
|
||||
{
|
||||
"src": [
|
||||
{
|
||||
"files": [
|
||||
"*.csproj",
|
||||
"*.vbproj"
|
||||
],
|
||||
"cwd": ".",
|
||||
"exclude": [
|
||||
"**/obj/**",
|
||||
"**/bin/**",
|
||||
"_site/**"
|
||||
]
|
||||
}
|
||||
],
|
||||
"dest": "obj/api"
|
||||
}
|
||||
],
|
||||
"build": {
|
||||
"content": [
|
||||
{
|
||||
"files": [
|
||||
"api/**.yml"
|
||||
],
|
||||
"cwd": "obj"
|
||||
},
|
||||
{
|
||||
"files": [
|
||||
"api/*.md",
|
||||
"articles/**.md",
|
||||
"toc.yml",
|
||||
"*.md"
|
||||
],
|
||||
"exclude": [
|
||||
"obj/**",
|
||||
"_site/**"
|
||||
]
|
||||
}
|
||||
],
|
||||
"resource": [
|
||||
{
|
||||
"files": [
|
||||
"images/**"
|
||||
],
|
||||
"exclude": [
|
||||
"obj/**",
|
||||
"_site/**"
|
||||
]
|
||||
}
|
||||
],
|
||||
"overwrite": [
|
||||
{
|
||||
"files": [
|
||||
"apidoc/**.md"
|
||||
],
|
||||
"exclude": [
|
||||
"obj/**",
|
||||
"_site/**"
|
||||
]
|
||||
}
|
||||
],
|
||||
"dest": "_site",
|
||||
"template": [
|
||||
"default"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
# EgwProxy.Shelly Library
|
||||
|
||||
Documentazione relativa alla libreria di interfaccia con sistemi Shelly x controllo domotico e del consumo energetico.
|
||||
|
||||
Disponibile in forma di pacchetto nuget sul repo aziendale nexus.steamware.net: i pacchetti sono disponibili all'indirizzo
|
||||
|
||||
https://nexus.steamware.net/#browse/browse:nuget-hosted
|
||||
|
||||
Vedere la sezione Articles per maggiori informazioni sulle definizioni, l'impiego ed esempi.
|
||||
|
||||
L'oggetot id base è **EgwProxy.Shelly.Clients.* **
|
||||
|
||||
## Articles
|
||||
|
||||
Per maggiori dettagli, definizioni e demo funzionamento si rimanda alla sezione Articles
|
||||
|
||||
## Api
|
||||
|
||||
Per ogni dettaglio e riferimento alla libreria si rimanda alla sezione Api Documentation
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Flurl" version="4.0.0" targetFramework="net462" />
|
||||
<package id="Flurl.Http" version="4.0.2" targetFramework="net462" />
|
||||
<package id="Microsoft.Bcl.AsyncInterfaces" version="6.0.0" targetFramework="net462" />
|
||||
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net462" />
|
||||
<package id="System.Buffers" version="4.5.1" targetFramework="net462" />
|
||||
<package id="System.Memory" version="4.5.4" targetFramework="net462" />
|
||||
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net462" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net462" />
|
||||
<package id="System.Text.Encodings.Web" version="6.0.0" targetFramework="net462" />
|
||||
<package id="System.Text.Json" version="6.0.4" targetFramework="net462" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net462" />
|
||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net462" />
|
||||
</packages>
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
- name: Articles
|
||||
href: articles/
|
||||
- name: API Documentation
|
||||
href: obj/api/
|
||||
homepage: api/index.md
|
||||
Reference in New Issue
Block a user