diff --git a/src/widgets/hdhomerun/component.jsx b/src/widgets/hdhomerun/component.jsx index 614578a5..a118eafe 100644 --- a/src/widgets/hdhomerun/component.jsx +++ b/src/widgets/hdhomerun/component.jsx @@ -2,61 +2,12 @@ import Container from "components/services/widget/container"; import Block from "components/services/widget/block"; import useWidgetAPI from "utils/proxy/use-widget-api"; -function generateDefinitions(channelsData, statusData, tuner) { - return { - channels: { - label: "hdhomerun.channels", - value: channelsData?.length, - }, - hd: { - label: "hdhomerun.hd", - value: channelsData?.filter((channel) => channel.HD === 1)?.length, - }, - tunerCount: { - label: "hdhomerun.tunerCount", - value: `${statusData?.filter((num) => num.VctNumber != null).length ?? 0} / ${statusData?.length ?? 0}`, - }, - channelNumber: { - label: "hdhomerun.channelNumber", - value: statusData[tuner]?.VctNumber ?? null, - }, - channelNetwork: { - label: "hdhomerun.channelNetwork", - value: statusData[tuner]?.VctName ?? null, - }, - signalStrength: { - label: "hdhomerun.signalStrength", - value: statusData[tuner]?.SignalStrengthPercent ?? null, - }, - signalQuality: { - label: "hdhomerun.signalQuality", - value: statusData[tuner]?.SignalQualityPercent ?? null, - }, - symbolQuality: { - label: "hdhomerun.symbolQuality", - value: statusData[tuner]?.SymbolQualityPercent ?? null, - }, - clientIP: { - label: "hdhomerun.clientIP", - value: statusData[tuner]?.TargetIP ?? null, - }, - networkRate: { - label: "hdhomerun.networkRate", - value: statusData[tuner]?.NetworkRate ?? null, - }, - }; -} - export default function Component({ service }) { const { widget } = service; - const { tuner = 0, refreshInterval = 10000, fields = ["channels", "hd"] } = widget; + const { tuner = 0 } = widget; - const { data: channelsData, error: channelsError } = useWidgetAPI(widget, "lineup", { - refreshInterval: Math.max(1000, refreshInterval), - }); - const { data: statusData, error: statusError } = useWidgetAPI(widget, "status", { - refreshInterval: Math.max(1000, refreshInterval), - }); + const { data: channelsData, error: channelsError } = useWidgetAPI(widget, "lineup"); + const { data: statusData, error: statusError } = useWidgetAPI(widget, "status"); if (channelsError || statusError) { const finalError = channelsError ?? statusError; @@ -72,17 +23,30 @@ export default function Component({ service }) { ); } - const definitions = generateDefinitions(channelsData, statusData, tuner); + // 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 ( - {fields.slice(0, 4).map((field) => ( - id === field)].label} - value={definitions[Object.keys(definitions).filter((id) => id === field)].value} - /> - ))} + + channel.HD === 1)?.length} /> + num.VctNumber != null).length ?? 0} / ${statusData?.length ?? 0}`} + /> + + + + + + + ); }