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

27 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-08-31 13:41 -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 

14class BasicCommands(): 

15 """Basic commands class.""" 

16 def __init__(self, state): 

17 self.broker = BrokerConnect(state) 

18 self.state = state 

19 

20 def wait(self, duration): 

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

22 

23 self.state.print_status(description=f"Waiting for {duration} milliseconds...") 

24 

25 wait_message = { 

26 "kind": "wait", 

27 "args": { 

28 "milliseconds": duration 

29 } 

30 } 

31 

32 self.broker.publish(wait_message) 

33 

34 def e_stop(self): 

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

36 

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

38 

39 stop_message = { 

40 "kind": "emergency_lock", 

41 "args": {} 

42 } 

43 

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

45 self.broker.publish(stop_message) 

46 

47 def unlock(self): 

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

49 

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

51 

52 unlock_message = { 

53 "kind": "emergency_unlock", 

54 "args": {} 

55 } 

56 

57 unlock_message = self.broker.wrap_message(unlock_message, priority=9000) 

58 self.broker.publish(unlock_message) 

59 

60 def reboot(self): 

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

62 

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

64 

65 reboot_message = { 

66 "kind": "reboot", 

67 "args": { 

68 "package": "farmbot_os" 

69 } 

70 } 

71 

72 self.broker.publish(reboot_message) 

73 

74 def shutdown(self): 

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

76 

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

78 

79 shutdown_message = { 

80 "kind": "power_off", 

81 "args": {} 

82 } 

83 

84 self.broker.publish(shutdown_message)