涂煌豪
2022-04-12 715152a0932fe16d743766c141527bc4634087f4
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
({
    getLights: function(component) {
 
        var demoMode = component.get("v.demoMode");
        if (demoMode) {
            component.set("v.waiting", true);
            setTimeout($A.getCallback(function() {
                component.set("v.waiting", false);
                var lights = [];
                lights.push({label: "Living Room", power:"off", brightness: 75});
                lights.push({label: "Kitchen", power:"off", brightness: 75});
                component.set("v.lights", lights);
            }), 1);
        } else {
            var action = component.get("c.getLights");
            action.setCallback(this, function(response) {
                component.set("v.waiting", false);
                var lights = JSON.parse(response.getReturnValue());
                component.set("v.lights", lights);
            });
            component.set("v.waiting", true);
            $A.enqueueAction(action);
        }
 
    },
 
    setPower: function(component, lightId, isOn) {
        var demoMode = component.get("v.demoMode");
        if (!demoMode) {
            var action = component.get("c.setPower");
            action.setParams({
                "lightId": lightId,
                "isOn": isOn
            });
            action.setCallback(this, function() {
            });
            $A.enqueueAction(action);
        }
    },
 
    setBrightness: function(component, lightId, brightness) {
        var demoMode = component.get("v.demoMode");
        if (!demoMode) {
            var action = component.get("c.setBrightness");
            action.setParams({
                "lightId": lightId,
                "brightness": brightness
            });
            action.setCallback(this, function() {
            });
            $A.enqueueAction(action);
        }
    }
 
})