Skip to content

Commit 63972b4

Browse files
author
pbochenski
authored
Merge pull request #1 from netguru/develop
release 0.0.2
2 parents 418d4bc + e8785f1 commit 63972b4

23 files changed

+484
-138
lines changed

bitrise.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
format_version: '7'
3+
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
4+
project_type: other
5+
trigger_map:
6+
- push_branch: "master"
7+
workflow: release
8+
workflows:
9+
release:
10+
steps:
11+
- activate-ssh-key@4.0.3:
12+
run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
13+
- git-clone@4.0.14: {}
14+
- cache-pull@2.0.1: {}
15+
- gradle-runner@1.8.5:
16+
inputs:
17+
- apk_file_include_filter: "*smarthome-*.zip"
18+
- gradle_task: distZip
19+
- script@1.1.5:
20+
inputs:
21+
- is_debug: 'no'
22+
- content: |+
23+
#!/usr/bin/env bash
24+
version=`grep "version \'\d*\.\d*\.\d*\'" build.gradle | cut -d" " -f2`
25+
envman add --key CURRENT_VERSION --value $version
26+
- cache-push@2.1.1: {}
27+
- deploy-to-bitrise-io@1.3.19:
28+
inputs:
29+
- notify_user_groups: none
30+
is_always_run: false
31+
app:
32+
envs:
33+
- opts:
34+
is_expand: false
35+
GRADLEW_PATH: "./gradlew"

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ apply plugin: 'application'
1818
apply plugin: 'com.moowork.node'
1919

2020
group 'smarthome'
21-
version '0.0.1'
21+
version '0.0.2'
2222
mainClassName = "io.ktor.server.netty.EngineMain"
2323

