Coverage for functions/basic_commands.py: 100%
27 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-08-30 11:51 -0700
« prev ^ index » next coverage.py v7.4.4, created at 2024-08-30 11:51 -0700
1"""
2BasicCommands class.
3"""
5# └── functions/basic_commands.py
6# ├── [BROKER] wait()
7# ├── [BROKER] e_stop()
8# ├── [BROKER] unlock()
9# ├── [BROKER] reboot()
10# └── [BROKER] shutdown()
12from .broker import BrokerConnect
14class BasicCommands():
15 """Basic commands class."""
16 def __init__(self, state):
17 self.broker = BrokerConnect(state)
18 self.state = state
20 def wait(self, duration):
21 """Pauses execution for a certain number of milliseconds."""
23 self.state.print_status(description=f"Waiting for {duration} milliseconds...")
25 wait_message = {
26 "kind": "wait",
27 "args": {
28 "milliseconds": duration
29 }
30 }
32 self.broker.publish(wait_message)
34 def e_stop(self):
35 """Emergency locks (E-stops) the Farmduino microcontroller."""
37 self.state.print_status(description="Emergency stopping device")
39 stop_message = {
40 "kind": "emergency_lock",
41 "args": {}
42 }
44 stop_message = self.broker.wrap_message(stop_message, priority=9000)
45 self.broker.publish(stop_message)
47 def unlock(self):
48 """Unlocks a locked (E-stopped) device."""
50 self.state.print_status(description="Unlocking device")
52 unlock_message = {
53 "kind": "emergency_unlock",
54 "args": {}
55 }
57 unlock_message = self.broker.wrap_message(unlock_message, priority=9000)
58 self.broker.publish(unlock_message)
60 def reboot(self):
61 """Reboots the FarmBot OS and re-initializes the device."""
63 self.state.print_status(description="Rebooting device")
65 reboot_message = {
66 "kind": "reboot",
67 "args": {
68 "package": "farmbot_os"
69 }
70 }
72 self.broker.publish(reboot_message)
74 def shutdown(self):
75 """Shuts down the FarmBot OS and turns the device off."""
77 self.state.print_status(description="Shutting down device")
79 shutdown_message = {
80 "kind": "power_off",
81 "args": {}
82 }
84 self.broker.publish(shutdown_message)