Coverage for farmbot/functions/basic_commands.py: 100%

28 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-09-12 12:03 -0700

1""" 

2BasicCommands class. 

3""" 

4 

5# └── functions/basic_commands.py 

6# ├── [BROKER] wait() 

7# ├── [BROKER] e_stop() 

8# ├── [BROKER] unlock() 

9# ├── [BROKER] reboot() 

10# └── [BROKER] shutdown() 

11 

12from .broker import BrokerConnect 

13 

14 

15class BasicCommands(): 

16 """Basic commands class.""" 

17 

18 def __init__(self, state): 

19 self.broker = BrokerConnect(state) 

20 self.state = state 

21 

22 def wait(self, duration): 

23 """Pauses execution for a certain number of milliseconds.""" 

24 

25 description = f"Waiting for {duration} milliseconds..." 

26 self.state.print_status(description=description) 

27 

28 wait_message = { 

29 "kind": "wait", 

30 "args": { 

31 "milliseconds": duration 

32 } 

33 } 

34 

35 self.broker.publish(wait_message) 

36 

37 def e_stop(self): 

38 """Emergency locks (E-stops) the Farmduino microcontroller.""" 

39 

40 self.state.print_status(description="Emergency stopping device") 

41 

42 stop_message = { 

43 "kind": "emergency_lock", 

44 "args": {} 

45 } 

46 

47 stop_message = self.broker.wrap_message(stop_message, priority=9000) 

48 self.broker.publish(stop_message) 

49 

50 def unlock(self): 

51 """Unlocks a locked (E-stopped) device.""" 

52 

53 self.state.print_status(description="Unlocking device") 

54 

55 unlock_message = { 

56 "kind": "emergency_unlock", 

57 "args": {} 

58 } 

59 

60 unlock_message = self.broker.wrap_message( 

61 unlock_message, 

62 priority=9000) 

63 self.broker.publish(unlock_message) 

64 

65 def reboot(self): 

66 """Reboots the FarmBot OS and re-initializes the device.""" 

67 

68 self.state.print_status(description="Rebooting device") 

69 

70 reboot_message = { 

71 "kind": "reboot", 

72 "args": { 

73 "package": "farmbot_os" 

74 } 

75 } 

76 

77 self.broker.publish(reboot_message) 

78 

79 def shutdown(self): 

80 """Shuts down the FarmBot OS and turns the device off.""" 

81 

82 self.state.print_status(description="Shutting down device") 

83 

84 shutdown_message = { 

85 "kind": "power_off", 

86 "args": {} 

87 } 

88 

89 self.broker.publish(shutdown_message)