CFenner/MMM-Netatmo

View on GitHub
helper.js

Summary

Maintainability
D
2 days
Test Coverage

Showing 9 of 9 total issues

Function loadData has 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

async loadData () {
if (this.config.mockData === true) {
this.sendSocketNotification(this.notifications.DATA_RESPONSE, {
payloadReturn: this.mockData(),
status: 'OK',
Severity: Minor
Found in helper.js - About 1 hr to fix

    Function authenticateRefresh has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    async authenticateRefresh (refreshToken) {
    console.log('Netatmo: Refresh Token')
    const params = new URLSearchParams()
    params.append('grant_type', 'refresh_token')
    params.append('refresh_token', refreshToken)
    Severity: Minor
    Found in helper.js - About 1 hr to fix

      Function authenticate has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      async authenticate () {
      const params = new URLSearchParams()
      params.append('grant_type', 'refresh_token')
      params.append('refresh_token', this.refreshToken)
      params.append('client_id', this.clientId)
      Severity: Minor
      Found in helper.js - About 1 hr to fix

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

        if (result.expires_in) {
        const expireAt = moment(Date.now() + (result.expires_in * 1000)).format('LLLL')
        console.log(`Netatmo: New Token Expire ${expireAt}`)
        setTimeout(() => this.authenticateRefresh(result.refresh_token), (result.expires_in - 60) * 1000)
        };
        Severity: Major
        Found in helper.js and 1 other location - About 3 hrs to fix
        helper.js on lines 230..234

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

        if (result.expires_in) {
        const expireAt = moment(Date.now() + (result.expires_in * 1000)).format('LLLL')
        console.log(`Netatmo: New Token Expire ${expireAt}`)
        setTimeout(() => this.authenticateRefresh(result.refresh_token), (result.expires_in - 60) * 1000)
        };
        Severity: Major
        Found in helper.js and 1 other location - About 3 hrs to fix
        helper.js on lines 50..54

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

        const result = await fetch(`https://${this.config.apiBase}${this.config.authEndpoint}`, {
        method: 'POST',
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        body: params,
        }).then((response) => response.json())
        Severity: Major
        Found in helper.js and 1 other location - About 2 hrs to fix
        helper.js on lines 216..220

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

        const result = await fetch(`https://${this.config.apiBase}${this.config.authEndpoint}`, {
        method: 'POST',
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        body: params,
        }).then((response) => response.json())
        Severity: Major
        Found in helper.js and 1 other location - About 2 hrs to fix
        helper.js on lines 33..37

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

        try {
        const result = await fetch(`https://${this.config.apiBase}${this.config.authEndpoint}`, {
        method: 'POST',
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        body: params,
        Severity: Major
        Found in helper.js and 1 other location - About 1 hr to fix
        helper.js on lines 88..123

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

        try {
        let result = await fetch(`https://${this.config.apiBase}${this.config.dataEndpoint}`, {
        headers: {
        'Content-Type': 'application/json',
        Authorization: `Bearer ${this.token}`,
        Severity: Major
        Found in helper.js and 1 other location - About 1 hr to fix
        helper.js on lines 32..67

        There are no issues that match your filters.

        Category
        Status