This commit is contained in:
2015-04-17 01:18:48 +02:00
parent 086c2591ae
commit c3bbf7252d
1902 changed files with 28413 additions and 111540 deletions
+2 -2
View File
@@ -46,11 +46,11 @@ if __name__ == '__main__':
msg_body["alert"] = dict()
msg_body["alert"]["type"] = "hos/huelight/command/alert"
msg_body["alert"]["set"] = "lselect"
msg_body["alert"]["set"] = "none"
msg_body["effect"] = dict()
msg_body["effect"]["type"] = "hos/huelight/command/effect"
msg_body["effect"]["set"] = "colorloop"
msg_body["effect"]["set"] = "none"
msg_body["advproperties"] = dict()
msg_body["advproperties"]["type"] = "hos/huelight/command/advproperties"
@@ -13,6 +13,7 @@ from hos_core_msgs.msg import HosStatusUpdate
from jsonspec_hos.reference.providers import HOSParamServerProvider
from jsonspec.validators import load
from curses.has_key import has_key
from time import sleep
@@ -22,6 +23,7 @@ class HueLight(object):
self.name = name
class HueController(object):
def __init__(self):
# Init ROS node
@@ -41,14 +43,40 @@ class HueController(object):
# Connect to bridge
self.hue_bridge = pyhue.Bridge(self.bridge_ip, self.bridge_secret)
# Retrieve connected devices from bride
new_devices = list()
for light in self.hue_bridge.lights:
name = self.getDeviceName(light)
self.lights[name] = HueLight(light, name)
new_devices.append(name)
print "Found hue light \"" + light.name + "\", assigned id = " + name
# Add device to device repository
key_base = "/hos/devices/repository/" + name
rospy.set_param(key_base + "/type", "hue/huelight")
rospy.set_param(key_base + "/status_topic", self.status_topic)
rospy.set_param(key_base + "/cmd_topic", self.cmd_topic)
# Create JSON schema provider
self.schemaProvider = HOSParamServerProvider()
# Create message publisher
self.statusPublisher = rospy.Publisher(self.status_topic, DeviceStatusUpdate, queue_size=10)
self.hosUpdatePublisher = rospy.Publisher(self.hos_update_topic, HosStatusUpdate, queue_size=10)
# Send HOS Status Update Message
updMsg = HosStatusUpdate()
stamp = rospy.get_rostime()
updMsg.stamp = stamp
updMsg.tags.append("devices")
updBody = dict()
updBody["type"] = "core/msgs/hosstatusupdate"
updBody["devices"] = dict()
updBody["devices"]["type"] = "core/msgs/hosstatusupdate/devices";
updBody["devices"]["added"] = new_devices
msg_schema = self.schemaProvider.getTypeSchema("core/msgs/hosstatusupdate")
validator = load(msg_schema, provider=self.schemaProvider)
validator.validate(updBody)
updMsg.msg_body = json.dumps(updBody)
sleep(1) # Apparently we need to wait before we can send messages
self.hosUpdatePublisher.publish(updMsg)
def getDeviceName(self, light):
@@ -63,7 +91,7 @@ class HueController(object):
msg.stamp = stamp
msg_body = dict()
msg_body["type"] = "hos/huelight/status"
msg_body["type"] = "hue/huelight/status"
msg_body["switch"] = dict()
msg_body["switch"]["type"] = "core/types/boolean/status"
@@ -82,11 +110,11 @@ class HueController(object):
msg_body["color"]["value_ct"] = [ light.state["ct"] ]
msg_body["alert"] = dict()
msg_body["alert"]["type"] = "hos/huelight/status/alert"
msg_body["alert"]["type"] = "hue/huelight/status/alert"
msg_body["alert"]["value"] = light.state["alert"]
msg_body["effect"] = dict()
msg_body["effect"]["type"] = "hos/huelight/status/effect"
msg_body["effect"]["type"] = "hue/huelight/status/effect"
msg_body["effect"]["value"] = light.state["effect"]
msg_schema = self.schemaProvider.getTypeSchema("hue/huelight/status")
@@ -98,7 +126,7 @@ class HueController(object):
def deviceCmdCallback(self, data):
rospy.loginfo(rospy.get_caller_id() + "I heard %s", str(data))
rospy.loginfo(rospy.get_caller_id() + ": I heard %s", str(data))
try:
light = self.lights[data.device_id]
except:
@@ -176,7 +204,6 @@ class HueController(object):
light.light.setStateAttr("transitiontime", value["transitiontime"])
light.light.commitStateAttrs()
light.light.refreshAttrs()
def deviceStatusCallback(self):
@@ -198,5 +225,12 @@ class HueController(object):
else:
status_timer += 1
rate.sleep()
# Remove devices from device repository
for key in self.lights:
light = self.lights[key]
key_base = "/hos/devices/repository/" + light.name
print "Remove device " + light.name + " from repository"
rospy.delete_param(key_base)
@@ -8,7 +8,7 @@
"type": {
"description": "",
"type": "string",
"pattern": "hos/huelight/command"
"pattern": "hue/huelight/command"
},
"switch": {
"$ref": "hos:schema://core/types/boolean/command"
@@ -25,7 +25,7 @@
"properties": {
"type": {
"type": "string",
"pattern": "hos/huelight/command/alert"
"pattern": "hue/huelight/command/alert"
},
"set": {
"type": "string",
@@ -41,7 +41,7 @@
"properties": {
"type": {
"type": "string",
"pattern": "hos/huelight/command/effect"
"pattern": "hue/huelight/command/effect"
},
"set": {
"type": "string",
@@ -57,7 +57,7 @@
"properties": {
"type": {
"type": "string",
"pattern": "hos/huelight/command/advproperties"
"pattern": "hue/huelight/command/advproperties"
},
"transitiontime": {
"type": "integer"
@@ -8,7 +8,7 @@
"type": {
"description": "",
"type": "string",
"pattern": "hos/huelight/status"
"pattern": "hue/huelight/status"
},
"switch": {
"$ref": "hos:schema://core/types/boolean/status"
@@ -25,7 +25,7 @@
"properties": {
"type": {
"type": "string",
"pattern": "hos/huelight/status/alert"
"pattern": "hue/huelight/status/alert"
},
"value": {
"type": "string",
@@ -41,7 +41,7 @@
"properties": {
"type": {
"type": "string",
"pattern": "hos/huelight/status/effect"
"pattern": "hue/huelight/status/effect"
},
"value": {
"type": "string",