snootforge

chee/kasa

a javascript for kasa veho lightbulbs

..

README.mdRaw

  1. ## smal lib for kasa veho (and tiktek?) smart bluetooth lightblibs
  2. small library for kasa veho lightbulbs and others like it.
  3. could not have finished this if it were not for
  4. [this blog post](https://mjg59.dreamwidth.org/43722.html) and
  5. [this python library](https://github.com/mjg59/python-tikteck) by
  6. [@mjg59](https://twitter.com/mjg59). so thank you a billion times for writing
  7. that and digging into that disassembled .so while i dug into nothing but shallow
  8. graves
  9. you'll note that this is nearly a carbon copy of their library
  10. i couldn't run that because i wasn't on a loonix machine, so now this has
  11. happened and should work on lanux and macos maybe even windows if the stars
  12. align\*. relies on the wnoderful [noble](https://github.com/sandeepmistry/noble)
  13. \* **_edit: after some fixes, it now works fine on Apple's Macintosh Operating System, GNU/Linux and Microsoft Windows 10_**
  14. ## use:
  15. * with a bulb you know
  16. ```js
  17. const {pair, setColor} = require('kasa')
  18. pair({
  19. name: 'Smart Light',
  20. password: 'password obtained from adb lolcat',
  21. address: 'ca:fe:0f:be:ef' // address of light
  22. }, dispatch => {
  23. // red, green, blue, brightness
  24. dispatch(setColor(0xff, 0x2a, 0x50, 0xff))
  25. })
  26. ```
  27. * with a bulb you've never met:
  28. ```js
  29. const {discover, pair, setColor} = require('kasa')
  30. discover({
  31. name: 'Smart Light', // defaults to Smart Light
  32. password: 'get this from adb lolcat'
  33. }, blub => {
  34. console.log('a real lootblub!', blub.address)
  35. pair(blub, dispatch => {
  36. dispatch(setColor(0x33, 0xcc, 0xff, 0xff))
  37. })
  38. })
  39. ```
  40. * there is also a promise api (note that you will only get the first bulb
  41. discovered this way, but the callback will keep calling you up with every
  42. light it finds)
  43. ```js
  44. const {discover, pair, setColor} = require('kasa')
  45. discover()
  46. .then(pair)
  47. .then(dispatch => dispatch(setColor(0xff, 0xff, 0xff, 0xff)))
  48. ```
  49. there are some silly examples in the directory called `play/`
  50. ## api
  51. ```js
  52. module.exports {
  53. // find a bulb or every bulb forever
  54. discover({name?, password?, address?}, callback?) -> Promise{Peripheral}
  55. pair({Peripheral?, callback?) -> Promise{dispatch()}
  56. // these return an array for use by the dispatch function that you get as
  57. // a gift for pairing a peripheral
  58. setColor(red, green, blue, brightness) -> [0xffff, 0xc1, ...args]
  59. setDefaultColor(red, green, blue, brightness) -> [0xffff, 0xc4, ...args]
  60. }
  61. // when a bulb gets paired it returns a function (to callback and .then)
  62. // that lets you send commands to the bulb. i have called it dispatch because
  63. // i use redux at work every day and it seemed like the most appropriate word
  64. // because i don't know many words
  65. // it creates the packet and sends it to the blub
  66. // it returns an error if the command failed. i have never seen this happen so
  67. // i don't have much information on that
  68. dispatch([id, command, data], callback?) -> Promise{error}
  69. ```
  70. note: there is currently a bug in noble that means it doesn't close even when
  71. we stop scanning, because it is still listening out for adapter changes. once
  72. the fix for that has merged, a `.stop()` will be added to the exports.
  73. ## tests
  74. * there are literally none
  75. *  
  76. *  
  77. *  
  78. ## todo:
  79. * clean up the code (vague!)
  80. * fix vague todo items (which?)
  81. * find out why my tongue has lumps on it* \***_edit: the lumps are gone_**
  82. * revise the api when i have had literally any sleep in the past 3 years
  83. * get rich, die old
  84. * get to the top of Tom's top 8
  85. * wear sunscreen
  86. * learn the xaphoon* \***_edit: i can play happy birthday on it_**
  87. * see how lb is doin
  88. * switch to crypto-js and pull parts out and see if this can run in web browsers
  89. <!-- i hope you are okay, i love you a lot -->