GladysProject/Gladys

View on GitHub
server/services/netatmo/lib/update/netatmo.updateNAMain.js

Summary

Maintainability
F
6 days
Test Coverage

Function updateNAMain has 96 lines of code (exceeds 25 allowed). Consider refactoring.
Open

async function updateNAMain(deviceGladys, deviceNetatmo, externalId) {
  const { room, dashboard_data: dashboardData } = deviceNetatmo;
  try {
    deviceGladys.features
      .filter((feature) => feature.external_id === `${externalId}:temperature`)
Severity: Major
Found in server/services/netatmo/lib/update/netatmo.updateNAMain.js - About 3 hrs to fix

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

        if (dashboardData) {
          deviceGladys.features
            .filter((feature) => feature.external_id === `${externalId}:min_temp`)
            .forEach((feature) => {
              this.gladys.event.emit(EVENTS.DEVICE.NEW_STATE, {
    Severity: Major
    Found in server/services/netatmo/lib/update/netatmo.updateNAMain.js and 3 other locations - About 1 day to fix
    server/services/netatmo/lib/update/netatmo.updateNAModule1.js on lines 41..58
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 59..76
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 60..77

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 241.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

        deviceGladys.features
          .filter((feature) => feature.external_id === `${externalId}:humidity`)
          .forEach((feature) => {
            const valueDeviceNetatmo = deviceNetatmo.humidity || (dashboardData && dashboardData.Humidity);
            this.gladys.event.emit(EVENTS.DEVICE.NEW_STATE, {
    Severity: Major
    Found in server/services/netatmo/lib/update/netatmo.updateNAMain.js and 21 other locations - About 5 hrs to fix
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 15..23
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 34..42
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 52..60
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 61..69
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 70..78
    server/services/netatmo/lib/update/netatmo.updateNAModule1.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule1.js on lines 32..40
    server/services/netatmo/lib/update/netatmo.updateNAModule1.js on lines 59..67
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 32..40
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 41..49
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 50..58
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 77..85
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 32..40
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 41..49
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 50..58
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 42..50
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 51..59
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 78..86

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 136.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

        deviceGladys.features
          .filter((feature) => feature.external_id === `${externalId}:co2`)
          .forEach((feature) => {
            const valueDeviceNetatmo = deviceNetatmo.co2 || (dashboardData && dashboardData.CO2);
            this.gladys.event.emit(EVENTS.DEVICE.NEW_STATE, {
    Severity: Major
    Found in server/services/netatmo/lib/update/netatmo.updateNAMain.js and 21 other locations - About 5 hrs to fix
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 15..23
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 43..51
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 52..60
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 61..69
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 70..78
    server/services/netatmo/lib/update/netatmo.updateNAModule1.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule1.js on lines 32..40
    server/services/netatmo/lib/update/netatmo.updateNAModule1.js on lines 59..67
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 32..40
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 41..49
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 50..58
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 77..85
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 32..40
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 41..49
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 50..58
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 42..50
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 51..59
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 78..86

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 136.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

        deviceGladys.features
          .filter((feature) => feature.external_id === `${externalId}:pressure`)
          .forEach((feature) => {
            const valueDeviceNetatmo = deviceNetatmo.pressure || (dashboardData && dashboardData.Pressure);
            this.gladys.event.emit(EVENTS.DEVICE.NEW_STATE, {
    Severity: Major
    Found in server/services/netatmo/lib/update/netatmo.updateNAMain.js and 21 other locations - About 5 hrs to fix
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 15..23
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 34..42
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 43..51
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 52..60
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 70..78
    server/services/netatmo/lib/update/netatmo.updateNAModule1.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule1.js on lines 32..40
    server/services/netatmo/lib/update/netatmo.updateNAModule1.js on lines 59..67
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 32..40
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 41..49
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 50..58
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 77..85
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 32..40
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 41..49
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 50..58
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 42..50
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 51..59
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 78..86

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 136.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

        deviceGladys.features
          .filter((feature) => feature.external_id === `${externalId}:noise`)
          .forEach((feature) => {
            const valueDeviceNetatmo = deviceNetatmo.noise || (dashboardData && dashboardData.Noise);
            this.gladys.event.emit(EVENTS.DEVICE.NEW_STATE, {
    Severity: Major
    Found in server/services/netatmo/lib/update/netatmo.updateNAMain.js and 21 other locations - About 5 hrs to fix
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 15..23
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 34..42
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 43..51
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 61..69
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 70..78
    server/services/netatmo/lib/update/netatmo.updateNAModule1.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule1.js on lines 32..40
    server/services/netatmo/lib/update/netatmo.updateNAModule1.js on lines 59..67
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 32..40
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 41..49
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 50..58
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 77..85
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 32..40
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 41..49
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 50..58
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 42..50
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 51..59
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 78..86

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 136.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

        deviceGladys.features
          .filter((feature) => feature.external_id === `${externalId}:absolute_pressure`)
          .forEach((feature) => {
            const valueDeviceNetatmo = deviceNetatmo.absolute_pressure || (dashboardData && dashboardData.AbsolutePressure);
            this.gladys.event.emit(EVENTS.DEVICE.NEW_STATE, {
    Severity: Major
    Found in server/services/netatmo/lib/update/netatmo.updateNAMain.js and 21 other locations - About 5 hrs to fix
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 15..23
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 34..42
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 43..51
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 52..60
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 61..69
    server/services/netatmo/lib/update/netatmo.updateNAModule1.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule1.js on lines 32..40
    server/services/netatmo/lib/update/netatmo.updateNAModule1.js on lines 59..67
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 32..40
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 41..49
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 50..58
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 77..85
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 32..40
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 41..49
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 50..58
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 42..50
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 51..59
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 78..86

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 136.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

        deviceGladys.features
          .filter((feature) => feature.external_id === `${externalId}:temperature`)
          .forEach((feature) => {
            const valueDeviceNetatmo = deviceNetatmo.temperature || (dashboardData && dashboardData.Temperature);
            this.gladys.event.emit(EVENTS.DEVICE.NEW_STATE, {
    Severity: Major
    Found in server/services/netatmo/lib/update/netatmo.updateNAMain.js and 21 other locations - About 5 hrs to fix
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 34..42
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 43..51
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 52..60
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 61..69
    server/services/netatmo/lib/update/netatmo.updateNAMain.js on lines 70..78
    server/services/netatmo/lib/update/netatmo.updateNAModule1.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule1.js on lines 32..40
    server/services/netatmo/lib/update/netatmo.updateNAModule1.js on lines 59..67
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 32..40
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 41..49
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 50..58
    server/services/netatmo/lib/update/netatmo.updateNAModule2.js on lines 77..85
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 32..40
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 41..49
    server/services/netatmo/lib/update/netatmo.updateNAModule3.js on lines 50..58
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 23..31
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 42..50
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 51..59
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 78..86

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 136.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

        if (room) {
          deviceGladys.features
            .filter((feature) => feature.external_id === `${externalId}:therm_measured_temperature`)
            .forEach((feature) => {
              this.gladys.event.emit(EVENTS.DEVICE.NEW_STATE, {
    Severity: Major
    Found in server/services/netatmo/lib/update/netatmo.updateNAMain.js and 1 other location - About 4 hrs to fix
    server/services/netatmo/lib/update/netatmo.updateNAModule4.js on lines 32..41

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 124.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    There are no issues that match your filters.

    Category
    Status