Skip to content

Commit

Permalink
Enhancement: add bitrate precision config option for speedtest-tracker (
Browse files Browse the repository at this point in the history
#3354)

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
  • Loading branch information
ameerabdallah and shamoon committed Apr 23, 2024
1 parent 312e97d commit 3404243
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/widgets/services/speedtest-tracker.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ Allowed fields: `["download", "upload", "ping"]`.
widget:
type: speedtest
url: http://speedtest.host.or.ip
bitratePrecision: 3 # optional, default is 0
```
8 changes: 8 additions & 0 deletions src/utils/config/service-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,9 @@ export function cleanServiceGroups(groups) {
// proxmox
node,

// speedtest
bitratePrecision,

// sonarr, radarr
enableQueue,

Expand Down Expand Up @@ -588,6 +591,11 @@ export function cleanServiceGroups(groups) {
if (type === "healthchecks") {
if (uuid !== undefined) cleanedService.widget.uuid = uuid;
}
if (type === "speedtest") {
if (bitratePrecision !== undefined) {
cleanedService.widget.bitratePrecision = parseInt(bitratePrecision, 10);
}
}
}

return cleanedService;
Expand Down
18 changes: 16 additions & 2 deletions src/widgets/speedtest/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export default function Component({ service }) {

const { data: speedtestData, error: speedtestError } = useWidgetAPI(widget, "speedtest/latest");

const bitratePrecision =
!widget?.bitratePrecision || Number.isNaN(widget?.bitratePrecision) || widget?.bitratePrecision < 0
? 0
: widget.bitratePrecision;

if (speedtestError) {
return <Container service={service} error={speedtestError} />;
}
Expand All @@ -29,9 +34,18 @@ export default function Component({ service }) {
<Container service={service}>
<Block
label="speedtest.download"
value={t("common.bitrate", { value: speedtestData.data.download * 1000 * 1000 })}
value={t("common.bitrate", {
value: speedtestData.data.download * 1000 * 1000,
decimals: bitratePrecision,
})}
/>
<Block
label="speedtest.upload"
value={t("common.bitrate", {
value: speedtestData.data.upload * 1000 * 1000,
decimals: bitratePrecision,
})}
/>
<Block label="speedtest.upload" value={t("common.bitrate", { value: speedtestData.data.upload * 1000 * 1000 })} />
<Block
label="speedtest.ping"
value={t("common.ms", {
Expand Down

0 comments on commit 3404243

Please sign in to comment.