From ad41de623b665f8d24d886d04e29409ee00d0304 Mon Sep 17 00:00:00 2001 From: Dobroslav Totev Date: Wed, 3 Apr 2024 11:51:23 +0200 Subject: [PATCH] fix: return predefined fallbacks on bad modem values for powerLevel and snr (#143) --- src/modem/arris-modem.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/modem/arris-modem.ts b/src/modem/arris-modem.ts index b689605..7adff9b 100644 --- a/src/modem/arris-modem.ts +++ b/src/modem/arris-modem.ts @@ -45,16 +45,18 @@ export function normalizeChannelStatus(channelStatus: ArrisDocsisChannelStatus): frequency.frequencyStart = Number(ofdmaFrequency[0]) frequency.frequencyEnd = Number(ofdmaFrequency[1]) } - + + const powerLevel = parseFloat(channelStatus.PowerLevel.split("/")[0]); + const snr = parseInt(`${channelStatus.SNRLevel ?? 0}`, 10); return { channelId: channelStatus.ChannelID, channelType: channelStatus.ChannelType, modulation: channelStatus.Modulation, - powerLevel: parseFloat(channelStatus.PowerLevel.split('/')[0]), + powerLevel: isNaN(powerLevel) ? -100 : powerLevel, lockStatus: channelStatus.LockStatus, - snr: parseInt(`${channelStatus.SNRLevel ?? 0}`, 10), - ...frequency - } as HumanizedDocsisChannelStatus | HumanizedDocsis31ChannelStatus + snr: isNaN(snr) ? 0 : snr, + ...frequency, + } as HumanizedDocsisChannelStatus | HumanizedDocsis31ChannelStatus; } export function normalizeDocsisStatus(arrisDocsisStatus: ArrisDocsisStatus): DocsisStatus {