diff --git a/Personal Light Bulb/31393132383041332d344138372d343636392d393643362d303634373934383736303034.entity b/Personal Light Bulb/31393132383041332d344138372d343636392d393643362d303634373934383736303034.entity deleted file mode 100644 index 4bb377e..0000000 --- a/Personal Light Bulb/31393132383041332d344138372d343636392d393643362d303634373934383736303034.entity +++ /dev/null @@ -1 +0,0 @@ -{"Name":"191280A3-4A87-4669-96C6-064794876004","PublicKey":"oSLgMjcuMkZynqswmP9PSaNOkQvWgWvNKgOPWjLlVsw=","PrivateKey":null} \ No newline at end of file diff --git a/Personal Light Bulb/39343a61383a38303a39623a37323a3364.entity b/Personal Light Bulb/39343a61383a38303a39623a37323a3364.entity deleted file mode 100644 index ee2a6ac..0000000 --- a/Personal Light Bulb/39343a61383a38303a39623a37323a3364.entity +++ /dev/null @@ -1 +0,0 @@ -{"Name":"94:a8:80:9b:72:3d","PublicKey":"57Z/hKa1lyMTMPPwxWbYf9nGH/tVmXGBnPfMcswvh5U=","PrivateKey":"OWViYzNiZTk1YjI4ZDkzYTA5YzlkNjZiZjQ0ZmMyOWHntn+EprWXIxMw8/DFZth/2cYf+1WZcYGc98xyzC+HlQ=="} \ No newline at end of file diff --git a/Personal Light Bulb/configHash b/Personal Light Bulb/configHash deleted file mode 100644 index d185cdf..0000000 --- a/Personal Light Bulb/configHash +++ /dev/null @@ -1 +0,0 @@ -AŽèŠ<²ù¥‚ çôè„ \ No newline at end of file diff --git a/Personal Light Bulb/uuid b/Personal Light Bulb/uuid deleted file mode 100644 index 4bd9f1f..0000000 --- a/Personal Light Bulb/uuid +++ /dev/null @@ -1 +0,0 @@ -94:a8:80:9b:72:3d \ No newline at end of file diff --git a/Personal Light Bulb/version b/Personal Light Bulb/version deleted file mode 100644 index 56a6051..0000000 --- a/Personal Light Bulb/version +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/groups.go b/groups.go index 10fdd20..a9f665f 100644 --- a/groups.go +++ b/groups.go @@ -1,8 +1,21 @@ package hue +import "fmt" + +const groupsEndpoint = "/groups" + +// ------------------------------------------------------------- +// ~ Types +// ------------------------------------------------------------- + +// GroupType hue group type type GroupType int +// RoomClasses in hue +type RoomClasses int + const ( + // All is a group containing all devices cannot be created All GroupType = iota Luminaire Lightsource @@ -10,3 +23,121 @@ const ( Room Entertainment ) + +const ( + LivingRoom RoomClasses = iota + Kitchen + Dining + Bedroom + KidsBedroom + Bathroom + Nursery + Recreation + Office + Gym + Hallway + Toilet + FrontDoor + Garage + Terrace + Garden + Driveway + Carport + Other +) + +// Group hue type +type Group struct { + Name string `json:"name"` + LightIDs []string `json:"Lights"` + Type string `json:"type"` + Action LightState `json:"action"` + Class string `json:"class,omitempty"` +} + +// GroupCreateResponse is returned after a create group request +type GroupCreateResponse struct { + Success struct { + ID string `json:"id"` + } `json:"success"` +} + +// ------------------------------------------------------------- +// ~ String conversions +// ------------------------------------------------------------- + +func (g GroupType) String() string { + return [...]string{"0", "Luminaire", "Lightsource", "LightGroup", "Room", "Entertainment"}[g] +} + +func (r RoomClasses) String() string { + return [...]string{ + "Living room", + "Kitchen", + "Dining", + "Bedroom", + "Kids bedroom", + "Bathroom", + "Nursery", + "Recreation", + "Office", + "Gym", + "Hallway", + "Toilet", + "Front door", + "Garage", + "Terrace", + "Garden", + "Driveway", + "Carport", + "Other", + }[r] +} + +// ------------------------------------------------------------- +// ~ Private methods +// ------------------------------------------------------------- + +// CreateGroup creates a new hue group. For rooms please use the CreateRoom call since it also needs a class +func (b *Bridge) CreateGroup(name string, groupType GroupType, lights []string) (string, error) { + // perform some checks + if groupType != Lightsource && groupType != LightGroup && groupType != Entertainment { + return "", fmt.Errorf("only Lightsource, LightGroup or Entertainment type groups can be created, to create a room group please use CreateRoom (As of now other groups cannot be created manually)") + } + + groupConfig := &Group{ + LightIDs: lights, + Name: name, + Type: groupType.String(), + } + return b.createGroup(groupConfig) +} + +// CreateRoom creates a new hue room. +func (b *Bridge) CreateRoom(name string, class RoomClasses, lights []string) (string, error) { + groupConfig := &Group{ + LightIDs: lights, + Name: name, + Type: Room.String(), + Class: class.String(), + } + return b.createGroup(groupConfig) +} + +// ------------------------------------------------------------- +// ~ Private methods +// ------------------------------------------------------------- + +func (b *Bridge) createGroup(group *Group) (string, error) { + res, errCreate := b.postToBridge(groupsEndpoint, group) + if errCreate != nil { + return "", errCreate + } + + newGroups, ok := res.([]*GroupCreateResponse) + if ok && len(newGroups) == 1 { + return newGroups[0].Success.ID, nil + } else { + return "", fmt.Errorf("could not create group, bridge did not return new group id") + } +}