snootforge

chee/kasa

a javascript for kasa veho lightbulbs

smal lib for kasa veho (and tiktek?) smart bluetooth lightblibs

small library for kasa veho lightbulbs and others like it.

could not have finished this if it were not for this blog post and this python library by @mjg59. so thank you a billion times for writing that and digging into that disassembled .so while i dug into nothing but shallow graves

you’ll note that this is nearly a carbon copy of their library

i couldn’t run that because i wasn’t on a loonix machine, so now this has happened and should work on lanux and macos maybe even windows if the stars align*. relies on the wnoderful noble

* edit: after some fixes, it now works fine on Apple’s Macintosh Operating System, GNU/Linux and Microsoft Windows 10

use:

  1. const {pair, setColor} = require('kasa')
  2. pair({
  3. name: 'Smart Light',
  4. password: 'password obtained from adb lolcat',
  5. address: 'ca:fe:0f:be:ef' // address of light
  6. }, dispatch => {
  7. // red, green, blue, brightness
  8. dispatch(setColor(0xff, 0x2a, 0x50, 0xff))
  9. })
  1. const {discover, pair, setColor} = require('kasa')
  2. discover({
  3. name: 'Smart Light', // defaults to Smart Light
  4. password: 'get this from adb lolcat'
  5. }, blub => {
  6. console.log('a real lootblub!', blub.address)
  7. pair(blub, dispatch => {
  8. dispatch(setColor(0x33, 0xcc, 0xff, 0xff))
  9. })
  10. })
  1. const {discover, pair, setColor} = require('kasa')
  2. discover()
  3. .then(pair)
  4. .then(dispatch => dispatch(setColor(0xff, 0xff, 0xff, 0xff)))

there are some silly examples in the directory called play/

api

  1. module.exports {
  2. // find a bulb or every bulb forever
  3. discover({name?, password?, address?}, callback?) -> Promise{Peripheral}
  4. pair({Peripheral?, callback?) -> Promise{dispatch()}
  5. // these return an array for use by the dispatch function that you get as
  6. // a gift for pairing a peripheral
  7. setColor(red, green, blue, brightness) -> [0xffff, 0xc1, ...args]
  8. setDefaultColor(red, green, blue, brightness) -> [0xffff, 0xc4, ...args]
  9. }
  10. // when a bulb gets paired it returns a function (to callback and .then)
  11. // that lets you send commands to the bulb. i have called it dispatch because
  12. // i use redux at work every day and it seemed like the most appropriate word
  13. // because i don't know many words
  14. // it creates the packet and sends it to the blub
  15. // it returns an error if the command failed. i have never seen this happen so
  16. // i don't have much information on that
  17. dispatch([id, command, data], callback?) -> Promise{error}

note: there is currently a bug in noble that means it doesn’t close even when we stop scanning, because it is still listening out for adapter changes. once the fix for that has merged, a .stop() will be added to the exports.

tests

todo: