CFenner/MMM-Netatmo

View on GitHub
netatmo.js

Summary

Maintainability
F
1 wk
Test Coverage

Showing 41 of 41 total issues

File netatmo.js has 579 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* MagicMirror²
* Module: MMM-Netatmo
*
* By Christopher Fenner https://github.com/CFenner
* MIT Licensed.
Severity: Major
Found in netatmo.js - About 1 day to fix

    Function getModule has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
    Open

    getModule (module, stationName) {
    const result = {}
     
    result.name = module.module_name
    if (this.config.showStationName) {
    Severity: Minor
    Found in netatmo.js - About 7 hrs to fix

    Function getModule has 119 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    getModule (module, stationName) {
    const result = {}
     
    result.name = module.module_name
    if (this.config.showStationName) {
    Severity: Major
    Found in netatmo.js - About 4 hrs to fix

      `` has 30 functions (exceeds 20 allowed). Consider refactoring.
      Open

      Module.register('netatmo', {
      // default config
      defaults: {
      initialDelay: 0,
      updateInterval: 3, // every 3 minutes, refresh interval on netatmo is 10 minutes
      Severity: Minor
      Found in netatmo.js - About 3 hrs to fix

        Function getDirection has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        getDirection (value) {
        if (value < 11.25) return 'N'
        if (value < 33.75) return 'NNE'
        if (value < 56.25) return 'NE'
        if (value < 78.75) return 'ENE'
        Severity: Minor
        Found in netatmo.js - About 2 hrs to fix

        Function updateModuleList has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

        updateModuleList (stationList) {
        let moduleList = []
         
        for (const station of stationList) {
        moduleList.push(this.getModule(station, station.home_name))
        Severity: Minor
        Found in netatmo.js - About 1 hr to fix

        Function convertToBeaufort has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        convertToBeaufort (value) {
        if (value < 1) return 0
        if (value <= 5) return 1
        if (value <= 11) return 2
        if (value <= 19) return 3
        Severity: Minor
        Found in netatmo.js - About 1 hr to fix

        Function getValue has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        getValue (measurement, value) {
        if (!value) { return value }
        switch (measurement) {
        case this.measurement.CO2:
        return value.toFixed(0)// + '&nbsp;ppm'
        Severity: Minor
        Found in netatmo.js - About 1 hr to fix

          Function getUnit has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          getUnit (measurement) {
          switch (measurement) {
          case this.measurement.CO2:
          return 'ppm'
          case this.measurement.NOISE:
          Severity: Minor
          Found in netatmo.js - About 1 hr to fix

            Function socketNotificationReceived has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

            socketNotificationReceived (notification, payload) {
            Log.debug(`Netatmo: received ${notification}`)
            switch (notification) {
            case this.notifications.AUTH_RESPONSE:
            if (payload.status === 'OK') {
            Severity: Minor
            Found in netatmo.js - About 45 mins to fix

            Avoid too many return statements within this function.
            Open

            if (value <= 61) return 7
            Severity: Major
            Found in netatmo.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

              if (value <= 49) return 6
              Severity: Major
              Found in netatmo.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                if (value < 168.75) return 'SSE'
                Severity: Major
                Found in netatmo.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                  if (value < 303.75) return 'WNW'
                  Severity: Major
                  Found in netatmo.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                    return 'N'
                    Severity: Major
                    Found in netatmo.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                      if (value < 101.25) return 'E'
                      Severity: Major
                      Found in netatmo.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                        if (value < 281.25) return 'W'
                        Severity: Major
                        Found in netatmo.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                          if (value < 326.25) return 'NW'
                          Severity: Major
                          Found in netatmo.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                            if (value <= 88) return 9
                            Severity: Major
                            Found in netatmo.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                              return 12
                              Severity: Major
                              Found in netatmo.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                if (value <= 74) return 8
                                Severity: Major
                                Found in netatmo.js - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                  return 'fa-battery-empty flash red'
                                  Severity: Major
                                  Found in netatmo.js - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                    if (value <= 28) return 4
                                    Severity: Major
                                    Found in netatmo.js - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                      if (value < 123.75) return 'ESE'
                                      Severity: Major
                                      Found in netatmo.js - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                        if (value <= 38) return 5
                                        Severity: Major
                                        Found in netatmo.js - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                          if (value < 191.25) return 'S'
                                          Severity: Major
                                          Found in netatmo.js - About 30 mins to fix

                                            Avoid too many return statements within this function.
                                            Open

                                            if (value < 258.75) return 'WSW'
                                            Severity: Major
                                            Found in netatmo.js - About 30 mins to fix

                                              Avoid too many return statements within this function.
                                              Open

                                              if (value <= 117) return 11
                                              Severity: Major
                                              Found in netatmo.js - About 30 mins to fix

                                                Avoid too many return statements within this function.
                                                Open

                                                if (value < 348.75) return 'NNW'
                                                Severity: Major
                                                Found in netatmo.js - About 30 mins to fix

                                                  Avoid too many return statements within this function.
                                                  Open

                                                  if (value < 213.75) return 'SSW'
                                                  Severity: Major
                                                  Found in netatmo.js - About 30 mins to fix

                                                    Avoid too many return statements within this function.
                                                    Open

                                                    if (value <= 102) return 10
                                                    Severity: Major
                                                    Found in netatmo.js - About 30 mins to fix

                                                      Avoid too many return statements within this function.
                                                      Open

                                                      if (value < 146.25) return 'SE'
                                                      Severity: Major
                                                      Found in netatmo.js - About 30 mins to fix

                                                        Avoid too many return statements within this function.
                                                        Open

                                                        if (value < 236.25) return 'SW'
                                                        Severity: Major
                                                        Found in netatmo.js - About 30 mins to fix

                                                          TODO found
                                                          Open

                                                          // TODO check module.reachable
                                                          Severity: Minor
                                                          Found in netatmo.js by fixme

                                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                                          Open

                                                          if (this.config.design === 'bubbles') {
                                                          primaryType = this.measurement.TEMPERATURE
                                                          primaryValue = module.dashboard_data ? module.dashboard_data[primaryType] : ''
                                                          result.primary = {
                                                          value: this.getValue(primaryType, primaryValue),
                                                          Severity: Major
                                                          Found in netatmo.js and 1 other location - About 5 hrs to fix
                                                          netatmo.js on lines 226..236

                                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                                          Open

                                                          if (this.config.design === 'bubbles') {
                                                          primaryType = this.measurement.RAIN
                                                          primaryValue = module.dashboard_data ? module.dashboard_data[primaryType] : ''
                                                          result.primary = {
                                                          value: this.getValue(primaryType, primaryValue),
                                                          Severity: Major
                                                          Found in netatmo.js and 1 other location - About 5 hrs to fix
                                                          netatmo.js on lines 186..196

                                                          Similar blocks of code found in 3 locations. Consider refactoring.
                                                          Open

                                                          if (this.config.unitOfMeasurementWind === '') {
                                                          this.config.unitOfMeasurementWind = this.convertNetatmoWindUnit(userPreferences.windunit)
                                                          console.log('Using user-preferred unit of measurement for wind values %o', this.config.unitOfMeasurementWind)
                                                          }
                                                          Severity: Major
                                                          Found in netatmo.js and 2 other locations - About 1 hr to fix
                                                          netatmo.js on lines 87..90
                                                          netatmo.js on lines 91..94

                                                          Similar blocks of code found in 3 locations. Consider refactoring.
                                                          Open

                                                          if (this.config.unitOfMeasurement === '') {
                                                          this.config.unitOfMeasurement = this.convertNetatmoUnit(userPreferences.unit)
                                                          console.log('Using user-preferred unit of measurement for temp/rain values %o', this.config.unitOfMeasurement)
                                                          }
                                                          Severity: Major
                                                          Found in netatmo.js and 2 other locations - About 1 hr to fix
                                                          netatmo.js on lines 91..94
                                                          netatmo.js on lines 95..98

                                                          Similar blocks of code found in 3 locations. Consider refactoring.
                                                          Open

                                                          if (this.config.unitOfMeasurementPressure === '') {
                                                          this.config.unitOfMeasurementPressure = this.convertNetatmoPressureUnit(userPreferences.pressureunit)
                                                          console.log('Using user-preferred unit of measurement for pressure values %o', this.config.unitOfMeasurementPressure)
                                                          }
                                                          Severity: Major
                                                          Found in netatmo.js and 2 other locations - About 1 hr to fix
                                                          netatmo.js on lines 87..90
                                                          netatmo.js on lines 95..98

                                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                                          Open

                                                          if (this.config.showTrend) { result.measurementList.push(this.getMeasurement(module, this.measurement.PRESSURE_TREND)) }
                                                          Severity: Minor
                                                          Found in netatmo.js and 1 other location - About 35 mins to fix
                                                          netatmo.js on lines 197..197

                                                          Similar blocks of code found in 2 locations. Consider refactoring.
                                                          Open

                                                          if (this.config.showTrend) { result.measurementList.push(this.getMeasurement(module, this.measurement.TEMPERATURE_TREND)) }
                                                          Severity: Minor
                                                          Found in netatmo.js and 1 other location - About 35 mins to fix
                                                          netatmo.js on lines 168..168
                                                          Category
                                                          Status