mirror of
https://github.com/gosticks/go-hue-interface.git
synced 2025-10-16 11:45:35 +00:00
add missing values to groups
This commit is contained in:
parent
ea74853787
commit
b52a03caad
45
groups.go
45
groups.go
@ -1,6 +1,9 @@
|
|||||||
package hue
|
package hue
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
const groupsEndpoint = "/groups"
|
const groupsEndpoint = "/groups"
|
||||||
|
|
||||||
@ -49,10 +52,13 @@ const (
|
|||||||
// Group hue type
|
// Group hue type
|
||||||
type Group struct {
|
type Group struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
LightIDs []string `json:"Lights"`
|
LightIDs []string `json:"lights"`
|
||||||
|
SensorIDs []string `json:"sensors"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Action LightState `json:"action"`
|
State *GroupState `json:"state"`
|
||||||
|
Recycle bool `json:"recycle"`
|
||||||
Class string `json:"class,omitempty"`
|
Class string `json:"class,omitempty"`
|
||||||
|
Action LightState `json:"action"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GroupCreateResponse is returned after a create group request
|
// GroupCreateResponse is returned after a create group request
|
||||||
@ -62,6 +68,11 @@ type GroupCreateResponse struct {
|
|||||||
} `json:"success"`
|
} `json:"success"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GroupState struct {
|
||||||
|
AllOn bool `json:"all_on"`
|
||||||
|
AnyOn bool `json:"any_on"`
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
// ~ String conversions
|
// ~ String conversions
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
@ -95,7 +106,7 @@ func (r RoomClasses) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
// ~ Private methods
|
// ~ Public methods
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
|
|
||||||
// CreateGroup creates a new hue group. For rooms please use the CreateRoom call since it also needs a class
|
// CreateGroup creates a new hue group. For rooms please use the CreateRoom call since it also needs a class
|
||||||
@ -113,6 +124,17 @@ func (b *Bridge) CreateGroup(name string, groupType GroupType, lights []string)
|
|||||||
return b.createGroup(groupConfig)
|
return b.createGroup(groupConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAllGroups returns all the groups for a hue bridge
|
||||||
|
func (b *Bridge) GetAllGroups() (map[string]*Group, error) {
|
||||||
|
result := make(map[string]*Group)
|
||||||
|
errCom := b.getAndDecode(groupsEndpoint, &result)
|
||||||
|
if errCom != nil {
|
||||||
|
return nil, errCom
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
// CreateRoom creates a new hue room.
|
// CreateRoom creates a new hue room.
|
||||||
func (b *Bridge) CreateRoom(name string, class RoomClasses, lights []string) (string, error) {
|
func (b *Bridge) CreateRoom(name string, class RoomClasses, lights []string) (string, error) {
|
||||||
groupConfig := &Group{
|
groupConfig := &Group{
|
||||||
@ -124,6 +146,8 @@ func (b *Bridge) CreateRoom(name string, class RoomClasses, lights []string) (st
|
|||||||
return b.createGroup(groupConfig)
|
return b.createGroup(groupConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// func (b *Bridge) SetGroupAttributes(id string)
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
// ~ Private methods
|
// ~ Private methods
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
@ -134,9 +158,16 @@ func (b *Bridge) createGroup(group *Group) (string, error) {
|
|||||||
return "", errCreate
|
return "", errCreate
|
||||||
}
|
}
|
||||||
|
|
||||||
newGroups, ok := res.([]*GroupCreateResponse)
|
result := []*GroupCreateResponse{}
|
||||||
if ok && len(newGroups) == 1 {
|
|
||||||
return newGroups[0].Success.ID, nil
|
// Unmarshal data
|
||||||
|
errDecode := json.NewDecoder(res.Body).Decode(result)
|
||||||
|
if errDecode != nil {
|
||||||
|
return "", errDecode
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(result) == 1 {
|
||||||
|
return result[0].Success.ID, nil
|
||||||
} else {
|
} else {
|
||||||
return "", fmt.Errorf("could not create group, bridge did not return new group id")
|
return "", fmt.Errorf("could not create group, bridge did not return new group id")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user