Skip to content

Commit

Permalink
switch OutletStatus from string to bool
Browse files Browse the repository at this point in the history
  • Loading branch information
johnwaalsh committed Jan 2, 2025
1 parent 381ade9 commit 42657bc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/phyto_arm/msg/OutletStatus.msg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
string name
string status
bool is_active
15 changes: 4 additions & 11 deletions src/phyto_arm/src/digital_logger_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,11 @@ def run(self):
except urllib.error.URLError as url_err:
raise ValueError(f"URL Error: {url_err.reason}") from url_err

# DL API uses 'true' and 'false' to denote outlet status, which need to be converted to Python bools
if response_data == 'true':
status = 'on'
else:
status = 'off'

# publish the status of each outlet to its specific topic
outlet_status = OutletStatus()
outlet_status.name = self.outlets[outlet_index]['name']
outlet_status.status = status
# DL API uses 'true' and 'false' to denote outlet status, which need to be converted to Python bools
outlet_status.is_active = response_data == 'true'

self.outlet_publishers[outlet_index].publish(outlet_status)

Expand All @@ -75,9 +70,7 @@ def control_outlet(self, msg):

outlet_num = self.outlet_names.get(msg.name)

status = msg.status == 'on'

data = f'value={str(status).lower()}'
data = f'value={str(msg.is_active).lower()}'
url = f'http://{self.address}/restapi/relay/outlets/{outlet_num}/state/'

# Create a PUT request
Expand All @@ -95,7 +88,7 @@ def control_outlet(self, msg):

result = response.read().decode('utf-8')

rospy.loginfo(f'sent status={str(status).lower()} to {self.address}:{url}, received: code {response.status} : {result}')
rospy.loginfo(f'sent status={str(msg.is_active).lower()} to {self.address}:{url}, received: code {response.status} : {result}')


if __name__ == '__main__':
Expand Down

0 comments on commit 42657bc

Please sign in to comment.