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
« prev ^ index » next coverage.py v7.4.4, created at 2024-09-12 12:03 -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
15class BasicCommands():
16 """Basic commands class."""
18 def __init__(self, state):
19 self.broker = BrokerConnect(state)
20 self.state = state
22 def wait(self, duration):
23 """Pauses execution for a certain number of milliseconds."""
25 description = f"Waiting for {duration} milliseconds..."
26 self.state.print_status(description=description)
28 wait_message = {
29 "kind": "wait",
30 "args": {
31 "milliseconds": duration
32 }
33 }
35 self.broker.publish(wait_message)
37 def e_stop(self):
38 """Emergency locks (E-stops) the Farmduino microcontroller."""
40 self.state.print_status(description="Emergency stopping device")
42 stop_message = {
43 "kind": "emergency_lock",
44 "args": {}
45 }
47 stop_message = self.broker.wrap_message(stop_message, priority=9000)
48 self.broker.publish(stop_message)
50 def unlock(self):
51 """Unlocks a locked (E-stopped) device."""
53 self.state.print_status(description="Unlocking device")
55 unlock_message = {
56 "kind": "emergency_unlock",
57 "args": {}
58 }
60 unlock_message = self.broker.wrap_message(
61 unlock_message,
62 priority=9000)
63 self.broker.publish(unlock_message)
65 def reboot(self):
66 """Reboots the FarmBot OS and re-initializes the device."""
68 self.state.print_status(description="Rebooting device")
70 reboot_message = {
71 "kind": "reboot",
72 "args": {
73 "package": "farmbot_os"
74 }
75 }
77 self.broker.publish(reboot_message)
79 def shutdown(self):
80 """Shuts down the FarmBot OS and turns the device off."""
82 self.state.print_status(description="Shutting down device")
84 shutdown_message = {
85 "kind": "power_off",
86 "args": {}
87 }
89 self.broker.publish(shutdown_message)