Code Monkey home page Code Monkey logo

kasatplinkandroidsdk's Introduction

Kasa TP-Link Android SDK

This is an (unofficial) Android SDK for interacting with Kasa smart devices and the Kasa API.

Dependency

In newer Gradle versions, insert this into settings.gradle:

dependencyResolutionManagement {
    ...
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

And then download the library as usual:

dependencies {
    implementation 'com.github.Sternbach-Software:KasaTPLinkAndroidSDK:-SNAPSHOT'
}

Usage

The entry point to this sdk is the KasaDeviceManager class. Use this class by creating an instance using the empty constructor, calling authenticate, and then using the instance to create KasaDevices by calling withDevice. For example:

val manager = KasaDeviceManager()
manager.authenticate(email, password)
val lamp = manager.withDevice(/* alias = */ "Kitchen lamp")!!

You can also use the KasaDeviceManager to get a list of devices associated with the account.

There are two types of device objects the SDK exposes:

  • the device objects as returned from the Kasa API (which have a lot of meaningless hardware information):
manager.getAllDevices()
  • a more user-friendly object (KasaDevice) that only has the alias (user-assigned name of smart device) and functions for turning on and off the device.
manager.getAllKasaDevices()

The currently available functions of KasaDevice are (I welcome PRs):

lamp.turnOn()
lamp.turnOff()
lamp.toggle() 

lamp.getIsOn()
lamp.setIsOn(true)

The above are all suspending functions, as is authenticate, because they use Retrofit to invoke the official API, wap.tplinkcloud.com.

Unfortunately, the last two functions cannot be condensed into lamp.isOn with a getter and setter because these functions are suspend, and suspending properties are currently not supported.

Credits

This SDK is heavily based on this widget which is under the MIT license.

License

   Copyright [2022] [[email protected]]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

kasatplinkandroidsdk's People

Contributors

sternbach-software avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

vaginessa

kasatplinkandroidsdk's Issues

Rename `withDevice()` to `getDevice()`

It is more idiomatic to use get. Although withDevice accurately conveys that the actions like turnOn are simply forwarded to the API, get is more familiar.

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.