switchbot_ros_client.py
Go to the documentation of this file.
1 import rospy
2 import actionlib
3 from switchbot_ros.msg import SwitchBotCommandAction
4 from switchbot_ros.msg import SwitchBotCommandGoal
5 from switchbot_ros.msg import DeviceArray
6 
7 
8 class SwitchBotROSClient(object):
9 
10  def __init__(self,
11  actionname='switchbot_ros/switch',
12  topicname='switchbot_ros/devices'):
13 
14  self.actionname = actionname
15  self.topicname = topicname
17  actionname,
18  SwitchBotCommandAction
19  )
20 
21  def get_devices(self, timeout=None):
22 
23  return rospy.wait_for_message(
24  self.topicname,
25  DeviceArray,
26  timeout=timeout
27  )
28 
29  def control_device(self,
30  device_name,
31  command,
32  parameter='',
33  command_type='',
34  wait=False
35  ):
36 
37  goal = SwitchBotCommandGoal()
38  goal.device_name = device_name
39  goal.command = command
40  goal.parameter = parameter
41  goal.command_type = command_type
42  self.action_client.send_goal(goal)
43  if wait:
44  self.action_client.wait_for_result()
45  return self.action_client.get_result()
def control_device(self, device_name, command, parameter='', command_type='', wait=False)
def __init__(self, actionname='switchbot_ros/switch', topicname='switchbot_ros/devices')


switchbot_ros
Author(s): Yoshiki Obinata
autogenerated on Sat Jun 24 2023 02:40:43