-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.js
More file actions
54 lines (44 loc) · 1.32 KB
/
interface.js
File metadata and controls
54 lines (44 loc) · 1.32 KB
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
$(document).ready(function() {
var thermostat = new Thermostat();
updateTemprature();
$('#temprature-up').on('click', function() {
thermostat.up(1);
updateTemprature();
})
$('#temprature-down').click(function() {
thermostat.down(1);
updateTemprature();
})
$('#temprature-reset').click(function() {
thermostat.resetTemprature();
updateTemprature();
})
$('#powersaving-on').click(function() {
thermostat.switchPowerSavingModeOn();
$('#power-saving-status').text('on');
updateTemprature();
})
$('#powersaving-off').click(function() {
thermostat.switchPowerSavingModeOff();
$('#power-saving-status').text('off');
updateTemprature();
})
function updateTemprature() {
$('#temprature').text(thermostat.temprature);
$('#temprature').attr('class', thermostat.energyUsage());
};
function displayWeather(city) {
var url = 'http://api.openweathermap.org/data/2.5/weather?q=' + city;
var token = '&appid=a3d9eb01d4de82b9b8d0849ef604dbed';
var units = '&units=metric';
$.get(url + token + units, function(data) {
$('#current-temperature').text(data.main.temp);
})
}
displayWeather('London');
$('#select-city').submit(function(event) {
event.preventDefault();
var city = $('#current-city').val();
displayWeather(city);
})
});