clone

a desktop tv and program guide for over-the-air broadcasts: what's on air, what your tuner gets, live tv, recordings

Read Tvheadend's hardware tree when it writes leaf as a number

FelineStateMachine committed 1b49589
Tvheadend 4.3 sends "leaf": 0 for a network HDHomeRun, which stopped the
tuner setup before it found the tuners.
commit
1b49589c385a1f85374e287f46985396a4fe37aa
parent
1d4e2e34c6b6f80b84b52a7abaa9f79a9d35cf6c
author
FelineStateMachine <226808055+FelineStateMachine@users.noreply.github.com>
2 files changed, +60 -4
Minternal/tvh/setup.go24+++++++++++++++---
Ainternal/tvh/setup_test.go40++++++++++++++++++++++++++++++
M internal/tvh/setup.go +20 -4
@@ -255,9 +255,9 @@ func (c *Client) Frontends(ctx context.Context) ([]Frontend, error) {
255255 var walk func(uuid string, depth int) error256256 walk = func(uuid string, depth int) error {257257 var nodes []struct {258- UUID string `json:"uuid"`259- Text string `json:"text"`260- Leaf bool `json:"leaf"`258+ UUID string `json:"uuid"`259+ Text string `json:"text"`260+ Leaf flexBool `json:"leaf"`261261 }262262 if err := c.get(ctx, "/api/hardware/tree", url.Values{"uuid": {uuid}}, &nodes); err != nil {263263 return err
@@ -270,7 +270,7 @@ func (c *Client) Frontends(ctx context.Context) ([]Frontend, error) {
270270 if strings.Contains(class, "_frontend_atsc") {271271 out = append(out, Frontend{UUID: n.UUID, Class: class, Name: n.Text})272272 }273- if !n.Leaf && depth < 3 {273+ if !bool(n.Leaf) && depth < 3 {274274 if err := walk(n.UUID, depth+1); err != nil {275275 return err276276 }
@@ -281,6 +281,22 @@ func (c *Client) Frontends(ctx context.Context) ([]Frontend, error) {
281281 return out, walk("root", 0)282282 }283283 284+// flexBool is a JSON boolean that Tvheadend sometimes writes as 0 or 1285+// (the hardware tree's "leaf").286+type flexBool bool287+288+func (b *flexBool) UnmarshalJSON(raw []byte) error {289+ switch string(raw) {290+ case "true", "1":291+ *b = true292+ case "false", "0", "null":293+ *b = false294+ default:295+ return fmt.Errorf("%s is not a boolean", raw)296+ }297+ return nil298+}299+284300 func (c *Client) class(ctx context.Context, uuid string) (string, error) {285301 var body struct {286302 Entries []struct {
A internal/tvh/setup_test.go +40 -0