-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMMM-NestRemoteThermostat.js
116 lines (104 loc) · 3.21 KB
/
MMM-NestRemoteThermostat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Magic Mirror Module: MMM-NestRemoteThermostat (https://github.com/sisimomo/MMM-NestRemoteThermostat)
* By Simon Vallières (https://www.linkedin.com/in/simon-vallieres-358555187/)
*
* Base on Magic Mirror Module: MMM-RemoteTemperature (https://github.com/balassy/MMM-RemoteTemperature)
* By György Balássy (https://www.linkedin.com/in/balassy)
*
* Base on codepen.io example: https://codepen.io/dalhundal/pen/KpabZB
* By Dal Hundal (https://codepen.io/dalhundal)
*
* MIT Licensed.
*/
Module.register('MMM-NestRemoteThermostat', {
defaults: {
thermostatId: null,
diameter: undefined,
minValue: undefined,
maxValue: undefined,
numTicks: undefined,
iconSize: undefined,
largeBarThickness: undefined,
roundTargetTemperature: undefined,
roundAmbientTemperature: undefined,
language: config.language,
width: '5em',
height: '5em',
},
requiresVersion: '2.1.0',
getScripts() {
return [
this.file('NestThermostat.js')
];
},
getStyles() {
return [
this.file('NestThermostat.css')
];
},
getTranslations() {
return {
en: 'translations/en.json',
fr: 'translations/fr.json'
};
},
start() {
this.newValues = {};
this.sendSocketNotification('MMM-NestRemoteThermostat.INIT', {
thermostatId: this.config.thermostatId
});
},
getDom() {
if (this.thermostat) {
if (this.newValues.targetTemperature) {
this.thermostat.setTargetTemperature(this.newValues.targetTemperature);
}
if (this.newValues.ambientTemperature) {
this.thermostat.setAmbientTemperature(this.newValues.ambientTemperature);
}
if (this.newValues.state) {
this.thermostat.setState(this.newValues.state);
}
if (this.newValues.power) {
this.thermostat.setPower(this.newValues.power);
}
if (this.newValues.icon) {
this.thermostat.setIcon(this.newValues.icon);
}
this.thermostat.setLoading(this.newValues.loading);
this.newValues = {};
} else {
this.thermostatDiv = document.createElement('div');
this.thermostat = new NestThermostat({
targetElement: this.thermostatDiv,
translateFn: (str) => {
return this.translate(str);
},
options: this.config,
properties: {
fanIcons: [ this.file('/images/fanIconSpeed1.gif'), this.file('/images/fanIconSpeed2.gif'), this.file('/images/fanIconSpeed3.gif'), this.file('/images/fanIconSpeed4.gif'), this.file('/images/fanIconSpeed5.gif') ],
radiatorIcon: this.file('/images/radiator.gif')
}
});
this.thermostatDiv.style.width = this.config.width;
this.thermostatDiv.style.height = this.config.height;
}
return this.thermostatDiv;
},
socketNotificationReceived(notificationName, payload) {
if (notificationName === 'MMM-NestRemoteThermostat.VALUE_RECEIVED' && payload) {
if (!this.config.thermostatId || (this.config.thermostatId && this.config.thermostatId === payload.thermostatId)) {
this.newValues = {
targetTemperature: payload.targetTemperature,
ambientTemperature: payload.ambientTemperature,
state: payload.state,
power: payload.power,
icon: payload.icon,
loading: payload.loading
};
Log.info('MMM-NestRemoteThermostat, thermostatId: "' + this.config.thermostatId + '" just receive new values.', this.newValues);
this.updateDom();
}
}
}
});