S&B Volcano vaporizer remote control with Pi Pico W
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

flow.py 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env python
  2. import sys
  3. import asyncio
  4. from poll import (
  5. ble_conn,
  6. get_current_temp,
  7. get_target_temp, set_target_temp,
  8. get_unit_is_fahrenheit,
  9. get_state, set_state
  10. )
  11. async def wait_for_temp(client, temp):
  12. print("Setting temperature {}".format(temp))
  13. await set_target_temp(client, temp)
  14. print("Waiting for temperature to rise...")
  15. curr = await get_current_temp(client)
  16. while curr < temp:
  17. print("Currently at {}".format(curr))
  18. await asyncio.sleep(2.0)
  19. curr = await get_current_temp(client)
  20. print("Reached temperature {}".format(temp))
  21. async def flow_step(client, temp, t_wait, t_pump):
  22. await wait_for_temp(client, temp)
  23. print("Waiting {}s for heat to settle...".format(t_wait))
  24. await asyncio.sleep(t_wait)
  25. print("Pumping for {}s".format(t_pump))
  26. await set_state(client, (True, True)) # turn on pump
  27. await asyncio.sleep(t_pump)
  28. await set_state(client, (True, False)) # turn off pump
  29. async def flow(client):
  30. print("Turning on heater")
  31. await set_state(client, (True, False))
  32. await flow_step(client, 190.0, 25.0, 5.0)
  33. await flow_step(client, 205.0, 10.0, 20.0)
  34. await flow_step(client, 220.0, 10.0, 20.0)
  35. print("Notification by pumping four times...")
  36. for i in range(0, 4):
  37. await asyncio.sleep(1.0)
  38. await set_state(client, (True, True)) # turn on pump
  39. await asyncio.sleep(1.0)
  40. await set_state(client, (True, False)) # turn off pump
  41. print("Turning heater off")
  42. await set_state(client, (False, False)) # turn off heater and pump
  43. async def main(address):
  44. device = await ble_conn(address)
  45. print("Connecting...")
  46. async with device as client:
  47. try:
  48. print("Starting Workflow")
  49. await flow(client)
  50. except asyncio.exceptions.CancelledError:
  51. print("Turning heater off")
  52. await set_state(client, (False, False)) # turn off heater and pump
  53. except KeyboardInterrupt:
  54. print("Turning heater off")
  55. await set_state(client, (False, False)) # turn off heater and pump
  56. if __name__ == "__main__":
  57. if len(sys.argv) <= 1:
  58. print("Please pass MAC address of device")
  59. sys.exit(1)
  60. asyncio.run(main(sys.argv[1]))