2424
sourceSets {
@@ -41,6 +41,7 @@ dependencies {
4141
compile "ch.qos.logback:logback-classic:$logback_version"
4242
compile "io.ktor:ktor-server-core:$ktor_version"
4343
compile "io.ktor:ktor-gson:$ktor_version"
44+
compile "io.ktor:ktor-websockets:$ktor_version"
4445
compile "org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0"
4546
compile 'com.jayway.jsonpath:json-path:2.4.0'
4647
compile 'io.github.microutils:kotlin-logging:1.6.24'

frontend/src/components/SensorEditCard.vue

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,41 @@
8080
></v-select>
8181
</v-flex>
8282

83-
<v-layout row>
84-
<v-flex>
83+
<v-flex v-if="selected.returnType === 'BOOLEAN'">
84+
<v-layout row>
85+
<v-text-field
86+
v-model="selected.boolOn"
87+
label="On state label"
88+
:disabled="selected.action=='REMOVE'"
89+
@input="characteristicChanged()"
90+
/>
91+
<v-text-field
92+
v-model="selected.boolOff"
93+
label="Off state label"
94+
:disabled="selected.action=='REMOVE'"
95+
@input="characteristicChanged()"
96+
/>
97+
</v-layout>
98+
</v-flex>
99+
<v-flex>
85100
<v-checkbox
86101
v-model="selected.writable"
87102
:disabled="selected.action=='REMOVE'"
88-
@change="characteristicChanged()"
103+
@change="writableClicked()"
89104
label="Writable"
90105
></v-checkbox>
91-
</v-flex>
106+
</v-flex>
107+
108+
<v-flex v-if="selected.writable">
109+
<v-text-field
110+
v-model="selected.cmdTopic"
111+
label="Write command topic"
112+
:disabled="selected.action=='REMOVE'"
113+
@input="characteristicChanged()"
114+
/>
115+
</v-flex>
116+
<v-layout row>
117+
92118
<v-flex v-if="selected.icon">
93119
Icon:
94120
<v-img
@@ -168,7 +194,7 @@ export default {
168194
title: String,
169195
deleteButton: Boolean,
170196
sensor: Object,
171-
createNew: Boolean
197+
createNew: Boolean,
172198
},
173199
174200
watch: {
@@ -178,7 +204,7 @@ export default {
178204
if (!this.mSensor.transforms) {
179205
this.$set(this.mSensor, "transforms", []);
180206
}
181-
}
207+
},
182208
},
183209
data() {
184210
return {
@@ -207,7 +233,7 @@ export default {
207233
"switch",
208234
"wallswitch",
209235
"washingmachine",
210-
"window"
236+
"window",
211237
],
212238
213239
intIcons: [
@@ -221,22 +247,22 @@ export default {
221247
"light",
222248
"qualityofservice",
223249
"rollershutter",
224-
"sewerage"
225-
]
250+
"sewerage",
251+
],
226252
};
227253
},
228254
mounted() {
229255
if (!this.mSensor.transforms) {
230256
this.$set(this.mSensor, "transforms", []);
231257
}
232-
for (let transform of this.mSensor.transforms) {
258+
for (const transform of this.mSensor.transforms) {
233259
this.$set(transform, "action", "");
234260
}
235261
},
236262
methods: {
237263
onSelect(transform) {
238264
this.selected = transform;
239-
this.selectedBackup = clonedeep(transform)
265+
this.selectedBackup = clonedeep(transform);
240266
},
241267
saveClicked() {
242268
this.inProgress = true;
@@ -253,11 +279,11 @@ export default {
253279
JSON.stringify(this.mSensor),
254280
{
255281
headers: {
256-
"Content-Type": "application/json"
257-
}
258-
}
282+
"Content-Type": "application/json",
283+
},
284+
},
259285
)
260-
.then(response => {
286+
.then((response) => {
261287
this.inProgress = false;
262288
if (response.status === 201) {
263289
this.$emit("refresh");
@@ -271,17 +297,17 @@ export default {
271297
JSON.stringify(this.mSensor),
272298
{
273299
headers: {
274-
"Content-Type": "application/json"
275-
}
276-
}
300+
"Content-Type": "application/json",
301+
},
302+
},
277303
)
278-
.then(response => {
304+
.then((response) => {
279305
this.inProgress = false;
280306
if (response.status === 200) {
281307
this.$emit("refresh");
282308
}
283309
})
284-
.catch(error => {
310+
.catch((error) => {
285311
this.inProgress = false;
286312
this.error = `${error.response.status} - ${
287313
error.response.statusText
@@ -292,7 +318,7 @@ export default {
292318
this.inProgress = true;
293319
axios
294320
.delete(`${process.env.VUE_APP_URL}/remove_sensor/${this.mSensor.id}`)
295-
.then(response => {
321+
.then((response) => {
296322
this.inProgress = false;
297323
if (response.status === 200) {
298324
this.$emit("refresh");
@@ -305,7 +331,7 @@ export default {
305331
if (this.selected.action === "ADD") {
306332
this.mSensor.transforms.splice(index, 1);
307333
} else {
308-
this.selected.action = "REMOVE";
334+
this.selected.action = "REMOVE";
309335
}
310336
},
311337
cancelUpdateClicked() {
@@ -322,6 +348,12 @@ export default {
322348
this.selected.action = "UPDATE";
323349
}
324350
},
351+
writableClicked(){
352+
if(this.selected.writable === false){
353+
this.selected.cmdTopic = null;
354+
}
355+
this.characteristicChanged();
356+
},
325357
getBooleanIcon(name) {
326358
return `icons/booleanIcons/${name}-true.png`;
327359
},
@@ -342,8 +374,8 @@ export default {
342374
this.selected.icon = icon;
343375
this.chooseIcon = false;
344376
this.characteristicChanged();
345-
}
346-
}
377+
},
378+
},
347379
};
348380
</script>
349381
<style lang="scss" scoped>

frontend/src/components/TransformView.vue

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -58,50 +58,52 @@ export default {
5858
return typeof item !== "undefined";
5959
},
6060
clicked() {
61-
switch (this.transform.returnType) {
62-
case "BOOLEAN": {
63-
console.log("BOOLEAN");
64-
let value = this.transform.event.data;
65-
if (this.notUndef(value)) {
66-
if (value.toLowerCase() === "true") {
67-
value = "false";
61+
if(this.transform.writable){
62+
switch (this.transform.returnType) {
63+
case "BOOLEAN": {
64+
console.log("BOOLEAN");
65+
let value = this.transform.event.data;
66+
if (this.notUndef(value)) {
67+
if (value.toLowerCase() === "true") {
68+
value = "false";
69+
} else {
70+
value = "true";
71+
}
6872
} else {
69-
value = "true";
73+
value = "false";
74+
}
75+
const field = this.transform.transform.split(".").slice(-1)[0];
76+
const event = {
77+
sensorId: this.transform.sensorId,
78+
transformId: this.transform.id,
79+
data: value,
80+
};
81+
axios.put(`${process.env.VUE_APP_URL}/add_event`, JSON.stringify(event),
82+
{
83+
headers: {
84+
"Content-Type": "application/json",
85+
},
86+
})
87+
.then((response) => {
88+
setTimeout(() => {
89+
this.$emit("refresh");
90+
}, 1500);
91+
});
92+
break;
93+
}
94+
case "INT": {
95+
console.log("INT");
96+
this.$emit("showDialog", this.transform);
97+
break;
98+
}
99+
case "FLOAT": {
100+
console.log("FLOAT");
101+
break;
102+
}
103+
case "STRING": {
104+
console.log("STRING");
105+
break;
70106
}
71-
} else {
72-
value = "false";
73-
}
74-
const field = this.transform.transform.split(".").slice(-1)[0];
75-
const event = {
76-
sensorId: this.transform.sensorId,
77-
transformId: this.transform.id,
78-
data: value,
79-
};
80-
axios.put(`${process.env.VUE_APP_URL}/add_event`, JSON.stringify(event),
81-
{
82-
headers: {
83-
"Content-Type": "application/json",
84-
},
85-
})
86-
.then((response) => {
87-
setTimeout(() => {
88-
this.$emit("refresh");
89-
}, 3000);
90-
});
91-
break;
92-
}
93-
case "INT": {
94-
console.log("INT");
95-
this.$emit("showDialog", this.transform);
96-
break;
97-
}
98-
case "FLOAT": {
99-
console.log("FLOAT");
100-
break;
101-
}
102-
case "STRING": {
103-
console.log("STRING");
104-
break;
105107
}
106108
}
107109
},

frontend/src/views/Dashboard.vue

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<TransformView
1414
:transform="transform"
1515
:icon="typeof transform.icon !== 'undefined'"
16-
v-on:refresh="fetchData()"
1716
v-on:showDialog="showDialog($event)"
1817
/>
1918
</v-flex>
@@ -53,14 +52,15 @@ export default {
5352
timer: "",
5453
intDialogShow: false,
5554
dialogTransform: null,
55+
socket: null,
5656
};
5757
},
5858
created() {
59-
this.timer = setInterval(this.fetchData, 1000 * 30);
59+
this.connect();
6060
this.fetchData();
6161
},
6262
destroyed() {
63-
clearInterval(this.timer);
63+
this.disconnect();
6464
},
6565
methods: {
6666
fetchData() {
@@ -89,6 +89,19 @@ export default {
8989
this.error = err.toString();
9090
});
9191
},
92+
connect() {
93+
this.socket = new WebSocket("ws://localhost:8080/ws");
94+
this.socket.onopen = () => {
95+
this.socket.onmessage = ({data}) => {
96+
if(data === "REFRESH"){
97+
this.fetchData()
98+
}
99+
};
100+
};
101+
},
102+
disconnect() {
103+
this.socket.close();
104+
},
92105
showDialog(dialogType) {
93106
this.dialogTransform = dialogType;
94107
this.intDialogShow = true;

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
ktor_version=1.1.1
22
kotlin.code.style=official
3-
kotlin_version=1.3.21
3+
kotlin_version=1.3.31
44
logback_version=1.2.1

0 commit comments

Comments
 (0)