Test Smart Brain implementation
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

smart_brain_test.py 3.1KB

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