@@ -23,6 +23,14 @@ Module.register('MMM-AirQuality', {
2323 DATA : 'AIR_QUALITY_DATA' ,
2424 DATA_RESPONSE : 'AIR_QUALITY_DATA_RESPONSE' ,
2525 } ,
26+ colors : {
27+ GOOD : '#009966' ,
28+ MODERATE : '#ffde33' ,
29+ UNHEALTHY_FOR_SENSITIVE_GROUPS : '#ff9933' ,
30+ UNHEALTHY : '#cc0033' ,
31+ HAZARDOUS : '#7e0023' ,
32+ UNKNOWN : '#333333' ,
33+ } ,
2634 start : function ( ) {
2735 const self = this
2836 Log . info ( `Starting module: ${ this . name } ` )
@@ -42,23 +50,19 @@ Module.register('MMM-AirQuality', {
4250 this . data . value = data . aqi
4351 this . data . city = data . city . name
4452 this . loaded = true
45-
46- if ( data . aqi < 51 ) {
47- this . data . color = '#009966'
48- this . data . impact = 'Good'
49- } else if ( data . aqi < 101 ) {
50- this . data . color = '#ffde33'
51- this . data . impact = 'Moderate'
52- } else if ( data . aqi < 151 ) {
53- this . data . color = '#ff9933'
54- this . data . impact = 'Unhealty for Sensitive Groups'
55- } else if ( data . aqi < 201 ) {
56- this . data . color = '#cc0033'
57- this . data . impact = 'Unhealthy'
58- } else if ( data . aqi < 301 ) {
59- this . data . color = '#7e0023'
60- this . data . impact = 'Hazardous'
61- }
53+ this . data . impact = this . getImpact ( data . aqi )
54+ this . data . color = this . getColor ( this . data . impact )
55+ } ,
56+ getImpact : function ( aqi ) {
57+ if ( aqi < 51 ) return 'GOOD'
58+ if ( aqi < 101 ) return 'MODERATE'
59+ if ( aqi < 151 ) return 'UNHEALTHY_FOR_SENSITIVE_GROUPS'
60+ if ( aqi < 201 ) return 'UNHEALTHY'
61+ if ( aqi < 301 ) return 'HAZARDOUS'
62+ return 'UNKNOWN'
63+ } ,
64+ getColor : function ( impact ) {
65+ return this . colors [ impact ]
6266 } ,
6367 html : {
6468 icon : '<i class="fa-solid fa-smog"></i>' ,
@@ -77,8 +81,15 @@ Module.register('MMM-AirQuality', {
7781 // Override getHeader method.
7882 getHeader : function ( ) {
7983 let header = ''
80- if ( this . data . header ) { header += this . data . header }
81- if ( this . config . appendLocationNameToHeader ) {
84+ if ( this . data . header !== '' ) {
85+ if ( this . data . header === undefined ) {
86+ header += this . translate ( 'HEADER' )
87+ } else {
88+ header += this . data . header
89+ }
90+ }
91+
92+ if ( this . loaded && this . config . appendLocationNameToHeader ) {
8293 if ( header !== '' ) {
8394 header += ' '
8495 }
@@ -101,19 +112,25 @@ Module.register('MMM-AirQuality', {
101112 }
102113
103114 if ( ! this . loaded ) {
104- wrapper . innerHTML = 'Loading air quality index ...'
115+ wrapper . innerHTML = this . translate ( 'LOADING' )
105116 wrapper . className = 'dimmed light small'
106117 return wrapper
107118 }
108119 wrapper . innerHTML =
109120 this . html . quality . format (
110121 this . data . color ,
111122 this . html . icon ,
112- this . data . impact ,
123+ this . translate ( this . data . impact ) ,
113124 ( this . config . showIndex ? ' (' + this . data . value + ')' : '' ) ) +
114125 ( this . config . showLocation && ! this . config . appendLocationNameToHeader ? this . html . city . format ( this . data . city ) : '' )
115126 return wrapper
116127 } ,
128+ getTranslations : function ( ) {
129+ return {
130+ en : 'l10n/en.json' , // fallback language
131+ de : 'l10n/de.json' ,
132+ }
133+ } ,
117134 socketNotificationReceived : function ( notification , payload ) {
118135 const self = this
119136 Log . debug ( 'received ' + notification )
0 commit comments