Skip to content

Commit

Permalink
convert numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
philipparndt committed Nov 1, 2022
1 parent 65e0cff commit 21da919
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/lib/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import { Options, query } from "./api/fritzbox"
import { log } from "./logger"
import { connectMqtt, publish } from "./mqtt/mqtt-client"

const isNumeric = (str: any) => {
return !isNaN(parseFloat(str)) && isFinite(str)
}

const convertType = (value: any) => {
return isNumeric(value) ? +value : value
}

const fetchFritzBoxData = async (config = getAppConfig().fritzbox) => {
const options: Options = {
server: config.host,
Expand Down Expand Up @@ -30,7 +38,7 @@ const fetchFritzBoxData = async (config = getAppConfig().fritzbox) => {
}
}

result[value.name] = valueData
result[value.name] = convertType(valueData)
}
}
catch (e: any) {
Expand Down

0 comments on commit 21da919

Please sign in to comment.