mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-10 04:07:28 -06:00
Add functionality to list entities from REST endpoint
This commit is contained in:
11
state.go
11
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 {
|
||||
|
||||
Reference in New Issue
Block a user