diff --git a/cmd/client/client.go b/cmd/client/client.go index f9e0f3a..441c84a 100644 --- a/cmd/client/client.go +++ b/cmd/client/client.go @@ -274,6 +274,9 @@ func getResults(c *Client) ([][]float64, error) { if !data.Success { return nil, fmt.Errorf("api response error: %v", data.Error) } + if len(data.Result[sensorID]) == 0 { + return nil, fmt.Errorf("no results returned - is your sensorID '%s' correct?", sensorID) + } changeSlice := make([]float64, hoursInADay) for j := range changeSlice { changeSlice[j] = data.Result[sensorID][j].Change diff --git a/cmd/root.go b/cmd/root.go index 8f10a81..76a0bc3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -112,7 +112,7 @@ func initConfig() { func promtUserConfig() error { urlPrompt := prompter.Prompt("Home Assistant URL - e.g. http://localhost:8123", "") token := prompter.Password("Home Assistant Long-Lived Access Token") - sensor := prompter.Prompt("Power sensor entity ID - e.g. sensor.power", "") + sensorID := prompter.Prompt("Power sensor entity ID - e.g. sensor.power", "") haURL, err := url.Parse(urlPrompt) if haURL.Scheme == "" { @@ -124,6 +124,6 @@ func promtUserConfig() error { viper.Set("api_key", token) viper.Set("url", haURL.String()) - viper.Set("sensor", sensor) + viper.Set("sensor_id", sensorID) return nil }