AC.Library.Core 1.0.3

dotnet add package AC.Library.Core --version 1.0.3                
NuGet\Install-Package AC.Library.Core -Version 1.0.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AC.Library.Core" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AC.Library.Core --version 1.0.3                
#r "nuget: AC.Library.Core, 1.0.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AC.Library.Core as a Cake Addin
#addin nuget:?package=AC.Library.Core&version=1.0.3

// Install AC.Library.Core as a Cake Tool
#tool nuget:?package=AC.Library.Core&version=1.0.3                

AC.Library.Core

AC.Library.Core is a streamlined library designed for managing Gree Air Conditioner devices. This library has been specifically tested with the Gree G-Tech model. For more information on this model, please visit Gree Global.

We extend our gratitude to tomikaa87 for his exceptional contributions, from which this project draws inspiration and methodology. To explore his innovative work, which served as a foundational resource for our development, visit gree-remote.

Usage Instructions

Local network discovery

This functionality initiates a local network discovery by dispatching a specialized UDP packet to the broadcast address. Devices within the network respond with pertinent information such as brand, MAC address, and device name, among others.

    using var udpWrapper = new UdpClientWrapper();    
    var deviceScanner = new ScanOperation(udpWrapper);
    // The IP address must be the broadcast address of  local network
    var devices = await deviceScanner.Scan("192.168.1.255");

Binding device

To communicate with an air conditioner (AC), the device must first be bound to the computer. Successful binding yields a private key essential for subsequent communications. It is advisable to store this key securely.

    // From the scanning results let's take the first one
    var device = devices.FirstOrDefault();

    using var udpWrapper = new UdpClientWrapper();
    var bindOperation = new BindOperation(udpWrapper);
    var privateKey = await bindOperation.Bind(device.ClientId, device.IpAddress);
    // We can now add the private key to the device object
    device.PrivateKey = privateKey;    

Set a parameter

To modify a device parameter, follow these steps:

Instantiate a SetParameterOperation. When creating an instance of UdpClientWrapper, it is crucial to employ the using statement as shown below. This approach ensures that the udpWrapper object is properly disposed of once it is no longer in use, thereby managing resources efficiently and preventing potential memory leaks.

    // Let's use the previously bound device
    using var udpWrapper = new UdpClientWrapper(); 
    var setParameterOperation = new SetParameterOperation(
        udpWrapper,
        device.ClientId,
        device.PrivateKey
    );

Execute the SetParameter method with the desired parameter and value:

    // Turn on the device
    await setParameterOperation.SetParameter(
        PowerParam.Power,
        new PowerParameterValue(PowerValues.On),
        acDevice.IpAddress
    );

    // Let's set the temperature to 20°C
    var result = await setParameterOperation.SetParameter(
        TemperatureParam.Temperature,
        new TempParameterValue(TemperatureValues._20),
        device.IpAddress
    );

Query status

You can also retrieve the current settings of one or more parameters:

Begin by creating a DeviceStatusOperation instance with the necessary parameters:

    using var udpWrapper = new UdpClientWrapper(); 
    var statusOperation = new DeviceStatusOperation(
        udpWrapper,
        device.ClientId,
        device.PrivateKey
    );

Formulate a list of parameters and invoke the GetDeviceStatus method:

    var parameterList = new List<IParameter>()
    {
        PowerParam.Power,
        TemperatureParam.Temperature
    };

   var status = await statusOperation.GetDeviceStatus(parameterList, device.IpAddress);

This method returns a Dictionary<string, int>, where each key-value pair represents a parameter and its corresponding value. The string key denotes the name of the queried parameter, and the int value signifies the parameter's actual value. This structure allows for efficient access to the status of multiple device parameters in a type-safe manner.

Examples

For practical implementation examples and to better understand how to utilize the features of this library, please refer to the example code provided in the repository at .\AC.Library.Core\Examples. This directory contains sample application and usage scenarios that demonstrate the library's capabilities in real-world contexts.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 158 2/24/2024
1.0.2 134 2/24/2024
1.0.1 114 2/24/2024
1.0.0 130 2/22/2024