athombv / homey-web-api-issues

This issue tracker is for Homey Developers using the Web API.
4 stars 1 forks source link

WebApi V3 Flow IsBroken() promise false positives #53

Open martijnpoppen opened 5 months ago

martijnpoppen commented 5 months ago

Hi, Bumping this again. The isBroken() promise for flows in webApi v3 still doesn't work properly. If the call fails it will mark a flow as isBroken while it actually is not.

In flowchecker i'm using this call and it actually gives a lot of false positives. I got these flows from people which were marked as broken:

Some flows which are marked as broken while they are not broken:

"root":{10 items
"id":string"1d98c343-639c-4b16-b975-c54775689a66"
"uri":string"homey:flow:1d98c343-639c-4b16-b975-c54775689a66"
"name":string"CO detected alarm"
"folder":string"af23ce34-3164-4ec8-b4d6-797f00b35ee7"
"enabled":booltrue
"broken":boolfalse
"triggerable":boolfalse
"trigger":{3 items
"id":string"homey:zone:9919ee1e-ffbc-480b-bc4b-77fb047e9e68:alarm_true"
"args":{1 item
"capability":{2 items
"id":string"alarm_co"
"name":string"CO alarm"
}
}
"droptoken":NULL
}
"conditions":[]0 items
"actions":[6 items
0:{6 items
"id":string"homey:manager:notifications:create_notification"
"args":{1 item
"text":string"Carbon dioxide detected by [[deviceName]] , zone [[deviceZone]] "
}
"droptoken":NULL
"group":string"then"
"delay":NULL
"duration":NULL
}
1:{6 items
"id":string"homey:manager:notifications:create_notification"
"args":{1 item
"text":string"Carbon dioxide detected by[[deviceName]] in[[deviceZone]] ."
}
"droptoken":NULL
"group":string"then"
"delay":NULL
"duration":NULL
}
2:{6 items
"id":string"homey:manager:mobile:push_text"
"args":{2 items
"user":{4 items
"name":string"SOME USER"
"id":string"3ace2ca3-065c-4a22-a3f9-be7f7b37ca31"
"image":string"https://api.athom.com/user/SOMEID/avatar"
"athomId":string"REDACTED"
}
"text":string"Carbon dioxide detected by [[deviceName]] , zone [[deviceZone]] "
}
"droptoken":NULL
"group":string"then"
"delay":NULL
"duration":NULL
}
3:{6 items
"id":string"homey:manager:mobile:push_text"
"args":{2 items
"user":{4 items
"name":string"SOME USER"
"id":string"7bd3f714-d7b2-4a25-984c-a0a3fcbdc413"
"image":string"https://api.athom.com/user/SOMEID/avatar"
"athomId":string"REDACTED"
}
"text":string"Carbon dioxide detected by [[deviceName]] , zone [[deviceZone]] "
}
"droptoken":NULL
"group":string"then"
"delay":NULL
"duration":NULL
}
4:{6 items
"id":string"homey:device:341b294d-4df2-4a0d-a56f-eec40eee1aa9:start_googlecloudtts"
"uri":string"homey:device:341b294d-4df2-4a0d-a56f-eec40eee1aa9"
"group":string"then"
"delay":NULL
"duration":NULL
"args":{1 item
"text":string"Detekován oxid uhelnatý - zařízení [[deviceName]] v zóně [[deviceZone]]."
}
}
5:{6 items
"id":string"homey:manager:ledring:animate_loading"
"args":{1 item
"color":string"#FF0000"
}
"droptoken":NULL
"group":string"then"
"delay":NULL
"duration":{2 items
"number":string"10"
"multiplier":int1
}
}
]
}
"root":{10 items
"id":string"90de9a74-0567-487c-a89d-e7512c77a5ff"
"uri":string"homey:flow:90de9a74-0567-487c-a89d-e7512c77a5ff"
"name":string"Water alarm general notification"
"folder":string"af23ce34-3164-4ec8-b4d6-797f00b35ee7"
"enabled":booltrue
"broken":boolfalse
"triggerable":boolfalse
"trigger":{3 items
"id":string"homey:zone:9919ee1e-ffbc-480b-bc4b-77fb047e9e68:alarm_true"
"args":{1 item
"capability":{2 items
"id":string"alarm_water"
"name":string"Water alarm"
}
}
"droptoken":NULL
}
"conditions":[2 items
0:{5 items
"id":string"homey:manager:logic:contains"
"args":{1 item
"comparator":string"TS_FT002"
}
"droptoken":string"deviceName"
"inverted":booltrue
"group":string"group1"
}
1:{5 items
"id":string"homey:manager:logic:contains"
"args":{1 item
"comparator":string"shaft"
}
"droptoken":string"deviceName"
"inverted":booltrue
"group":string"group1"
}
]
"actions":[3 items
0:{6 items
"id":string"homey:manager:notifications:create_notification"
"args":{1 item
"text":string"Water alarm - [[deviceName]] in - [[deviceZone]] ."
}
"droptoken":NULL
"group":string"then"
"delay":NULL
"duration":NULL
}
1:{6 items
"id":string"homey:manager:logic:variable_set_boolean"
"args":{2 items
"variable":{2 items
"id":string"886564eb-47b5-4904-a011-6219404134e1"
"name":string"Alarm"
}
"value":booltrue
}
"droptoken":NULL
"group":string"then"
"delay":NULL
"duration":NULL
}
2:{6 items
"id":string"homey:manager:logic:variable_set_boolean"
"args":{2 items
"variable":{2 items
"id":string"886564eb-47b5-4904-a011-6219404134e1"
"name":string"Alarm"
}
"value":boolfalse
}
"droptoken":NULL
"group":string"then"
"delay":{2 items
"number":string"40"
"multiplier":int1
}
"duration":NULL
}
]
}
"root":{10 items
"id":string"05fc2af9-93f9-405e-bc0d-6d155c2dc1fd"
"uri":string"homey:flow:05fc2af9-93f9-405e-bc0d-6d155c2dc1fd"
"name":string"Dim downlight bathroom"
"folder":string"2184da0b-b97e-443c-af62-ff662bba1dce"
"enabled":booltrue
"broken":boolfalse
"triggerable":boolfalse
"trigger":{3 items
"id":string"homey:device:8cc5b245-f3c5-468d-80f4-4c89dbf4a12a:dim_changed"
"args":{}0 items
"droptoken":NULL
}
"conditions":[1 item
0:{5 items
"id":string"homey:device:8eb9bdf5-580d-42f6-bd68-7718a29d806e:on"
"args":{}0 items
"droptoken":NULL
"inverted":NULL
"group":string"group1"
}
]
"actions":[4 items
0:{6 items
"id":string"homey:manager:logic:variable_set_number"
"args":{2 items
"variable":{2 items
"id":string"c10e779b-246c-4db0-b628-789b382c696f"
"name":string"Downlight_temp"
}
"value":string"[[homey:device:8cc5b245-f3c5-468d-80f4-4c89dbf4a12a|light_temperature]]"
}
"droptoken":NULL
"group":string"then"
"delay":NULL
"duration":NULL
}
1:{6 items
"id":string"homey:manager:logic:variable_set_number_math"
"args":{2 items
"variable":{2 items
"id":string"c10e779b-246c-4db0-b628-789b382c696f"
"name":string"Downlight_temp"
}
"value":string"1-[[homey:manager:logic|c10e779b-246c-4db0-b628-789b382c696f]] "
}
"droptoken":NULL
"group":string"then"
"delay":{2 items
"number":string"1"
"multiplier":int1
}
"duration":NULL
}
2:{6 items
"id":string"homey:device:8eb9bdf5-580d-42f6-bd68-7718a29d806e:dim"
"args":{1 item
"dim":string"[[dim]]"
}
"droptoken":NULL
"group":string"then"
"delay":NULL
"duration":NULL
}
3:{6 items
"id":string"homey:device:8eb9bdf5-580d-42f6-bd68-7718a29d806e:temperature"
"args":{1 item
"temperature":string"[[homey:manager:logic|c10e779b-246c-4db0-b628-789b382c696f]]"
}
"droptoken":NULL
"group":string"then"
"delay":{2 items
"number":string"2"
"multiplier":int1
}
"duration":NULL
}
]
}
martijnpoppen commented 5 months ago

