Coverage for functions/tools.py: 100%
23 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"""
2ToolControls class.
3"""
5# └── functions/tools.py
6# ├── [BROKER] verify_tool()
7# ├── [BROKER] mount_tool()
8# ├── [BROKER] dismount_tool()
9# ├── [BROKER] water()
10# └── [BROKER] dispense()
12from .broker import BrokerConnect
13from .resources import Resources
15class ToolControls():
16 """Tool controls class."""
17 def __init__(self, state):
18 self.broker = BrokerConnect(state)
19 self.resource = Resources(state)
20 self.state = state
22 # TODO: verify_tool()
24 def mount_tool(self, tool_str):
25 """Mounts the given tool and pulls it out of assigned slot."""
26 self.state.print_status(description=f"Mounting {tool_str} tool.")
28 lua_code = f"""
29 mount_tool("{tool_str}")
30 """
32 self.resource.lua(lua_code)
34 def dismount_tool(self):
35 """Dismounts the currently mounted tool into assigned slot."""
36 self.state.print_status(description="Dismounting tool.")
38 lua_code = """
39 dismount_tool()
40 """
42 self.resource.lua(lua_code)
44 def water(self, plant_id):
45 """Moves to and waters plant based on age and assigned watering curve."""
46 self.state.print_status(description=f"Watering plant {plant_id}...")
48 lua_code = f"""
49 plant = api({
50 method = "GET",
51 url = "/api/points/{plant_id}"
52 } )
53 water(plant)
54 """
56 self.resource.lua(lua_code)
58 def dispense(self, milliliters, tool_name, pin):
59 """Dispenses user-defined amount of liquid in milliliters."""
60 self.state.print_status(description=f"Dispensing {milliliters} from tool {tool_name}...")
62 lua_code = f"""
63 dispense({milliliters}, { tool_name = "{tool_name}", pin = {pin}} )
64 """
66 self.resource.lua(lua_code)