1- const storage = require ( ' Storage' ) ;
2- const B2 = process . env . HWVERSION === 2 ;
1+ const storage = require ( " Storage" ) ;
2+ const B2 = process . env . HWVERSION === 2 ;
33
44let expiryTimeout ;
55function scheduleExpiry ( json ) {
66 if ( expiryTimeout ) {
77 clearTimeout ( expiryTimeout ) ;
88 expiryTimeout = undefined ;
99 }
10- let expiry = "expiry" in json ? json . expiry : 2 * 3600000 ;
10+ let expiry = "expiry" in json ? json . expiry : 2 * 3600000 ;
1111 if ( json . weather && json . weather . time && expiry ) {
1212 let t = json . weather . time + expiry - Date . now ( ) ;
1313 expiryTimeout = setTimeout ( update , t ) ;
1414 }
1515}
1616
1717function update ( weatherEvent ) {
18- let json = storage . readJSON ( ' weather.json' ) || { } ;
18+ let json = storage . readJSON ( " weather.json" ) || { } ;
1919
2020 if ( weatherEvent ) {
2121 let weather = weatherEvent . clone ( ) ;
@@ -24,103 +24,101 @@ function update(weatherEvent) {
2424 if ( weather . wdir != null ) {
2525 // Convert numeric direction into human-readable label
2626 let deg = weather . wdir ;
27- while ( deg < 0 || deg > 360 ) {
28- deg = ( deg + 360 ) % 360 ;
27+ while ( deg < 0 || deg > 360 ) {
28+ deg = ( deg + 360 ) % 360 ;
2929 }
30- weather . wrose = [ 'n' , 'ne' , 'e' , 'se' , 's' , 'sw' , 'w' , 'nw' , 'n' ] [ Math . floor ( ( deg + 22.5 ) / 45 ) ] ;
30+ weather . wrose = [ "n" , "ne" , "e" , "se" , "s" , "sw" , "w" , "nw" , "n" ] [ Math . floor ( ( deg + 22.5 ) / 45 ) ] ;
3131 }
3232
3333 json . weather = weather ;
34- }
35- else {
34+ } else {
3635 delete json . weather ;
3736 }
3837
39-
40- storage . write ( 'weather.json' , json ) ;
38+ storage . write ( "weather.json" , json ) ;
4139 scheduleExpiry ( json ) ;
4240 exports . emit ( "update" , json . weather ) ;
4341}
4442exports . update = update ;
4543const _GB = global . GB ;
4644global . GB = ( event ) => {
47- if ( event . t === "weather" ) update ( event ) ;
45+ if ( event . t === "weather" ) update ( event ) ;
4846 if ( _GB ) setTimeout ( _GB , 0 , event ) ;
4947} ;
5048
51- exports . get = function ( ) {
52- return ( storage . readJSON ( ' weather.json' ) || { } ) . weather ;
53- }
49+ exports . get = ( ) => {
50+ return ( storage . readJSON ( " weather.json" ) || { } ) . weather ;
51+ } ;
5452
55- scheduleExpiry ( storage . readJSON ( ' weather.json' ) || { } ) ;
53+ scheduleExpiry ( storage . readJSON ( " weather.json" ) || { } ) ;
5654
5755function getPalette ( monochrome , ovr ) {
5856 var palette ;
59- if ( monochrome ) {
57+ if ( monochrome ) {
6058 palette = {
61- sun : ' #FFF' ,
62- cloud : ' #FFF' ,
63- bgCloud : ' #FFF' ,
64- rain : ' #FFF' ,
65- lightning : ' #FFF' ,
66- snow : ' #FFF' ,
67- mist : ' #FFF' ,
68- background : ' #000'
59+ sun : " #FFF" ,
60+ cloud : " #FFF" ,
61+ bgCloud : " #FFF" ,
62+ rain : " #FFF" ,
63+ lightning : " #FFF" ,
64+ snow : " #FFF" ,
65+ mist : " #FFF" ,
66+ background : " #000" ,
6967 } ;
7068 } else {
7169 if ( B2 ) {
7270 if ( ovr . theme . dark ) {
7371 palette = {
74- sun : ' #FF0' ,
75- cloud : ' #FFF' ,
76- bgCloud : ' #777' , // dithers on B2, but that's ok
77- rain : ' #0FF' ,
78- lightning : ' #FF0' ,
79- snow : ' #FFF' ,
80- mist : ' #FFF'
72+ sun : " #FF0" ,
73+ cloud : " #FFF" ,
74+ bgCloud : " #777" , // dithers on B2, but that's ok
75+ rain : " #0FF" ,
76+ lightning : " #FF0" ,
77+ snow : " #FFF" ,
78+ mist : " #FFF" ,
8179 } ;
8280 } else {
8381 palette = {
84- sun : ' #FF0' ,
85- cloud : ' #777' , // dithers on B2, but that's ok
86- bgCloud : ' #000' ,
87- rain : ' #00F' ,
88- lightning : ' #FF0' ,
89- snow : ' #0FF' ,
90- mist : ' #0FF'
82+ sun : " #FF0" ,
83+ cloud : " #777" , // dithers on B2, but that's ok
84+ bgCloud : " #000" ,
85+ rain : " #00F" ,
86+ lightning : " #FF0" ,
87+ snow : " #0FF" ,
88+ mist : " #0FF" ,
9189 } ;
9290 }
9391 } else {
9492 if ( ovr . theme . dark ) {
9593 palette = {
96- sun : ' #FE0' ,
97- cloud : ' #BBB' ,
98- bgCloud : ' #777' ,
99- rain : ' #0CF' ,
100- lightning : ' #FE0' ,
101- snow : ' #FFF' ,
102- mist : ' #FFF'
94+ sun : " #FE0" ,
95+ cloud : " #BBB" ,
96+ bgCloud : " #777" ,
97+ rain : " #0CF" ,
98+ lightning : " #FE0" ,
99+ snow : " #FFF" ,
100+ mist : " #FFF" ,
103101 } ;
104102 } else {
105103 palette = {
106- sun : ' #FC0' ,
107- cloud : ' #000' ,
108- bgCloud : ' #777' ,
109- rain : ' #07F' ,
110- lightning : ' #FC0' ,
111- snow : ' #CCC' ,
112- mist : ' #CCC'
104+ sun : " #FC0" ,
105+ cloud : " #000" ,
106+ bgCloud : " #777" ,
107+ rain : " #07F" ,
108+ lightning : " #FC0" ,
109+ snow : " #CCC" ,
110+ mist : " #CCC" ,
113111 } ;
114112 }
115113 }
116114 }
117115 return palette ;
118116}
119117
120- exports . getColor = function ( code ) {
118+ exports . getColor = ( code ) => {
121119 const codeGroup = Math . round ( code / 100 ) ;
122120 const palette = getPalette ( 0 , g ) ;
123- const cloud = g . blendColor ( palette . cloud , palette . bgCloud , .5 ) ; //theme independent
121+ const cloud = g . blendColor ( palette . cloud , palette . bgCloud , 0 .5) ; //theme independent
124122 switch ( codeGroup ) {
125123 case 2 : return g . blendColor ( cloud , palette . lightning , .5 ) ;
126124 case 3 : return palette . rain ;
@@ -144,7 +142,7 @@ exports.getColor = function(code) {
144142 }
145143 default : return cloud ;
146144 }
147- }
145+ } ;
148146
149147/**
150148 *
@@ -158,9 +156,9 @@ exports.getColor = function(code) {
158156 * @param ovr Graphics instance (or undefined for g)
159157 * @param monochrome If true, produce a monochromatic icon
160158 */
161- exports . drawIcon = function ( cond , x , y , r , ovr , monochrome ) {
159+ exports . drawIcon = ( cond , x , y , r , ovr , monochrome ) => {
162160 var palette ;
163- if ( ! ovr ) ovr = g ;
161+ if ( ! ovr ) ovr = g ;
164162
165163 palette = getPalette ( monochrome , ovr ) ;
166164
@@ -257,7 +255,7 @@ exports.drawIcon = function(cond, x, y, r, ovr, monochrome) {
257255
258256 function drawSnow ( x , y , r ) {
259257 function rotatePoints ( points , pivotX , pivotY , angle ) {
260- for ( let i = 0 ; i < points . length ; i += 2 ) {
258+ for ( let i = 0 ; i < points . length ; i += 2 ) {
261259 const x = points [ i ] ;
262260 const y = points [ i + 1 ] ;
263261 points [ i ] = Math . cos ( angle ) * ( x - pivotX ) - Math . sin ( angle ) * ( y - pivotY ) +
@@ -269,7 +267,7 @@ exports.drawIcon = function(cond, x, y, r, ovr, monochrome) {
269267
270268 ovr . setColor ( palette . snow ) ;
271269 const w = 1 / 12 * r ;
272- for ( let i = 0 ; i <= 6 ; ++ i ) {
270+ for ( let i = 0 ; i <= 6 ; ++ i ) {
273271 const points = [
274272 x + w , y ,
275273 x - w , y ,
@@ -279,7 +277,7 @@ exports.drawIcon = function(cond, x, y, r, ovr, monochrome) {
279277 rotatePoints ( points , x , y , i / 3 * Math . PI ) ;
280278 ovr . fillPoly ( points ) ;
281279
282- for ( let j = - 1 ; j <= 1 ; j += 2 ) {
280+ for ( let j = - 1 ; j <= 1 ; j += 2 ) {
283281 const points = [
284282 x + w , y + 7 / 12 * r ,
285283 x - w , y + 7 / 12 * r ,
@@ -317,8 +315,8 @@ exports.drawIcon = function(cond, x, y, r, ovr, monochrome) {
317315 }
318316
319317 /*
320- * Choose weather icon to display based on weather description
321- */
318+ * Choose weather icon to display based on weather description
319+ */
322320 function chooseIconByTxt ( txt ) {
323321 if ( ! txt ) return ( ) => { } ;
324322 txt = txt . toLowerCase ( ) ;
@@ -336,24 +334,26 @@ exports.drawIcon = function(cond, x, y, r, ovr, monochrome) {
336334 if ( txt . includes ( "few clouds" ) ) return drawFewClouds ;
337335 if ( txt . includes ( "scattered clouds" ) ) return drawCloud ;
338336 if ( txt . includes ( "clouds" ) ) return drawBrokenClouds ;
339- if ( txt . includes ( "mist" ) ||
337+ if (
338+ txt . includes ( "mist" ) ||
340339 txt . includes ( "smoke" ) ||
341340 txt . includes ( "haze" ) ||
342341 txt . includes ( "sand" ) ||
343342 txt . includes ( "dust" ) ||
344343 txt . includes ( "fog" ) ||
345344 txt . includes ( "ash" ) ||
346345 txt . includes ( "squalls" ) ||
347- txt . includes ( "tornado" ) ) {
346+ txt . includes ( "tornado" )
347+ ) {
348348 return drawMist ;
349349 }
350350 return drawUnknown ;
351351 }
352352
353353 /*
354- * Choose weather icon to display based on weather conditition code
355- * https://openweathermap.org/weather-conditions#Weather-Condition-Codes-2
356- */
354+ * Choose weather icon to display based on weather condition code
355+ * https://openweathermap.org/weather-conditions#Weather-Condition-Codes-2
356+ */
357357 function chooseIconByCode ( code ) {
358358 const codeGroup = Math . round ( code / 100 ) ;
359359 switch ( codeGroup ) {
@@ -382,16 +382,15 @@ exports.drawIcon = function(cond, x, y, r, ovr, monochrome) {
382382 }
383383
384384 function chooseIcon ( cond ) {
385- if ( typeof ( cond ) === "object" ) {
385+ if ( typeof cond === "object" ) {
386386 if ( "code" in cond ) return chooseIconByCode ( cond . code ) ;
387387 if ( "txt" in cond ) return chooseIconByTxt ( cond . txt ) ;
388- } else if ( typeof ( cond ) === "number" ) {
388+ } else if ( typeof cond === "number" ) {
389389 return chooseIconByCode ( cond . code ) ;
390- } else if ( typeof ( cond ) === "string" ) {
390+ } else if ( typeof cond === "string" ) {
391391 return chooseIconByTxt ( cond . txt ) ;
392392 }
393393 return drawUnknown ;
394394 }
395395 chooseIcon ( cond ) ( x , y , r ) ;
396-
397396} ;
0 commit comments