My code:

async getApiData() {
    this.log(`[getApiData] Setting API_DATA`);
    await this._api.flow.connect();
    await this._api.flowtoken.connect();
    await sleep(2000);

    // Fill all caches
    this.API_DATA.FLOWTOKENS = Object.values(await this._api.flowtoken.getFlowTokens().catch(e => { console.log(e); return {}}));
    this.API_DATA.FLOWS = Object.values(await this._api.flow.getFlows().catch(e => { console.log(e); return {}}));
    this.API_DATA.ADVANCED_FLOWS = Object.values(await this._api.flow.getAdvancedFlows().catch(e => { console.log(e); return {}}));
    this.API_DATA.FOLDERS = Object.values(await this._api.flow.getFlowFolders().catch(e => { console.log(e); return {}}));
    this.API_DATA.SCREENSAVERS = this.appSettings.HOMEY_VERSION === 'Homey2023' ? [] : await this._api.ledring.getScreensavers().catch(e => { console.log(e); return []});
    this.API_DATA.APPS = Object.values(await this._api.apps.getApps().catch(e => { console.log(e); return {}}));
    this.API_DATA.VARIABLES = Object.values(await this._api.logic.getVariables().catch(e => { console.log(e); return {}}));

    this.log(`[getApiData] Setting API_DATA - data length:`, Object.keys(this.API_DATA).length);
}
   async findBrokenFlows() {
    const flowsArray = [...this.API_DATA.FLOWS, ...this.API_DATA.ADVANCED_FLOWS];

    try {
        // Add promises to array
        for (let i = 0; i < flowsArray.length; i++) {
            if (await flowsArray[i].isBroken().catch(e => { this.log(`[findFlows] ${key} - isBroken Error: `, e); return false })) {
                console.log(`[findFlows] ${key} - isBroken: `, flowsArray[i].name);
                flows.push(flowsArray[i]);
            }
        }
    } catch (error) {
        this.log(`[findFlows] ${key} - Error: `, error);
    }
}