This repository has been archived by the owner on Apr 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathleaf_climate.dart
59 lines (49 loc) · 1.52 KB
/
leaf_climate.dart
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
import 'package:dartnissanconnect/dartnissanconnect.dart';
import 'package:intl/intl.dart';
import 'package:args/args.dart';
import 'dart:io';
ArgResults argResults;
void main(List<String> arguments) {
var parser = ArgParser();
parser.addOption('username');
parser.addOption('password');
parser.addOption('temperature', defaultsTo: '20');
var results = parser.parse(arguments);
NissanConnectSession session = new NissanConnectSession(debug: false);
var temperature = 0;
if (results['temperature'] != 'off') {
temperature = int.parse(results['temperature']);
}
session
.login(username: results['username'], password: results['password'])
.then((vehicle) {
vehicle.requestClimateControlStatusRefresh()
.then((_) {
vehicle.requestClimateControlStatus()
.then((_) {});
});
if (temperature == 0) {
stdout.write('requesting climate off...');
vehicle.requestClimateControlOff()
.then((_) {
stdout.write('success.\n');
}).catchError((error) {
stdout.write('failed.\n');
});
}
else {
stdout.write('requesting climate at ${temperature}°C...');
vehicle.requestClimateControlOn(DateTime.now(), temperature.toInt())
.then((_) {
stdout.write('success.\n');
}).catchError((error) {
stdout.write('failed.\n');
});
}
vehicle.requestClimateControlStatusRefresh()
.then((_) {
vehicle.requestClimateControlStatus()
.then((_) {});
});
});
}