Skip to content

Commit

Permalink
Added alarm
Browse files Browse the repository at this point in the history
Fixed pump relay toggle
  • Loading branch information
cecchisandrone committed Dec 28, 2017
1 parent f58ea8b commit 36f299d
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 16 deletions.
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) [2017] [Alessandro Dionisi]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,13 @@
<input type='checkbox' v-model="selectedCamera.Enabled"/>
Enabled
</label>
</div>
</div>
<div>
<label>
<input type='checkbox' v-model="selectedCamera.AlarmEnabled"/>
Alarm Enabled
</label>
</div>
</div>
<div slot="footer">
<button class="btn btn-info" v-on:click="createOrUpdateCamera()">
Expand Down Expand Up @@ -149,7 +155,7 @@
}
return {
title: 'Cameras',
columns: ['ID', 'Name', 'Type', 'Host', 'Port', 'Enabled'],
columns: ['ID', 'Name', 'Type', 'Host', 'Port', 'Enabled', 'AlarmEnabled'],
data: cameras
}
}
Expand Down
15 changes: 10 additions & 5 deletions smarthome-ui/src/components/Dashboard/Views/Overview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@

<!--Stats cards-->
<div class="row">
<div class="col-lg-3 col-sm-6">
<div class="col-lg-2 col-sm-6">
<gate></gate>
</div>
<div class="col-lg-3 col-sm-6">
<div class="col-lg-2 col-sm-6">
<alarm></alarm>
</div>
<div class="col-lg-2 col-sm-6">
<temperature></temperature>
</div>
<div class="col-lg-3 col-sm-6">
<div class="col-lg-2 col-sm-6">
<pump></pump>
</div>
<div class="col-lg-3 col-sm-6">
<div class="col-lg-2 col-sm-6">
<raspsonar></raspsonar>
</div>
</div>
Expand All @@ -37,6 +40,7 @@
import TemperatureChart from 'components/Dashboard/Views/Overview/TemperatureChart.vue'
import RaspsonarChart from 'components/Dashboard/Views/Overview/RaspsonarChart.vue'
import Raspsonar from 'components/Dashboard/Views/Overview/Raspsonar.vue'
import Alarm from 'components/Dashboard/Views/Overview/Alarm.vue'
import ChartCard from 'components/UIComponents/Cards/ChartCard.vue'
export default {
components: {
Expand All @@ -46,7 +50,8 @@
TemperatureChart,
Raspsonar,
RaspsonarChart,
ChartCard
ChartCard,
Alarm
}
}
</script>
Expand Down
68 changes: 68 additions & 0 deletions smarthome-ui/src/components/Dashboard/Views/Overview/Alarm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<template>
<stats-card>
<div class="icon-big icon-success" slot="header">
Alarm
</div>
<div class="numbers" slot="content">
<button class="btn btn-default btn-md" v-bind:class="{ active: isActive }" v-on:click="toggleAlarm">
{{ status }}
</button>
</div>
<div class="stats" slot="footer">
<i v-if="messages" class="ti-info"></i> {{messages}}
</div>
</stats-card>
</template>
<script>
import StatsCard from 'components/UIComponents/Cards/StatsCard.vue'
import * as alarmService from 'src/services/alarmService.js'
export default {
components: {
StatsCard
},
data () {
return {
messages: '',
isActive: false
}
},
computed: {
status: function () {
return this.isActive ? 'On' : 'Off'
}
},
methods: {
toggleAlarm: function () {
var that = this
alarmService.toggleAlarm(!this.isActive).then((data) => {
that.isActive = !that.isActive
that.messages = that.getMessage(that.isActive, data.cameras)
})
.catch((err) => {
that.messages = err.message
})
},
getMessage: function (enabled, cameras) {
var message = ''
if (enabled && cameras.length) {
message = 'Enabled on ' + cameras
}
if (enabled && !cameras.length) {
message = 'Enabled but no camera enabled'
}
return message
}
},
created () {
var that = this
alarmService.getAlarmStatus().then((data) => {
that.isActive = data.alarmEnabled
that.messages = that.getMessage(data.alarmEnabled, data.cameras)
})
.catch((err) => {
that.messages = err.message
that.isActive = false
})
}
}
</script>
21 changes: 18 additions & 3 deletions smarthome-ui/src/components/Dashboard/Views/Overview/Pump.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
methods: {
togglePump: function () {
var that = this
raspsonarService.togglePump(that.isActive).then((data) => {
that.isActive = !that.isActive
raspsonarService.toggleRelay(!that.isActive).then((data) => {
that.isActive = data.relayStatus
if (that.isActive) {
that.messages = 'Pump activated at ' + new Date().toLocaleTimeString()
that.messages = 'Pump activated at ' + new Date(data.activationTime).toLocaleTimeString()
} else {
that.messages = ''
}
Expand All @@ -47,6 +47,21 @@
that.isActive = false
})
}
},
created () {
var that = this
raspsonarService.getRelayStatus().then((data) => {
that.isActive = data.relayStatus
if (that.isActive) {
that.messages = 'Pump activated at ' + new Date(data.activationTime).toLocaleTimeString()
} else {
that.messages = ''
}
})
.catch((err) => {
that.messages = err.message
that.isActive = false
})
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
var that = this
raspsonarService.getLastMeasurement().then((data) => {
that.raspsonar.value = data.value.toFixed(2) + ' cm'
that.raspsonar.footerText = 'Updated at ' + new Date(data.timestamp).toLocaleString()
that.raspsonar.footerText = new Date(data.timestamp).toLocaleString()
})
.catch((err) => {
that.raspsonar.footerText = err.message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
var that = this
temperatureService.getLastMeasurement().then((data) => {
that.temperature.value = data.value.toFixed(2) + ' °C'
that.temperature.footerText = 'Updated at ' + new Date(data.timestamp).toLocaleString()
that.temperature.footerText = new Date(data.timestamp).toLocaleString()
})
.catch((err) => {
that.temperature.footerText = err.message
Expand Down
32 changes: 32 additions & 0 deletions smarthome-ui/src/services/alarmService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import axios from 'axios'
import * as authService from './authService.js'

function toggleAlarm (status) {
var user = authService.getCurrentUser()
var configurationId = user.configurationId
return new Promise(function (resolve, reject) {
axios.put(process.env.API_ENDPOINT + '/configurations/' + configurationId + '/alarm/', null, {params: {status: status ? 1 : 0}, headers: { Authorization: `Bearer ${user.token}` }})
.then(function (res) {
resolve(res.data)
})
.catch(function (err) {
reject(err)
})
})
}

function getAlarmStatus () {
var user = authService.getCurrentUser()
var configurationId = user.configurationId
return new Promise(function (resolve, reject) {
axios.get(process.env.API_ENDPOINT + '/configurations/' + configurationId + '/alarm/', {headers: { Authorization: `Bearer ${user.token}` }})
.then(function (res) {
resolve(res.data)
})
.catch(function (err) {
reject(err)
})
})
}

export {toggleAlarm, getAlarmStatus}
20 changes: 17 additions & 3 deletions smarthome-ui/src/services/raspsonarService.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ function getScheduledMeasurements () {
})
}

function togglePump (status) {
function toggleRelay (status) {
var user = authService.getCurrentUser()
var configurationId = user.configurationId
return new Promise(function (resolve, reject) {
axios.post(process.env.API_ENDPOINT + '/configurations/' + configurationId + '/raspsonar/', null, {params: {relayStatus: status ? 1 : 0}, headers: { Authorization: `Bearer ${user.token}` }})
axios.put(process.env.API_ENDPOINT + '/configurations/' + configurationId + '/raspsonar/relay', null, {params: {relayStatus: status ? 1 : 0}, headers: { Authorization: `Bearer ${user.token}` }})
.then(function (res) {
resolve(res.data)
})
Expand All @@ -43,4 +43,18 @@ function togglePump (status) {
})
}

export {getLastMeasurement, getScheduledMeasurements, togglePump}
function getRelayStatus () {
var user = authService.getCurrentUser()
var configurationId = user.configurationId
return new Promise(function (resolve, reject) {
axios.get(process.env.API_ENDPOINT + '/configurations/' + configurationId + '/raspsonar/relay', {headers: { Authorization: `Bearer ${user.token}` }})
.then(function (res) {
resolve(res.data)
})
.catch(function (err) {
reject(err)
})
})
}

export {getLastMeasurement, getScheduledMeasurements, toggleRelay, getRelayStatus}

0 comments on commit 36f299d

Please sign in to comment.