Test Smart Brain implementation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smart_brain_test.py 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import config
  2. import mqtt
  3. import readline
  4. from simulation.rooms import house
  5. import sys
  6. from tests.all import test_smarthome
  7. # TODO: Extend tests in simulation
  8. # - Switching button functions (gfw_dirk, ffe.sleep)
  9. # - Brightness button functions (gfw.dirk, ffe.sleep)
  10. # - Synch functions of amplifier with spotify, mpd
  11. # - Remote actions after amplifier on
  12. # - Heating functionality (extended: mode switch off by other function, timer)
  13. # - Circulation pump (Extend Timer)
  14. # - Stairways (Extend Motion sensor and Timer)
  15. if __name__ == "__main__":
  16. mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER,
  17. password=config.MQTT_PASSWORD, name=config.APP_NAME + '_simulation')
  18. #
  19. COMMANDS = ['quit', 'help']
  20. #
  21. h = house(mc)
  22. for name in h.getmembers():
  23. d = h.getobjbyname(name)
  24. for c in d.capabilities():
  25. COMMANDS.append(name + '.' + c)
  26. #
  27. ts = test_smarthome(h, mc)
  28. for name in ts.getmembers():
  29. d = ts.getobjbyname(name)
  30. for c in d.capabilities():
  31. COMMANDS.append('test.' + name + '.' + c)
  32. def reduced_list(text):
  33. """
  34. Create reduced completation list
  35. """
  36. reduced_list = {}
  37. for cmd in COMMANDS:
  38. next_dot = cmd[len(text):].find('.')
  39. if next_dot >= 0:
  40. reduced_list[cmd[:len(text) + next_dot + 1]] = None
  41. else:
  42. reduced_list[cmd] = None
  43. return reduced_list.keys()
  44. def completer(text, state):
  45. """
  46. Our custom completer function
  47. """
  48. options = [x for x in reduced_list(text) if x.startswith(text)]
  49. return options[state]
  50. def complete(text, state):
  51. for cmd in COMMANDS:
  52. if cmd.startswith(text):
  53. if not state:
  54. hit = ""
  55. index = 0
  56. sub_list = cmd.split('.')
  57. while len(text) >= len(hit):
  58. hit += sub_list[index] + '.'
  59. return hit # cmd
  60. else:
  61. state -= 1
  62. if len(sys.argv) == 1:
  63. readline.parse_and_bind("tab: complete")
  64. readline.set_completer(completer)
  65. print("\nEnter command: ")
  66. while True:
  67. userfeedback = input('')
  68. command = userfeedback.split(' ')[0]
  69. if userfeedback == 'quit':
  70. break
  71. elif userfeedback == 'help':
  72. print("Help is not yet implemented!")
  73. elif userfeedback.startswith("test"):
  74. ts.command(userfeedback)
  75. elif command in COMMANDS[2:]:
  76. h.command(userfeedback)
  77. elif userfeedback != "":
  78. print("Unknown command!")
  79. else:
  80. print()
  81. else:
  82. cmd = sys.argv[1]
  83. if cmd.startswith('test'):
  84. ts.command(cmd)
  85. else:
  86. h.command(cmd)
  87. ts.close()