From ebb0656127dbb5c6d925671e954f5b79bdb52621 Mon Sep 17 00:00:00 2001 From: Jeff Randall Date: Fri, 26 Jan 2024 00:09:09 -0600 Subject: [PATCH] discussion #772: Extend the hdhomerun widget - maintain the previous behavior if no additional configuration is done - define additional available fields and present the data in order configured - global: "tunerCount" - per-tuner: "channelNumber", "channelNetwork", "signalStrength", "signalQuality", "symbolQuality", "networkRate", "clientIP" - add handling for refreshInterval - update docs --- docs/widgets/services/hdhomerun.md | 10 +++- public/locales/en/common.json | 10 +++- src/widgets/hdhomerun/component.jsx | 73 +++++++++++++++++++++++++---- src/widgets/hdhomerun/widget.js | 3 ++ 4 files changed, 85 insertions(+), 11 deletions(-) diff --git a/docs/widgets/services/hdhomerun.md b/docs/widgets/services/hdhomerun.md index a7351156..5f991eea 100644 --- a/docs/widgets/services/hdhomerun.md +++ b/docs/widgets/services/hdhomerun.md @@ -3,12 +3,18 @@ title: HDHomerun description: HDHomerun Widget Configuration --- -Learn more about [HDHomerun](https://www.silicondust.com/support/downloads/). +[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. The +order that fields are configured is preserved for display. ```yaml +tuner: 0 # optional - defaults to 0, used for tuner-specific fields widget: type: hdhomerun url: http://hdhomerun.host.or.ip + refreshInterval: 10000 # optional - minimum of 1 sec, default of 10s + fields: ["channels", "hd"] # optional - default fields shown ``` diff --git a/public/locales/en/common.json b/public/locales/en/common.json index b0f60a6d..494949a5 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -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", diff --git a/src/widgets/hdhomerun/component.jsx b/src/widgets/hdhomerun/component.jsx index 2b2cb24a..a6a8ed82 100644 --- a/src/widgets/hdhomerun/component.jsx +++ b/src/widgets/hdhomerun/component.jsx @@ -2,16 +2,68 @@ 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 { widget, tuner = 0 } = service; + const { refreshInterval = 10000, fields = ["channels", "hd"] } = widget; - const { data: channelsData, error: channelsError } = useWidgetAPI(widget, "lineup"); + 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), + }); - if (channelsError) { - return ; + if (channelsError || statusError) { + const finalError = channelsError ?? statusError; + return ; } - if (!channelsData) { + if (!channelsData || !statusData) { return ( @@ -20,12 +72,17 @@ export default function Component({ service }) { ); } - const hdChannels = channelsData?.filter((channel) => channel.HD === 1); + const definitions = generateDefinitions(channelsData, statusData, tuner); return ( - - + {fields.slice(0, 4).map((field) => ( + id === field)].label} + value={definitions[Object.keys(definitions).filter((id) => id === field)].value} + /> + ))} ); } diff --git a/src/widgets/hdhomerun/widget.js b/src/widgets/hdhomerun/widget.js index 689fbf0b..e708b4d4 100644 --- a/src/widgets/hdhomerun/widget.js +++ b/src/widgets/hdhomerun/widget.js @@ -8,6 +8,9 @@ const widget = { lineup: { endpoint: "lineup.json", }, + status: { + endpoint: "status.json", + }, }, };