Skip to content

Commit 5d7caa2

Browse files
Juliana MashonJuliana Mashon
Juliana Mashon
authored and
Juliana Mashon
committed
Added get_xyz()
1 parent 229f1fa commit 5d7caa2

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

broker_functions.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def read_status(self):
3232

3333
status_tree = self.broker_connect.last_message
3434

35-
return print(json.dumps(status_tree, indent=4))
35+
return status_tree
3636

3737
def read_sensor(self, id):
3838
peripheral_str = self.api.get_info('peripherals', id)
@@ -56,12 +56,7 @@ def read_sensor(self, id):
5656
}]
5757
}
5858

59-
self.broker_connect.publish(read_sensor_message)
60-
self.broker_connect.listen(5, 'status')
61-
62-
sensor_data = self.broker_connect.last_message
63-
64-
return print(sensor_data)
59+
# return ...
6560

6661
def message(self, message, type=None, channel=None):
6762
message_message = {
@@ -311,7 +306,20 @@ def detect_weeds(self):
311306
self.broker_connect.publish(detect_weeds_message)
312307
# return ...
313308

314-
# get_xyz() --> requires read_status() --> LUA
309+
def get_xyz(self):
310+
tree_data = self.read_status()
311+
312+
position = tree_data["position"]
313+
314+
x_val = position['x']
315+
y_val = position['y']
316+
z_val = position['z']
317+
318+
return print(f'Garden size:\n'
319+
f'\tx = {x_val:.2f}\n'
320+
f'\ty = {y_val:.2f}\n'
321+
f'\tz = {z_val:.2f}')
322+
315323
# check_position() --> requires read_status() --> LUA
316324

317325
def move(self, x, y, z):

0 commit comments

Comments
 (0)