WIP for lightings...

This commit is contained in:
2017-08-03 23:09:23 +02:00
parent 85855a4dca
commit 01d7c53e3e
4 changed files with 97 additions and 0 deletions

View File

@@ -2,6 +2,35 @@
<h1> Lights </h1>
</template>
<script>
import { Cell, Group, GroupTitle } from 'vux'
import Lights from '../models/lights'
export default {
components: {
Cell,
Group,
GroupTitle
},
data () {
return {
lights: []
}
},
methods: {
fetchData () {
var vm = this
Lights.get({onSuccess: function (data) {
vm.lights = data.Lights
console.log(vm.lights)
}})
}
},
mounted () {
// console.log('mounted')
this.fetchData()
}
}
</script>
<style>
</style>

View File

@@ -0,0 +1,51 @@
import axios from 'axios'
/*
* Make the Request and call onSuccess method on the call back object.
*/
export default {
request (route, data = 0, callback) {
axios({
method: route.method,
url: this.server + route.url,
data: data,
timeout: this.timeout
}).then(function (response) {
// console.log('response...')
if (callback && callback.onSuccess) {
callback.onSuccess(response.data)
}
})
},
// server: '',
server: 'http://192.168.1.6:8081',
timeout: 1000,
route: {
/*
* The route tree for the Domo APIs.
*/
lights: {
get: {
url: '/v1/capabilities/lights',
method: 'get'
},
set: {
url: '/v1/capabilities/lights',
method: 'post'
}
},
sprinklers: {
get: {
url: '/v1/capabilities/sprinklers',
method: 'get'
},
set: {
url: '/v1/capabilities/sprinklers',
method: 'post'
}
}
}
}

View File

@@ -0,0 +1,2 @@
import Vue from 'vue'
export const EventBus = new Vue()

View File

@@ -0,0 +1,15 @@
import api from './api'
export default {
// get cpu info
lights: {
get (callback) {
api.request(api.route.lights.get, callback)
},
set (light, callback) {
var msg = '{"id": ' + light.id + ', "state": ' + light.state + '}'
api.request(api.route.lights.set, msg, callback)
}
}
}