Mercurial > code > home > repos > homeauto
comparison service/mqtt_graph_bridge/mqtt_graph_bridge.py @ 586:b112da45e035
fix str/bytes to mqtt client
Ignore-this: 6840d55dfdf0408cee1b4fb39a4b3c7c
author | drewp@bigasterisk.com |
---|---|
date | Fri, 10 May 2019 02:28:14 -0700 |
parents | 30022797642e |
children | e1ee6661329a |
comparison
equal
deleted
inserted
replaced
585:bac05a73a8ab | 586:b112da45e035 |
---|---|
52 if stmt[0:2] == (dev, ROOM['brightness']): | 52 if stmt[0:2] == (dev, ROOM['brightness']): |
53 for chan, scale in [('w1', 1), | 53 for chan, scale in [('w1', 1), |
54 ('r', 1), | 54 ('r', 1), |
55 ('g', .8), | 55 ('g', .8), |
56 ('b', .8)]: | 56 ('b', .8)]: |
57 out = stmt[2].toPython() * scale | 57 out = stmt[2].toPython() * scale |
58 topic = f"{attrs['root']}/light/kit_{chan}/command" | |
58 self.settings.mqtt.publish( | 59 self.settings.mqtt.publish( |
59 "%s/light/kit_%s/command" % (attrs['root'], chan), | 60 topic.encode('ascii'), |
60 json.dumps({ | 61 json.dumps({ |
61 'state': 'ON', | 62 'state': 'ON', |
62 'brightness': int(out * 255)})) | 63 'brightness': int(out * 255)}).encode('ascii')) |
63 self.settings.masterGraph.patchObject( | 64 self.settings.masterGraph.patchObject( |
64 attrs['ctx'], | 65 attrs['ctx'], |
65 stmt[0], stmt[1], stmt[2]) | 66 stmt[0], stmt[1], stmt[2]) |
66 ignored = False | 67 ignored = False |
67 if ignored: | 68 if ignored: |
75 """) | 76 """) |
76 verboseLogging(arg['-v']) | 77 verboseLogging(arg['-v']) |
77 | 78 |
78 masterGraph = PatchableGraph() | 79 masterGraph = PatchableGraph() |
79 | 80 |
80 mqtt = MqttClient(brokerPort=1883) | 81 mqtt = MqttClient(clientId='mqtt_graph_bridge', brokerPort=1883) |
81 | 82 |
82 port = 10008 | 83 port = 10008 |
83 reactor.listenTCP(port, cyclone.web.Application([ | 84 reactor.listenTCP(port, cyclone.web.Application([ |
84 (r"/()", cyclone.web.StaticFileHandler, | 85 (r"/()", cyclone.web.StaticFileHandler, |
85 {"path": ".", "default_filename": "index.html"}), | 86 {"path": ".", "default_filename": "index.html"}), |