diff --git a/internal/http/http.go b/internal/http/http.go index 8d9c9f7..71c9eaf 100644 --- a/internal/http/http.go +++ b/internal/http/http.go @@ -40,6 +40,14 @@ func (c *HttpClient) GetState(entityId string) ([]byte, error) { return resp, nil } +func (c *HttpClient) States() ([]byte, error) { + resp, err := get(c.url+"/states", c.token) + if err != nil { + return nil, err + } + return resp, nil +} + func get(url, token string) ([]byte, error) { req, err := http.NewRequest("GET", url, nil) if err != nil { diff --git a/state.go b/state.go index 2f1e700..4b95c08 100644 --- a/state.go +++ b/state.go @@ -16,6 +16,7 @@ type State interface { BeforeSunrise(...DurationString) bool AfterSunset(...DurationString) bool BeforeSunset(...DurationString) bool + List() ([]EntityState, error) Get(entityId string) (EntityState, error) Equals(entityId, state string) (bool, error) } @@ -74,6 +75,16 @@ func (s *StateImpl) Get(entityId string) (EntityState, error) { return es, err } +func (s *StateImpl) List() ([]EntityState, error) { + resp, err := s.httpClient.States() + if err != nil { + return nil, err + } + es := []EntityState{} + err = json.Unmarshal(resp, &es) + return es, err +} + func (s *StateImpl) Equals(entityId string, expectedState string) (bool, error) { currentState, err := s.Get(entityId) if err != nil {