Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: add bitrate precision config option for speedtest-tracker #3354

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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