-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.js
50 lines (44 loc) · 1.36 KB
/
interface.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
$(document).ready(function() {
var thermostat = new Thermostat();
$('#temperature').text(thermostat.temperature);
$('#temperature').css('color', 'orange');
$('#psm').text(thermostat.psm());
$.get('http://api.openweathermap.org/data/2.5/weather?q=London&appid=a3d9eb01d4de82b9b8d0849ef604dbed&units=metric', function(data) {
$('#current-temperature').text(data.main.temp);
})
function update(){
$('#temperature').text(thermostat.temperature)
$('#psm').text(thermostat.psm());
if(thermostat.energyusage() === 'Low-usage') {
$('#temperature').css('color', 'green')
}
else if(thermostat.energyusage() === 'Medium-usage') {
$('#temperature').css('color', 'orange')
}
else {
$('#temperature').css('color', 'red')
}
};
$('#current-city').change(function() {
var city = $('#current-city').val();
$.get('http://api.openweathermap.org/data/2.5/weather?q=' + city + '&appid=a3d9eb01d4de82b9b8d0849ef604dbed&units=metric', function(data) {
$('#current-temperature').text(data.main.temp)
})
})
$('#up').click(function() {
thermostat.up();
update();
});
$('#down').click(function() {
thermostat.down();
update();
});
$('#reset').click(function() {
thermostat.reset();
update();
});
$('#switchmode').click(function() {
thermostat.switchmode();
update();
});
});