8
8
"github.com/djthorpe/go-tablewriter"
9
9
"github.com/mutablelogic/go-client"
10
10
"github.com/mutablelogic/go-client/pkg/homeassistant"
11
+ "golang.org/x/exp/maps"
11
12
)
12
13
13
14
///////////////////////////////////////////////////////////////////////////////
@@ -26,7 +27,7 @@ type haEntity struct {
26
27
27
28
type haDomain struct {
28
29
Name string `json:"domain"`
29
- Services string `json:"services,omitempty"`
30
+ Services string `json:"services,omitempty,width:40,wrap "`
30
31
}
31
32
32
33
///////////////////////////////////////////////////////////////////////////////
@@ -103,10 +104,27 @@ func haDomains(_ context.Context, w *tablewriter.Writer, args []string) error {
103
104
classes [state .Class ] = true
104
105
}
105
106
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
+
106
117
result := []haDomain {}
107
118
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
+ }
108
125
result = append (result , haDomain {
109
- Name : c ,
126
+ Name : c ,
127
+ Services : strings .Join (services , ", " ),
110
128
})
111
129
}
112
130
return w .Write (result )
0 commit comments