Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,13 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

src/.DS_Store

.DS_Store

src/TuyaNet.Console/Database.secret.json

.idea/.idea.tuyanet.dir/.idea/

src/.idea/.idea.TuyaNet/.idea/
183 changes: 0 additions & 183 deletions TuyaParser.cs

This file was deleted.

17 changes: 17 additions & 0 deletions src/TuyaNet.Console/Database.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Text.Json;
using com.clusterrr.TuyaNet.Models;

namespace TuyaNet.Console
{
public static class Database
{
public static TuyaDeviceInfo[] Devices { get; set; }

public static void LoadFromFile(string path)
{
var fileBytes = File.ReadAllBytes(path);
var readOnlySpan = new ReadOnlySpan<byte>(fileBytes);
Devices = JsonSerializer.Deserialize<TuyaDeviceInfo[]>(readOnlySpan)!;
}
}
}
16 changes: 16 additions & 0 deletions src/TuyaNet.Console/Database.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"Name": "room 1 device v 3.4",
"DeviceId": "secret",
"LocalIp": "127.0.0.1",
"LocalKey": "secret",
"ApiVer": "3.4"
},
{
"Name": "room 2 device v 3.3",
"DeviceId": "secret",
"LocalIp": "127.0.0.1",
"LocalKey": "secret",
"ApiVer": "3.3"
}
]
33 changes: 33 additions & 0 deletions src/TuyaNet.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using com.clusterrr.TuyaNet.Services;
using TuyaNet.Console;

var devicesDatabaseFile = args.FirstOrDefault() ?? "../../Database.example.json";
Database.LoadFromFile(devicesDatabaseFile);

var device = Database.Devices.First(x => x.ApiVer == "3.4");
var service = new TuyaSwitcherService(device);
await service.Connect();

async Task TurnOn()
{
await service.TurnOn();
var isEnabled = await service.GetStatus();
Console.WriteLine($"status get response: {isEnabled}");
}

async Task TurnOff()
{
await service.TurnOff();
var isEnabled = await service.GetStatus();
Console.WriteLine($"status get response: {isEnabled}");
}

async Task<bool> GetIsEnabled()
{
return await service.GetStatus();
}

if(await GetIsEnabled())
await TurnOff();
else
await TurnOn();
16 changes: 16 additions & 0 deletions src/TuyaNet.Console/TuyaNet.Console.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>


<ItemGroup>
<ProjectReference Include="..\TuyaNet\TuyaNet.csproj" />
</ItemGroup>

</Project>
22 changes: 22 additions & 0 deletions src/TuyaNet.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TuyaNet", "TuyaNet\TuyaNet.csproj", "{40D5F27F-9357-4742-AA98-A15256CE7443}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TuyaNet.Console", "TuyaNet.Console\TuyaNet.Console.csproj", "{6CA562A2-B362-4376-A793-ABDF97562A69}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{40D5F27F-9357-4742-AA98-A15256CE7443}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{40D5F27F-9357-4742-AA98-A15256CE7443}.Debug|Any CPU.Build.0 = Debug|Any CPU
{40D5F27F-9357-4742-AA98-A15256CE7443}.Release|Any CPU.ActiveCfg = Release|Any CPU
{40D5F27F-9357-4742-AA98-A15256CE7443}.Release|Any CPU.Build.0 = Release|Any CPU
{6CA562A2-B362-4376-A793-ABDF97562A69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CA562A2-B362-4376-A793-ABDF97562A69}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CA562A2-B362-4376-A793-ABDF97562A69}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CA562A2-B362-4376-A793-ABDF97562A69}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions src/TuyaNet/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Linq;

namespace com.clusterrr.TuyaNet.Extensions
{
public static class EnumExtensions
{
public static TuyaProtocolVersion[] GetTuyaVersionsValues()
{
var values = (TuyaProtocolVersion[])Enum.GetValues(typeof(TuyaProtocolVersion));
return values;
}

public static string GetNames(this TuyaCommand command)
{
var values = (TuyaCommand[])Enum.GetValues(typeof(TuyaCommand));
return string.Join(", ", values.Where(x => x == command).Select(x=>x.ToString()));
}
}
}
File renamed without changes.
13 changes: 13 additions & 0 deletions src/TuyaNet/Models/TuyaDeviceInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace com.clusterrr.TuyaNet.Models
{
public class TuyaDeviceInfo
{
public string Name { get; set; }
public string DeviceId { get; set; }
public string LocalIp { get; set; }
public string LocalKey { get; set; }
public int Priority { get; set; }
public string ApiVer { get; set; }
}

}
File renamed without changes.
File renamed without changes.
Loading