Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
FabFaeb committed Apr 30, 2024
1 parent aac0240 commit 39f080b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cmd/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand All @@ -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
}

0 comments on commit 39f080b

Please sign in to comment.