-
Notifications
You must be signed in to change notification settings - Fork 2
/
garage_server.dart
40 lines (37 loc) · 1 KB
/
garage_server.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
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:garage_door_controller/garage.dart';
void remoteEventHandler(GarageDoorTrigger t) {
switch (t.type) {
case GarageDoorTriggerType.Open:
GarageDoor.openDoor();
break;
case GarageDoorTriggerType.Close:
GarageDoor.closeDoor();
break;
case GarageDoorTriggerType.Trigger:
GarageDoor.triggerDoor();
break;
case GarageDoorTriggerType.IsOpenQuery:
t.response(GarageDoor.isOpen);
break;
case GarageDoorTriggerType.CloseIn:
assert(t.delay != null);
GarageDoor.closeDoorIn(t.delay);
break;
case GarageDoorTriggerType.OpenFor:
assert(t.delay != null);
GarageDoor.openDoorFor(t.delay);
break;
default:
throw UnimplementedError();
}
t.complete();
}
main() async {
GarageDoor.initialize();
await GarageDoorRemoteHandler.startListening();
GarageDoorRemoteHandler.listen(remoteEventHandler);
print('Garage door server running...');
}