annotate service/rdf_to_mqtt/rdf_to_mqtt.py @ 1732:3f4b447d65f5

port to starlette/asyncio
author drewp@bigasterisk.com
date Mon, 10 Jul 2023 17:37:58 -0700
parents 80b01d548b9c
children 09df2b4b886f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
597
e1ee6661329a adjust kitchen PWM freqs. add comments and proposed contents of n3 configs
drewp@bigasterisk.com
parents: 586
diff changeset
1 """
e1ee6661329a adjust kitchen PWM freqs. add comments and proposed contents of n3 configs
drewp@bigasterisk.com
parents: 586
diff changeset
2 We get output statements that are like light9's deviceAttrs (:dev1 :color "#ff0000"),
e1ee6661329a adjust kitchen PWM freqs. add comments and proposed contents of n3 configs
drewp@bigasterisk.com
parents: 586
diff changeset
3 convert those to outputAttrs (:dev1 :red 255; :green 0; :blue 0) and post them to mqtt.
e1ee6661329a adjust kitchen PWM freqs. add comments and proposed contents of n3 configs
drewp@bigasterisk.com
parents: 586
diff changeset
4
e1ee6661329a adjust kitchen PWM freqs. add comments and proposed contents of n3 configs
drewp@bigasterisk.com
parents: 586
diff changeset
5 This is like light9/bin/collector.
e1ee6661329a adjust kitchen PWM freqs. add comments and proposed contents of n3 configs
drewp@bigasterisk.com
parents: 586
diff changeset
6 """
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
7 import asyncio
581
30022797642e mqtt_graph_bridge to new build rules and to py3
drewp@bigasterisk.com
parents: 460
diff changeset
8 import json
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
9 import os
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
10 import time
777
df7035db28f1 reformat
drewp@bigasterisk.com
parents: 776
diff changeset
11
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
12 from prometheus_client import Counter, Gauge, Summary
777
df7035db28f1 reformat
drewp@bigasterisk.com
parents: 776
diff changeset
13 from rdflib import Namespace
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
14 from starlette_exporter import PrometheusMiddleware, handle_metrics
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
15 from starlette.applications import Starlette
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
16 from starlette.requests import Request
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
17 from starlette.responses import PlainTextResponse
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
18 from starlette.routing import Route
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
19 from starlette.staticfiles import StaticFiles
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
20 import aiomqtt
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
21
1703
80b01d548b9c add new devs, factor out to devs.py
drewp@bigasterisk.com
parents: 1702
diff changeset
22 from devs import devs
694
925bc4137c93 extract rdfStatementsFromRequest for sharing with other tools
drewp@bigasterisk.com
parents: 597
diff changeset
23 import rdf_over_http
373
2158e7ad19b1 receive oneshot updates from reasoning; emit commands on MQTT to control H801 wifi dimmer
drewp@bigasterisk.com
parents:
diff changeset
24
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
25 # from victorialogger import log
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
26 import logging
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
27
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
28 logging.basicConfig(level=logging.DEBUG)
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
29 log = logging.getLogger(__name__)
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
30
373
2158e7ad19b1 receive oneshot updates from reasoning; emit commands on MQTT to control H801 wifi dimmer
drewp@bigasterisk.com
parents:
diff changeset
31 ROOM = Namespace('http://projects.bigasterisk.com/room/')
2158e7ad19b1 receive oneshot updates from reasoning; emit commands on MQTT to control H801 wifi dimmer
drewp@bigasterisk.com
parents:
diff changeset
32
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
33 PUT_REQUESTS = Summary('put_requests', 'calls')
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
34 STATEMENT = Summary('on_statement', 'calls')
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
35 MQTT_PUBLISH = Summary('mqtt_publish', 'calls')
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
36
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
37 mqtt: aiomqtt.Client | None = None
762
5943cacc8b9b stats page
drewp@bigasterisk.com
parents: 761
diff changeset
38
373
2158e7ad19b1 receive oneshot updates from reasoning; emit commands on MQTT to control H801 wifi dimmer
drewp@bigasterisk.com
parents:
diff changeset
39
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
40 class OutputPage:
778
acf58b83022f rdf_to_mqtt sylvania bulbs and code cleanup and k8s updates
drewp@bigasterisk.com
parents: 777
diff changeset
41
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
42 async def put(self, request: Request) -> PlainTextResponse:
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
43 with PUT_REQUESTS.time():
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
44 for stmt in rdf_over_http.rdfStatementsFromRequest(request.query_params, await request.body(), request.headers):
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
45 await self._onStatement(stmt)
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
46 return PlainTextResponse("ok")
694
925bc4137c93 extract rdfStatementsFromRequest for sharing with other tools
drewp@bigasterisk.com
parents: 597
diff changeset
47
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
48 @STATEMENT.time()
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
49 async def _onStatement(self, stmt):
694
925bc4137c93 extract rdfStatementsFromRequest for sharing with other tools
drewp@bigasterisk.com
parents: 597
diff changeset
50 log.info(f'incoming statement: {stmt}')
392
79d041273e26 mqtt has two devices now. various older cleanups.
drewp@bigasterisk.com
parents: 378
diff changeset
51 ignored = True
373
2158e7ad19b1 receive oneshot updates from reasoning; emit commands on MQTT to control H801 wifi dimmer
drewp@bigasterisk.com
parents:
diff changeset
52 for dev, attrs in devs.items():
696
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
53 if stmt[0] == ROOM['frontWindow']:
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
54 ignored = ignored and self._publishFrontScreenText(stmt)
373
2158e7ad19b1 receive oneshot updates from reasoning; emit commands on MQTT to control H801 wifi dimmer
drewp@bigasterisk.com
parents:
diff changeset
55 if stmt[0:2] == (dev, ROOM['brightness']):
696
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
56 log.info(f'brightness request: {stmt}')
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
57 brightness = stmt[2].toPython()
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
58
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
59 if attrs.get('values', '') == 'binary':
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
60 await self._publishOnOff(attrs, brightness)
696
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
61 else:
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
62 await self._publishRgbw(attrs, brightness)
392
79d041273e26 mqtt has two devices now. various older cleanups.
drewp@bigasterisk.com
parents: 378
diff changeset
63 ignored = False
761
78f699077ff5 more theater output controls
drewp@bigasterisk.com
parents: 741
diff changeset
64 if stmt[0:2] == (dev, ROOM['inputSelector']):
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
65 choice = stmt[2].toPython()
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
66 await self._publish(topic=attrs['root'], message=f'input_{choice}')
761
78f699077ff5 more theater output controls
drewp@bigasterisk.com
parents: 741
diff changeset
67 ignored = False
78f699077ff5 more theater output controls
drewp@bigasterisk.com
parents: 741
diff changeset
68 if stmt[0:2] == (dev, ROOM['volumeChange']):
78f699077ff5 more theater output controls
drewp@bigasterisk.com
parents: 741
diff changeset
69 delta = int(stmt[2].toPython())
78f699077ff5 more theater output controls
drewp@bigasterisk.com
parents: 741
diff changeset
70 which = 'up' if delta > 0 else 'down'
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
71 await self._publish(topic=f'theater_blaster/ir_out/volume_{which}', message=json.dumps({'timed': abs(delta)}))
761
78f699077ff5 more theater output controls
drewp@bigasterisk.com
parents: 741
diff changeset
72 ignored = False
776
8fa420250799 add headboard
drewp@bigasterisk.com
parents: 765
diff changeset
73 if stmt[0:2] == (dev, ROOM['color']):
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
74 msg = self._onColor(stmt[2].toPython(), attrs)
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
75 await self._publish(topic=attrs['root'], message=json.dumps(msg))
777
df7035db28f1 reformat
drewp@bigasterisk.com
parents: 776
diff changeset
76 ignored = False
778
acf58b83022f rdf_to_mqtt sylvania bulbs and code cleanup and k8s updates
drewp@bigasterisk.com
parents: 777
diff changeset
77
392
79d041273e26 mqtt has two devices now. various older cleanups.
drewp@bigasterisk.com
parents: 378
diff changeset
78 if ignored:
79d041273e26 mqtt has two devices now. various older cleanups.
drewp@bigasterisk.com
parents: 378
diff changeset
79 log.warn("ignoring %s", stmt)
696
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
80
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
81 def _onColor(self, h, attrs):
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
82 if isinstance(h, bytes):
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
83 h = h.decode('utf8')
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
84 msg = {}
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
85 if h.endswith('K'): # accept "0.7*2200K" (brightness 0.7)
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
86 # see https://www.zigbee2mqtt.io/information/mqtt_topics_and_message_structure.html#zigbee2mqttfriendly_nameset
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
87 bright, kelvin = map(float, h[:-1].split('*'))
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
88 msg['state'] = 'ON'
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
89 msg["color_temp"] = round(1000000 / kelvin, 2)
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
90 msg['brightness'] = int(bright * 255) # 1..20 look about the same
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
91 else:
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
92 r, g, b = int(h[1:3], 16), int(h[3:5], 16), int(h[5:7], 16)
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
93 msg = {
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
94 'state': 'ON' if r or g or b else 'OFF',
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
95 'color': {
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
96 'r': r,
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
97 'g': g,
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
98 'b': b
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
99 },
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
100 'brightness': max(r, g, b),
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
101 }
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
102
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
103 if attrs.get('hasWhite', False):
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
104 msg['white_value'] = max(r, g, b)
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
105 msg.update(attrs.get('defaults', {}))
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
106 return msg
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
107
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
108 async def _publishOnOff(self, attrs, brightness):
696
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
109 msg = 'OFF'
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
110 if brightness > 0:
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
111 msg = 'ON'
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
112 await self._publish(topic=attrs['root'], message=msg)
696
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
113
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
114 async def _publishRgbw(self, attrs, brightness):
777
df7035db28f1 reformat
drewp@bigasterisk.com
parents: 776
diff changeset
115 for chan, scale in [('w1', 1), ('r', 1), ('g', .8), ('b', .8)]:
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
116 await self._publish(topic=f"{attrs['root']}/light/kit_{chan}/command", messageJson={'state': 'ON', 'brightness': int(brightness * 255)})
696
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
117
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
118 async def _publishFrontScreenText(self, stmt):
696
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
119 ignored = True
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
120 for line in ['line1', 'line2', 'line3', 'line4']:
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
121 if stmt[1] == ROOM[line]:
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
122 ignored = False
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
123 assert mqtt is not None
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
124 await mqtt.publish('frontwindow/%s' % line, stmt[2].toPython())
696
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
125 return ignored
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
126
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
127 @MQTT_PUBLISH.time()
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
128 async def _publish(self, topic: str, messageJson: object = None, message: str | None = None):
765
82bea37aeb92 fix theater input selector string assembling
drewp@bigasterisk.com
parents: 764
diff changeset
129 log.debug(f'mqtt.publish {topic} {message} {messageJson}')
696
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
130 if messageJson is not None:
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
131 message = json.dumps(messageJson)
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
132 assert mqtt is not None
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
133 await mqtt.publish(topic, message)
696
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
134
c52b172c0824 add publish to ON/OFF messages. split up the main statement handler
drewp@bigasterisk.com
parents: 694
diff changeset
135
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
136 def main():
373
2158e7ad19b1 receive oneshot updates from reasoning; emit commands on MQTT to control H801 wifi dimmer
drewp@bigasterisk.com
parents:
diff changeset
137
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
138 async def start2():
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
139 global mqtt
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
140 async with aiomqtt.Client(os.environ.get('MOSQUITTO', "mosquitto-ext"), 1883, client_id="rdf_to_mqtt-%s" % time.time(), keepalive=6) as mqtt:
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
141 log.info(f'connected to mqtt {mqtt}')
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
142 while True:
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
143 await asyncio.sleep(5)
373
2158e7ad19b1 receive oneshot updates from reasoning; emit commands on MQTT to control H801 wifi dimmer
drewp@bigasterisk.com
parents:
diff changeset
144
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
145 def start():
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
146 asyncio.create_task(start2())
373
2158e7ad19b1 receive oneshot updates from reasoning; emit commands on MQTT to control H801 wifi dimmer
drewp@bigasterisk.com
parents:
diff changeset
147
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
148 log.info('make app')
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
149 app = Starlette(debug=True,
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
150 on_startup=[start],
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
151 routes=[
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
152 Route('/', StaticFiles(directory='.', html=True)),
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
153 Route("/output", OutputPage().put, methods=["PUT"]),
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
154 ])
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
155 app.add_middleware(PrometheusMiddleware, app_name='environment')
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
156 app.add_route("/metrics", handle_metrics)
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
157 log.info('return app')
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
158 return app
373
2158e7ad19b1 receive oneshot updates from reasoning; emit commands on MQTT to control H801 wifi dimmer
drewp@bigasterisk.com
parents:
diff changeset
159
1732
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
160
3f4b447d65f5 port to starlette/asyncio
drewp@bigasterisk.com
parents: 1703
diff changeset
161 app = main()