Skip to content

Commit

Permalink
Enhancement: extend hdhomerun widget (#2757)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffRandall authored Jan 26, 2024
1 parent 23e697e commit 05a7c0f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
6 changes: 5 additions & 1 deletion docs/widgets/services/hdhomerun.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ description: HDHomerun Widget Configuration

Learn more about [HDHomerun](https://www.silicondust.com/support/downloads/).

Allowed fields: `["channels", "hd"]`.
Allowed fields: `["channels", "hd", "tunerCount", "channelNumber", "channelNetwork", "signalStrength", "signalQuality", "symbolQuality", "networkRate", "clientIP" ]`.

If more than 4 fields are provided, only the first 4 are displayed.

```yaml
widget:
type: hdhomerun
url: http://hdhomerun.host.or.ip
tuner: 0 # optional - defaults to 0, used for tuner-specific fields
fields: ["channels", "hd"] # optional - default fields shown
```
10 changes: 9 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,15 @@
},
"hdhomerun": {
"channels": "Channels",
"hd": "HD"
"hd": "HD",
"tunerCount": "Tuners",
"channelNumber": "Channel",
"channelNetwork": "Network",
"signalStrength": "Strength",
"signalQuality": "Quality",
"symbolQuality": "Quality",
"networkRate": "Bitrate",
"clientIP": "Client"
},
"scrutiny": {
"passed": "Passed",
Expand Down
6 changes: 6 additions & 0 deletions src/utils/config/service-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ export function cleanServiceGroups(groups) {
// glances, customapi, iframe
refreshInterval,

// hdhomerun
tuner,

// healthchecks
uuid,

Expand Down Expand Up @@ -541,6 +544,9 @@ export function cleanServiceGroups(groups) {
if (showTime) cleanedService.widget.showTime = showTime;
if (timezone) cleanedService.widget.timezone = timezone;
}
if (type === "hdhomerun") {
if (tuner !== undefined) cleanedService.widget.tuner = tuner;
}
if (type === "healthchecks") {
if (uuid !== undefined) cleanedService.widget.uuid = uuid;
}
Expand Down
33 changes: 27 additions & 6 deletions src/widgets/hdhomerun/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import useWidgetAPI from "utils/proxy/use-widget-api";

export default function Component({ service }) {
const { widget } = service;
const { tuner = 0 } = widget;

const { data: channelsData, error: channelsError } = useWidgetAPI(widget, "lineup");
const { data: statusData, error: statusError } = useWidgetAPI(widget, "status");

if (channelsError) {
return <Container service={service} error={channelsError} />;
if (channelsError || statusError) {
const finalError = channelsError ?? statusError;
return <Container service={service} error={finalError} />;
}

if (!channelsData) {
if (!channelsData || !statusData) {
return (
<Container service={service}>
<Block label="hdhomerun.channels" />
Expand All @@ -20,12 +23,30 @@ export default function Component({ service }) {
);
}

const hdChannels = channelsData?.filter((channel) => channel.HD === 1);
// Provide a default if not set in the config
if (!widget.fields) {
widget.fields = ["channels", "hd"];
}
// Limit to a maximum of 4 at a time
if (widget.fields.length > 4) {
widget.fields = widget.fields.slice(0, 4);
}

return (
<Container service={service}>
<Block label="hdhomerun.channels" value={channelsData.length} />
<Block label="hdhomerun.hd" value={hdChannels.length} />
<Block label="hdhomerun.channels" value={channelsData?.length} />
<Block label="hdhomerun.hd" value={channelsData?.filter((channel) => channel.HD === 1)?.length} />
<Block
label="hdhomerun.tunerCount"
value={`${statusData?.filter((num) => num.VctNumber != null).length ?? 0} / ${statusData?.length ?? 0}`}
/>
<Block label="hdhomerun.channelNumber" value={statusData[tuner]?.VctNumber ?? null} />
<Block label="hdhomerun.channelNetwork" value={statusData[tuner]?.VctName ?? null} />
<Block label="hdhomerun.signalStrength" value={statusData[tuner]?.SignalStrengthPercent ?? null} />
<Block label="hdhomerun.signalQuality" value={statusData[tuner]?.SignalQualityPercent ?? null} />
<Block label="hdhomerun.symbolQuality" value={statusData[tuner]?.SymbolQualityPercent ?? null} />
<Block label="hdhomerun.clientIP" value={statusData[tuner]?.TargetIP ?? null} />
<Block label="hdhomerun.networkRate" value={statusData[tuner]?.NetworkRate ?? null} />
</Container>
);
}
3 changes: 3 additions & 0 deletions src/widgets/hdhomerun/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const widget = {
lineup: {
endpoint: "lineup.json",
},
status: {
endpoint: "status.json",
},
},
};

Expand Down

0 comments on commit 05a7c0f

Please sign in to comment.