Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import binascii
  4. from bluepy.btle import Peripheral
  5.  
  6. class SwitchBot:
  7. def __init__(self, mac_address):
  8. self.p = Peripheral(mac_address, "random")
  9. hand_service = self.p.getServiceByUUID("cba20d00-224d-11e6-9fb8-0002a5d5c51b")
  10. self.hand = hand_service.getCharacteristics("cba20002-224d-11e6-9fb8-0002a5d5c51b")[0]
  11.  
  12. def press(self):
  13. self.hand.write(binascii.a2b_hex("570100"))
  14. self.p.disconnect()
  15.  
  16. def on(self):
  17. self.p.disconnect()
  18. raise NotImplementedError()
  19.  
  20. def off(self):
  21. self.p.disconnect()
  22. raise NotImplementedError()
  23.  
  24. if __name__ == "__main__":
  25. from optparse import OptionParser
  26. parser = OptionParser()
  27. parser.add_option("-a", "--address", dest="addr", help="MAC address of SwitchBot")
  28. parser.add_option("-c", "--command", dest="cmd", help="Command for SwitchBot (press|on|off)")
  29. (options, args) = parser.parse_args()
  30.  
  31. getattr(SwitchBot(options.addr), options.cmd)()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement