Skip to content

Commit f7aeac0

Browse files
committed
Added services to domains command call
1 parent 316c55a commit f7aeac0

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

cmd/api/homeassistant.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/djthorpe/go-tablewriter"
99
"github.com/mutablelogic/go-client"
1010
"github.com/mutablelogic/go-client/pkg/homeassistant"
11+
"golang.org/x/exp/maps"
1112
)
1213

1314
///////////////////////////////////////////////////////////////////////////////
@@ -26,7 +27,7 @@ type haEntity struct {
2627

2728
type haDomain struct {
2829
Name string `json:"domain"`
29-
Services string `json:"services,omitempty"`
30+
Services string `json:"services,omitempty,width:40,wrap"`
3031
}
3132

3233
///////////////////////////////////////////////////////////////////////////////
@@ -103,10 +104,27 @@ func haDomains(_ context.Context, w *tablewriter.Writer, args []string) error {
103104
classes[state.Class] = true
104105
}
105106

107+
// Get all the domains, and make a map of them
108+
domains, err := haClient.Domains()
109+
if err != nil {
110+
return err
111+
}
112+
map_domains := make(map[string]*homeassistant.Domain)
113+
for _, domain := range domains {
114+
map_domains[domain.Domain] = domain
115+
}
116+
106117
result := []haDomain{}
107118
for c := range classes {
119+
var services []string
120+
if domain, exists := map_domains[c]; exists {
121+
if v := domain.Services; v != nil {
122+
services = maps.Keys(v)
123+
}
124+
}
108125
result = append(result, haDomain{
109-
Name: c,
126+
Name: c,
127+
Services: strings.Join(services, ", "),
110128
})
111129
}
112130
return w.Write(result)

0 commit comments

Comments
 (0)