Git Product home page Git Product logo

lgthinqsharp's Introduction

EP94.ThinqSharp

Library to connect and interact with LG V2 devices through the thinq api. For now the only supported device is the airconditioner, as I don't own any other LG devices.

NuGet version (EP94.ThinqSharp)

Code example:

// In this example Serilog is used, but it can be any logging library
Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Verbose()
                .WriteTo.Console().CreateLogger();

ThinqClient thinqClient;
string passportFilePath = Path.Combine(Directory.GetCurrentDirectory(), "Passport.json");

// A passport can be used to speed up the login process
// In this example the passport is saved in a json file
if (!File.Exists(passportFilePath))
{
    thinqClient = new ThinqClient(LoggerFactory.Create(builder => builder.AddSerilog()));
    // Request the passport and save it for later use
    Passport passport = await thinqClient.GetPassportAsync("your_username", "your_password");
    File.WriteAllText(passportFilePath, JsonConvert.SerializeObject(passport));
}
else
{
    Passport passport = JsonConvert.DeserializeObject<Passport>(File.ReadAllText(passportFilePath));
    // If the passport is provided through the constructor, the GetPassportAsync method doesn't have to be called
    thinqClient = new ThinqClient(passport, LoggerFactory.Create(builder => builder.AddSerilog()));
}
IEnumerable<DeviceClient> deviceClients = await thinqClient.ConnectAsync();

// Turn all airconditioners on
foreach (DeviceClient deviceClient in deviceClients)
{
    if (deviceClient is AcClient acClient)
    {
        await acClient.SetSnapshotValue(snapshot => snapshot.IsOn, true);
        // or
        await acClient.SetOnState(true);
        // or send multiple values
        await acClient.SendMultipleValues(TimeSpan.FromMilliseconds(100))
            .Value(s => s.IsOn, true)
            .Value(s => s.OperationMode, (double)AcMode.Cool)
            .Value(s => s.FanSpeed, (double)AcFanSpeed.High)
            .SendCommandsAsync();
    }
    deviceClient.OnDeviceSnapshotChanged += (sender, args) =>
    {
        Console.WriteLine($"Snapshot of device {deviceClient.DeviceInfo.Alias} has changed: {deviceClient.DeviceSnapshot}");
    };
}      

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.