GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (890)

src/plugins/externallights/index.js (5 issues)

1
(function() 
2
{
3
    const Periodic = require( 'Periodic' );
0 ignored issues
show
Backwards Compatibility introduced by
'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
4
    const Listener = require( 'Listener' );
0 ignored issues
show
Backwards Compatibility introduced by
'const' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
5
6
    // Encoding helper functions
7
    function encode( floatIn )
8
    {
9
        return parseInt( floatIn * 1000 );
10
    }
11
12
    function decode( intIn )
13
    {
14
        return ( intIn * 0.001 );
15
    }
16
17
    class ExternalLights
0 ignored issues
show
Backwards Compatibility introduced by
'class' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz).
Loading history...
18
    {
19
        constructor(name, deps)
20
        {
21
            deps.logger.debug( 'ExternalLights plugin loaded' );
22
23
            this.globalBus  = deps.globalEventLoop;
24
            this.cockpitBus = deps.cockpit;
25
26
            this.targetPower          = 0;
27
            this.targetPower_enc      = 0;
28
            this.mcuTargetPower_enc   = 0;
29
30
            var self = this;
31
32
            this.SyncTargetPower = new Periodic( 33, "timeout", function()
33
            {
34
                var synced = true;
35
36
                // Send target power to MCU until it responds with affirmation
37
                if( self.mcuTargetPower_enc !== self.targetPower_enc )
38
                {
39
                    synced = false;
40
41
                    // Encode floating point to integer representation
42
                    var command = 'elights_tpow(' + self.targetPower_enc + ')';
43
44
                    // Emit command to mcu
45
                    self.globalBus.emit( 'mcu.SendCommand', command );
46
                }
47
48
                if( synced )
49
                {
50
                    // No need to continue
51
                    self.SyncTargetPower.stop();
52
                }
53
            });
54
55
            this.listeners = 
56
            {
57
                settings: new Listener( this.globalBus, 'settings-change.external-lights', true, function( settings )
58
                {
59
                    // Apply settings
60
                    self.settings = settings.lights;
61
                    
62
                    // Emit settings update to cockpit
63
                    self.cockpitBus.emit( 'plugin.externalLights.settingsChange', self.settings );
64
65
                    // Enable MCU Status listener
66
                    self.listeners.mcuStatus.enable();
67
68
                    // Enable API
69
                    self.listeners.setTargetPower.enable();
70
                }),
71
72
                mcuStatus: new Listener( this.globalBus, 'mcu.status', false, function( data )
73
                {
74
                    // Current light power
75
                    if( 'elights_pow' in data ) 
76
                    {
77
                        // Convert from integer to float
78
                        var power = decode( parseInt( data.elights_pow ) );
79
80
                        // Emit on cockpit bus for UI purposes
81
                        self.cockpitBus.emit( 'plugin.externalLights.currentPower', power );
82
                    }
83
84
                    // Target light power
85
                    if( 'elights_tpow' in data ) 
86
                    {
87
                        // Save encoded version for sync validation purposes
88
                        self.mcuTargetPower_enc = parseInt( data.elights_tpow );
89
90
                        // Convert from integer to float
91
                        var power = decode( self.mcuTargetPower_enc );
0 ignored issues
show
It seems like power was already defined.
Loading history...
92
93
                        // Emit the real target power on the cockpit bus for UI purposes
94
                        self.cockpitBus.emit( 'plugin.externalLights.targetPower', power );
95
                    }
96
                }),
97
98
                setTargetPower: new Listener( this.cockpitBus, 'plugin.externalLights.setTargetPower', false, function( powerIn )
99
                {
100
                    // Set new target Power
101
                    self.setTargetPower( powerIn );
102
                })
103
            }
0 ignored issues
show
There should be a semicolon.

Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers.

Further Readings:

Loading history...
104
        }
105
106
        setTargetPower( powerIn )
107
        {
108
            var self = this;
109
110
            // Validate input
111
            if( isNaN( powerIn ) )
112
            {
113
              // Ignore
114
              return;
115
            }
116
117
            // Apply limits
118
            if( powerIn > 1.0 )
119
            {
120
                self.targetPower = 1.0;
121
            }
122
            else if( powerIn < 0 )
123
            {
124
                self.targetPower = 0;
125
            }
126
            else
127
            {
128
                self.targetPower = powerIn;
129
            }
130
131
            self.targetPower_enc = encode( self.targetPower );
132
133
            // Start targetPower sync, if not already running
134
            self.SyncTargetPower.start();
135
        }
136
        
137
        start()
138
        {
139
          this.listeners.settings.enable();
140
        }
141
142
        stop()
143
        {
144
          this.listeners.settings.disable();
145
          this.listeners.mcuStatus.disable();
146
          this.listeners.setTargetPower.disable();
147
        }
148
149
        getSettingSchema()
150
        {
151
            //from http://json-schema.org/examples.html
152
            return [{
153
                'title': 'External Lights',
154
                'type': 'object',
155
                'id': 'external-lights',
156
                'managedBy': '_hidden',
157
                'properties': {},
158
                'required': []
159
            }];
160
        }
161
    }
162
163
    module.exports = function(name, deps) 
164
    {
165
        if( process.env.PRODUCTID == "trident" )
166
        {
167
            deps.logger.debug( "External Lights Not supported on trident" );
168
            return {};
169
        }
170
171
        return new ExternalLights(name, deps);
172
    };
173
}());