mihai-dinculescu / tapo

Unofficial Tapo API Client. Works with TP-Link Tapo smart devices. Tested with light bulbs (L510, L520, L530, L610, L630), light strips (L900, L920, L930), plugs (P100, P105, P110, P115, P300), hubs (H100), switches (S200B) and sensors (KE100, T100, T110, T300, T310, T315).
MIT License
352 stars 36 forks source link

Feature request: toggle state #67

Closed claviger-pc closed 1 year ago

claviger-pc commented 1 year ago

Would it be possible to create a toggle function by reading the json info and switching accordingly? Unfortunately I am not very familiar with Rust, and it would seem better to do this within rust rather than parsing json with some other language and setting a variable.

btw, I was able to build this with termux on Android and it is really great to be able to do things with tasker!

mihai-dinculescu commented 1 year ago

That's a very neat use case, thanks for sharing it!

How exactly did you get termux to make use of the library? Would a Rust example on how you can achieve the toggle functionality help you out?

claviger-pc commented 1 year ago

In fact, it was not too hard. Basic process was:

  1. Install rust and git on termux.
  2. Clone your repo
  3. try to build with cargo and install packages when cargo fails, needed: binutils, openssl, pkg-config
  4. run cargo successfully

There are some limitations, as I think that you have to call the binary from the command line and it may require root in some cases. But I can call it from without root from within termux and with root in tasker.

I do not know rust, and so I was hoping to avoid figuring out how to parse json, and respond accordingly based on the info function, if that is something that you could easily share a snippet for, I would greatly appreciate it. I already used the functionalities from the examples to create my own examples and have compiled them for use on windows and now android.

mihai-dinculescu commented 1 year ago

Please look at this newly added example and let me know if it answers your need. https://github.com/mihai-dinculescu/tapo/blob/main/examples/tapo_generic_device_toggle.rs

claviger-pc commented 1 year ago

perfect! This works and is exactly what I was looking for. Thank you so much!