Mercurial > code > home > repos > homeauto
annotate service/reasoning/actions.py @ 1047:e3d77b7f16ca
rearrange Actions
Ignore-this: abd7b4dbaa1e83f071ae898b78344068
darcs-hash:84c6fae3fc79b2ecc0556a2dc1362add830c2998
author | drewp <drewp@bigasterisk.com> |
---|---|
date | Tue, 02 Feb 2016 01:52:29 -0800 |
parents | a328cc370b22 |
children | b0089d1ca4f6 |
rev | line source |
---|---|
1045
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
1 from rdflib import URIRef, Namespace, RDF, Literal |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
2 import logging |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
3 import urllib |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
4 |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
5 from cyclone.httpclient import fetch |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
6 log = logging.getLogger('output') |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
7 log.setLevel(logging.WARN) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
8 |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
9 ROOM = Namespace("http://projects.bigasterisk.com/room/") |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
10 DEV = Namespace("http://projects.bigasterisk.com/device/") |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
11 |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
12 class Actions(object): |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
13 def __init__(self, sendToLiveClients): |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
14 self.sendToLiveClients = sendToLiveClients |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
15 |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
16 def putResults(self, deviceGraph, inferred): |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
17 """ |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
18 some conclusions in the inferred graph lead to PUT requests |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
19 getting made |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
20 |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
21 if the graph contains (?d ?p ?o) and ?d and ?p are a device |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
22 and predicate we support PUTs for, then we look up |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
23 (?d :putUrl ?url) and (?o :putValue ?val) and call |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
24 PUT ?url <- ?val |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
25 |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
26 If the graph doesn't contain any matches, we use (?d |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
27 :zeroValue ?val) for the value and PUT that. |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
28 """ |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
29 |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
30 self._oneShotPostActions(deviceGraph, inferred) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
31 for dev, pred in [ |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
32 # the config of each putUrl should actually be in the |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
33 # context of a dev and predicate pair, and then that would |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
34 # be the source of this list |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
35 #(DEV.theaterDoorLock, ROOM.state), |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
36 #(URIRef('http://bigasterisk.com/host/bang/monitor'), ROOM.powerState), |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
37 (URIRef('http://bigasterisk.com/host/dash/monitor'), ROOM.powerState), |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
38 (URIRef('http://projects.bigasterisk.com/room/storageCeilingLedLong'), ROOM.brightness), |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
39 (URIRef('http://projects.bigasterisk.com/room/storageCeilingLedCross'), ROOM.brightness), |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
40 ]: |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
41 url = deviceGraph.value(dev, ROOM.putUrl) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
42 |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
43 if url and dev == DEV.theaterDoorLock: # ew |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
44 self._put(url+"/mode", payload="output") |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
45 |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
46 inferredObjects = list(inferred.objects(dev, pred)) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
47 if len(inferredObjects) == 0: |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
48 self._putZero(deviceGraph, dev, pred, url) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
49 elif len(inferredObjects) == 1: |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
50 self._putInferred(deviceGraph, url, inferredObjects[0]) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
51 elif len(inferredObjects) > 1: |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
52 log.info("conflict, ignoring: %s has %s of %s" % |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
53 (dev, pred, inferredObjects)) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
54 # write about it to the inferred graph? |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
55 |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
56 #self._frontDoorPuts(deviceGraph, inferred) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
57 |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
58 def _oneShotPostActions(self, deviceGraph, inferred): |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
59 """ |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
60 Inferred graph may contain some one-shot statements. We'll send |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
61 statement objects to anyone on web sockets, and also generate |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
62 POST requests as described in the graph. |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
63 |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
64 one-shot statement ?s ?p ?o |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
65 with this in the graph: |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
66 ?osp a :OneShotPost |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
67 ?osp :subject ?s |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
68 ?osp :predicate ?p |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
69 this will cause a post to ?o |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
70 """ |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
71 # nothing in this actually makes them one-shot yet. they'll |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
72 # just fire as often as we get in here, which is not desirable |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
73 log.info("_oneShotPostActions") |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
74 def err(e): |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
75 log.warn("post %s failed", postTarget) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
76 for osp in deviceGraph.subjects(RDF.type, ROOM['OneShotPost']): |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
77 s = deviceGraph.value(osp, ROOM['subject']) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
78 p = deviceGraph.value(osp, ROOM['predicate']) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
79 if s is None or p is None: |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
80 continue |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
81 for postTarget in inferred.objects(s, p): |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
82 log.info("post target %r", postTarget) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
83 # this packet ought to have 'oneShot' in it somewhere |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
84 self.sendToLiveClients({"s":s, "p":p, "o":postTarget}) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
85 |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
86 log.info(" POST %s", postTarget) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
87 fetch(postTarget, method="POST", timeout=2).addErrback(err) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
88 self._postMpdCommands(inferred) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
89 |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
90 def _postMpdCommands(self, inferred): |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
91 """special case to be eliminated. mpd play urls are made of an |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
92 mpd service and a song/album/playlist uri to be played. |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
93 Ideally the graph rules would assemble these like |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
94 http://{mpd}/addAndPlay?uri={toPlay} or maybe toPlay as the payload |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
95 which would be fairly general but still allow toPlay uris to |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
96 be matched with any player.""" |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
97 |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
98 rootSkippingAuth = "http://brace:9009/" |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
99 for mpd in [URIRef("http://bigasterisk.com/host/brace/mpd")]: |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
100 |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
101 for song in inferred.objects(mpd, ROOM['startMusic']): |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
102 log.info("mpd statement: %r" % song) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
103 assert song.startswith('http://bigasterisk.com/music/') |
1047 | 104 self.post(rootSkippingAuth + "addAndPlay" + urllib.quote(song[len("http://bigasterisk.com/music"):])) |
1045
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
105 |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
106 for state in inferred.objects(mpd, ROOM['playState']): |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
107 log.info('hello playstate %s', state) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
108 if state == ROOM['pause']: |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
109 log.info("mpd %s %s", mpd, state) |
1047 | 110 self.post(rootSkippingAuth + "mpd/pause") |
1045
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
111 for vol in inferred.objects(mpd, ROOM['audioState']): |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
112 if vol == ROOM['volumeStepUp']: |
1047 | 113 self.post(rootSkippingAuth + "volumeAdjust?amount=6&max=70") |
1045
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
114 if vol == ROOM['volumeStepDown']: |
1047 | 115 self.post(rootSkippingAuth + "volumeAdjust?amount=-6&min=10") |
1045
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
116 |
1047 | 117 |
118 def _frontDoorPuts(self, deviceGraph, inferred): | |
119 # todo: shouldn't have to be a special case | |
120 brt = inferred.value(DEV.frontDoorLcd, ROOM.brightness) | |
121 if brt is None: | |
122 return | |
123 url = deviceGraph.value(DEV.frontDoorLcdBrightness, ROOM.putUrl) | |
124 log.info("put lcd %s brightness %s", url, brt) | |
125 self._put(str(url) + "?brightness=%s" % str(brt), payload='') | |
126 | |
127 msg = "open %s motion %s" % ( | |
128 inferred.value(DEV['frontDoorOpenIndicator'], ROOM.text), | |
129 inferred.value(DEV['frontDoorMotionIndicator'], ROOM.text)) | |
130 # this was meant to be 2 chars in the bottom row, but the | |
131 # easier test was to replace the whole top msg | |
132 #restkit.Resource("http://slash:9080/").put("lcd", message=msg) | |
133 | |
134 | |
135 | |
136 | |
137 def _put(self, url, payload): | |
138 def err(e): | |
139 log.warn(" put %s failed (%r)", url, e) | |
140 log.info(" PUT %s payload=%r", url, payload) | |
141 fetch(url, method="PUT", postdata=payload, timeout=2).addErrback(err) | |
142 | |
143 def post(self, postTarget): | |
144 log.info("special mpd POST %s", postTarget) | |
145 def err(e): | |
146 log.warn("post %s failed", postTarget) | |
147 fetch(postTarget, method="POST", timeout=2).addErrback(err) | |
148 | |
1045
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
149 def _putZero(self, deviceGraph, dev, pred, putUrl): |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
150 # zerovalue should be a function of pred as well. |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
151 value = deviceGraph.value(dev, ROOM.zeroValue) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
152 if value is not None: |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
153 log.info("put zero (%r) to %s", value, putUrl) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
154 self._put(putUrl, payload=str(value)) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
155 # this should be written back into the inferred graph |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
156 # for feedback |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
157 |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
158 def _putInferred(self, deviceGraph, putUrl, obj): |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
159 """ |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
160 HTTP PUT to putUrl, with a payload that's either obj's :putValue |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
161 or obj itself. |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
162 """ |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
163 value = deviceGraph.value(obj, ROOM.putValue) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
164 if value is not None: |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
165 log.info("put %s to %s", value, putUrl) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
166 self._put(putUrl, payload=str(value)) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
167 elif isinstance(obj, Literal): |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
168 log.info("put %s to %s", obj, putUrl) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
169 self._put(putUrl, payload=str(obj)) |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
170 else: |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
171 log.warn("don't know what payload to put for %s. obj=%r", |
a328cc370b22
ipv6 fetch support. refactor Actions to new class and file
drewp <drewp@bigasterisk.com>
parents:
diff
changeset
|
172 putUrl, obj) |