Skip to content

Commit 50c6cd1

Browse files
authored
Add a Virtual Thermostat device. (#44)
1 parent a055d2d commit 50c6cd1

File tree

3 files changed

+82
-3
lines changed

3 files changed

+82
-3
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,5 @@
140140
}
141141
},
142142
"short_name": "Virtual",
143-
"version": "0.5.1"
143+
"version": "0.6.0"
144144
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "virtual-things-adapter",
33
"display_name": "Virtual Things",
4-
"version": "0.5.1",
4+
"version": "0.6.0",
55
"description": "Mozilla WebThings Gateway Virtual Things Adapter",
66
"main": "index.js",
77
"scripts": {
@@ -30,7 +30,7 @@
3030
},
3131
"devDependencies": {
3232
"babel-eslint": "^10.0.3",
33-
"eslint": "^6.4.0"
33+
"eslint": "^6.5.1"
3434
},
3535
"files": [
3636
"LICENSE",

virtual-things-adapter.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,74 @@ const colorControl = {
804804
events: [],
805805
};
806806

807+
const thermostat = {
808+
'@context': 'https://iot.mozilla.org/schemas',
809+
'@type': ['Thermostat', 'TemperatureSensor'],
810+
name: 'Virtual Thermostat',
811+
properties: [
812+
{
813+
name: 'temperature',
814+
value: 20,
815+
metadata: {
816+
title: 'Temperature',
817+
type: 'number',
818+
'@type': 'TemperatureProperty',
819+
unit: 'degree celsius',
820+
minimum: 0,
821+
maximum: 100,
822+
readOnly: true,
823+
},
824+
},
825+
{
826+
name: 'heatingTargetTemperature',
827+
value: 19,
828+
metadata: {
829+
title: 'Heating Target',
830+
type: 'number',
831+
'@type': 'TargetTemperatureProperty',
832+
unit: 'degree celsius',
833+
minimum: 10,
834+
maximum: 38,
835+
},
836+
},
837+
{
838+
name: 'coolingTargetTemperature',
839+
value: 25,
840+
metadata: {
841+
title: 'Cooling Target',
842+
type: 'number',
843+
'@type': 'TargetTemperatureProperty',
844+
unit: 'degree celsius',
845+
minimum: 10,
846+
maximum: 38,
847+
},
848+
},
849+
{
850+
name: 'heatingCooling',
851+
value: 'heating',
852+
metadata: {
853+
title: 'Heating/Cooling',
854+
type: 'string',
855+
'@type': 'HeatingCoolingProperty',
856+
enum: ['off', 'heating', 'cooling'],
857+
readOnly: true,
858+
},
859+
},
860+
{
861+
name: 'thermostatMode',
862+
value: 'heat',
863+
metadata: {
864+
title: 'Mode',
865+
type: 'string',
866+
'@type': 'ThermostatModeProperty',
867+
enum: ['off', 'heat', 'cool', 'auto'],
868+
},
869+
},
870+
],
871+
actions: [],
872+
events: [],
873+
};
874+
807875
if (ffmpegMajor !== null && ffmpegMajor >= 4) {
808876
videoCamera.properties[0].metadata.links.push({
809877
rel: 'alternate',
@@ -837,6 +905,7 @@ const VIRTUAL_THINGS = [
837905
alarm,
838906
energyMonitor,
839907
colorControl,
908+
thermostat,
840909
];
841910

842911
/**
@@ -905,6 +974,16 @@ class VirtualThingsProperty extends Property {
905974
} else {
906975
this.device.adapter.stopTranscode();
907976
}
977+
} else if (this.name == 'thermostatMode') {
978+
const heatingCooling = this.device.properties.get('heatingCooling');
979+
980+
if (this.value === 'heat') {
981+
heatingCooling.setCachedValueAndNotify('heating');
982+
} else if (this.value === 'cool') {
983+
heatingCooling.setCachedValueAndNotify('cooling');
984+
} else if (this.value === 'off') {
985+
heatingCooling.setCachedValueAndNotify('off');
986+
}
908987
}
909988

910989
resolve(this.value);

0 commit comments

Comments
 (0)