Implement phase 1 completion and phase 2 dynamic QR
This commit is contained in:
26
dist/shared/services/deviceCapabilityResolver.js
vendored
Normal file
26
dist/shared/services/deviceCapabilityResolver.js
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
function getProfile(device) {
|
||||
return (device.capability_profile_json || {});
|
||||
}
|
||||
export function supportsDynamicQrFlow(device, flow) {
|
||||
const profile = getProfile(device);
|
||||
const flows = Array.isArray(profile.flows) ? profile.flows : [];
|
||||
if (flow === "api_direct" && device.communication_mode !== "api") {
|
||||
return false;
|
||||
}
|
||||
if (flow === "mqtt" && device.communication_mode !== "mqtt") {
|
||||
return false;
|
||||
}
|
||||
if (typeof profile.dynamic_qr === "boolean") {
|
||||
return profile.dynamic_qr || flows.includes(`dynamic_qr:${flow}`);
|
||||
}
|
||||
if (profile.dynamic_qr && typeof profile.dynamic_qr === "object") {
|
||||
return Boolean(profile.dynamic_qr[flow]) || flows.includes(`dynamic_qr:${flow}`);
|
||||
}
|
||||
return flows.includes(`dynamic_qr:${flow}`);
|
||||
}
|
||||
export function resolveDeviceCapabilitySummary(device) {
|
||||
return {
|
||||
dynamic_qr_api_direct: supportsDynamicQrFlow(device, "api_direct"),
|
||||
dynamic_qr_mqtt: supportsDynamicQrFlow(device, "mqtt")
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user