M frontend/src/views/Home.vue => frontend/src/views/Home.vue +10 -31
@@ 20,14 20,14 @@
</div>
</div>
<div v-if="rokuHost">
- <button @click="apiInfo">info</button>
- <button @click="apiSelect">select</button>
- <button @click="apiUp">up</button>
- <button @click="apiDown">down</button>
- <button @click="apiLeft">left</button>
- <button @click="apiRight">right</button>
- <button @click="apiBack">back</button>
- <button @click="apiHome">home</button>
+ <button @click="apiPress('info')">info</button>
+ <button @click="apiPress('select')">select</button>
+ <button @click="apiPress('up')">up</button>
+ <button @click="apiPress('down')">down</button>
+ <button @click="apiPress('left')">left</button>
+ <button @click="apiPress('right')">right</button>
+ <button @click="apiPress('back')">back</button>
+ <button @click="apiPress('home')">home</button>
</div>
</div>
</template>
@@ 55,29 55,8 @@ export default {
}
},
methods: {
- async apiBack () {
- await axios.get('/api/back')
- },
- async apiDown () {
- await axios.get('/api/down')
- },
- async apiHome () {
- await axios.get('/api/home')
- },
- async apiInfo () {
- await axios.get('/api/info')
- },
- async apiLeft () {
- await axios.get('/api/left')
- },
- async apiRight () {
- await axios.get('/api/right')
- },
- async apiSelect () {
- await axios.get('/api/select')
- },
- async apiUp () {
- await axios.get('/api/up')
+ async apiPress (button) {
+ await axios.get(`/api/press/${button}`)
},
},
name: 'Home',
M sample.py => sample.py +17 -41
@@ 36,47 36,23 @@ def discover():
200
)
-@app.route('/api/info')
-def info():
- current_roku.info()
-
- return 'OK', 200
-
-@app.route('/api/back')
-def back():
- current_roku.back()
- return 'OK', 200
-
-@app.route('/api/home')
-def home():
- current_roku.home()
- return 'OK', 200
-
-@app.route('/api/up')
-def up():
- current_roku.up()
- return 'OK', 200
-
-@app.route('/api/down')
-def down():
- current_roku.down()
- return 'OK', 200
-
-@app.route('/api/left')
-def left():
- current_roku.left()
- return 'OK', 200
-
-@app.route('/api/right')
-def right():
- current_roku.right()
- return 'OK', 200
-
-@app.route('/api/select')
-def select():
- current_roku.select()
-
- return 'OK', 200
+@app.route('/api/press/<button>')
+def press(button):
+ allowed = [
+ "back",
+ "down",
+ "home",
+ "info",
+ "left",
+ "right",
+ "select",
+ "up",
+ ]
+ if button in allowed:
+ getattr(current_roku, button)()
+ return 'OK', 200
+ else:
+ return 'ERROR: invalid button', 400
@app.route('/api/literal', methods=["POST"])
def literal():