Skip to content

Commit 2d3a731

Browse files
committed
First pass adding v2 API
1 parent 02219d0 commit 2d3a731

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2381
-1
lines changed

cmd/api.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ func init() {
99

1010
type apiCmd struct {
1111
V1 *apiV1Cmd `command:"v1" description:"Interact with v1 of the Hue Bridge API"`
12+
V2 *apiV2Cmd `command:"v2" description:"Interact with v2 (CLIP) of the Hue Bridge API"`
1213
}

cmd/api_v2.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cmd
2+
3+
type apiV2Cmd struct {
4+
BehaviorInstance *apiV2BehaviorInstanceCmd `command:"behavior-instance" description:"API to manage instances of script"`
5+
BehaviorScript *apiV2BehaviorScriptCmd `command:"behavior-script" description:"API to discover available scripts that can be instantiated"`
6+
Bridge *apiV2BridgeCmd `command:"bridge" description:"API to manage the bridge"`
7+
BridgeHome *apiV2BridgeHomeCmd `command:"bridge-home" description:"API to manage bridge homes"`
8+
Button *apiV2ButtonCmd `command:"button" description:"API to manage button services"`
9+
CameraMotion *apiV2CameraMotionCmd `command:"camera-motion" description:"API to manage camera_motion services"`
10+
Contact *apiV2ContactCmd `command:"contact" description:"API to manage contact sensor state"`
11+
Device *apiV2DeviceCmd `command:"device" description:"API to manage devices"`
12+
DevicePower *apiV2DevicePowerCmd `command:"device-power" description:"API to manage device power services"`
13+
DeviceSoftwareUpdate *apiV2DeviceSoftwareUpdateCmd `command:"device-software-update" description:"API to manage device update services"`
14+
Entertainment *apiV2EntertainmentCmd `command:"entertainment" description:"API to manage entertainment services"`
15+
EntertainmentConfiguration *apiV2EntertainmentConfigurationCmd `command:"entertainment-configuration" description:"API to manage entertainment configurations"`
16+
GeofenceClient *apiV2GeofenceClientCmd `command:"geofence-client" description:"API for geofencing functionality"`
17+
Geolocation *apiV2GeolocationCmd `command:"geolocation" description:"API for setting the geolocation"`
18+
GroupedLight *apiV2GroupedLightCmd `command:"grouped-light" description:"API to manage grouped light services"`
19+
GroupedLightLevel *apiV2GroupedLightLevelCmd `command:"grouped-light-level" description:"API to manage grouped light-level services"`
20+
GroupedMotion *apiV2GroupedMotionCmd `command:"grouped-motion" description:"API to manage grouped motion services"`
21+
Homekit *apiV2HomekitCmd `command:"homekit" description:"API to manage homekit service"`
22+
Light *apiV2LightCmd `command:"light" description:"API to manage light services"`
23+
LightLevel *apiV2LightLevelCmd `command:"light-level" description:"API to manage light level services"`
24+
Matter *apiV2MatterCmd `command:"matter" description:"API to manage matter service"`
25+
MatterFabric *apiV2MatterFabricCmd `command:"matter-fabric" description:"API to manage matter fabrics"`
26+
Motion *apiV2MotionCmd `command:"motion" description:"API to manage motion services"`
27+
RelativeRotary *apiV2RelativeRotaryCmd `command:"relative-rotary" description:"API to manage relative rotary services"`
28+
Resource *apiV2ResourceCmd `command:"resource" description:"API to retrieve all resources"`
29+
Room *apiV2RoomCmd `command:"room" description:"API to manage rooms"`
30+
Scene *apiV2SceneCmd `command:"scene" description:"API to manage scenes"`
31+
ServiceGroup *apiV2ServiceGroupCmd `command:"service-group" description:"API to manage service group services"`
32+
SmartScene *apiV2SmartSceneCmd `command:"smart-scene" description:"API to manage smart scenes"`
33+
Tamper *apiV2TamperCmd `command:"tamper" description:"API to manage device tamper state"`
34+
Temperature *apiV2TemperatureCmd `command:"temperature" description:"API to manage temperature services"`
35+
ZgpConnectivity *apiV2ZGPConnectivityCmd `command:"zgp-connectivity" description:"API to manage zgp connectivity services"`
36+
ZigbeeConnectivity *apiV2ZigbeeConnectivityCmd `command:"zigbee-connectivity" description:"API to manage zigbee connectivity services"`
37+
ZigbeeDeviceDiscovery *apiV2ZigbeeDeviceDiscoveryCmd `command:"zigbee-device-discovery" description:"API to manage zigbee device discovery service"`
38+
Zone *apiV2ZoneCmd `command:"zone" description:"API to manage zones"`
39+
}

cmd/api_v2_behaviour_instance.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cmd
2+
3+
import "github.com/dansimau/huecfg/pkg/jsonutil"
4+
5+
type apiV2BehaviorInstanceCmd struct{}
6+
7+
func (c *apiV2BehaviorInstanceCmd) Execute(args []string) error {
8+
huev2 := cmd.getHueAPIV2()
9+
10+
respBytes, err := huev2.GetBehaviorInstances()
11+
if err != nil {
12+
return err
13+
}
14+
15+
return jsonutil.PrintBytes(respBytes)
16+
}

cmd/api_v2_behaviour_script.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cmd
2+
3+
import "github.com/dansimau/huecfg/pkg/jsonutil"
4+
5+
type apiV2BehaviorScriptCmd struct{}
6+
7+
func (c *apiV2BehaviorScriptCmd) Execute(args []string) error {
8+
huev2 := cmd.getHueAPIV2()
9+
10+
respBytes, err := huev2.GetBehaviorScripts()
11+
if err != nil {
12+
return err
13+
}
14+
15+
return jsonutil.PrintBytes(respBytes)
16+
}

cmd/api_v2_bridge.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package cmd
2+
3+
import "github.com/dansimau/huecfg/pkg/jsonutil"
4+
5+
type apiV2BridgeCmd struct {
6+
Get *apiV2BridgeGetCmd `command:"get"`
7+
Put *apiV2BridgePutCmd `command:"put"`
8+
}
9+
10+
type apiV2BridgeGetCmd struct{}
11+
12+
func (c *apiV2BridgeGetCmd) Execute(args []string) error {
13+
huev2 := cmd.getHueAPIV2()
14+
15+
respBytes, err := huev2.GetBridges()
16+
if err != nil {
17+
return err
18+
}
19+
20+
return jsonutil.PrintBytes(respBytes)
21+
}
22+
23+
type apiV2BridgePutCmd struct {
24+
Data string `long:"data" description:"JSON data to send" default:"-"`
25+
26+
Arguments struct {
27+
ID string `description:"ID of the bridge"`
28+
} `positional-args:"true" required:"true" positional-arg-name:"bridge-ID"`
29+
}
30+
31+
func (c *apiV2BridgePutCmd) Execute(args []string) error {
32+
huev2 := cmd.getHueAPIV2()
33+
34+
respBytes, err := huev2.PutBridge(c.Arguments.ID, c.Data)
35+
if err != nil {
36+
return err
37+
}
38+
39+
return jsonutil.PrintBytes(respBytes)
40+
}

cmd/api_v2_bridge_home.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package cmd
2+
3+
import "github.com/dansimau/huecfg/pkg/jsonutil"
4+
5+
type apiV2BridgeHomeCmd struct {
6+
Get *apiV2BridgeHomeGetCmd `command:"get"`
7+
}
8+
9+
type apiV2BridgeHomeGetCmd struct{}
10+
11+
func (c *apiV2BridgeHomeGetCmd) Execute(args []string) error {
12+
huev2 := cmd.getHueAPIV2()
13+
14+
respBytes, err := huev2.GetBridgeHomes()
15+
if err != nil {
16+
return err
17+
}
18+
19+
return jsonutil.PrintBytes(respBytes)
20+
}

cmd/api_v2_button.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package cmd
2+
3+
import "github.com/dansimau/huecfg/pkg/jsonutil"
4+
5+
type apiV2ButtonCmd struct{}
6+
7+
func (c *apiV2ButtonCmd) Execute(args []string) error {
8+
huev2 := cmd.getHueAPIV2()
9+
10+
respBytes, err := huev2.GetButtons()
11+
if err != nil {
12+
return err
13+
}
14+
15+
return jsonutil.PrintBytes(respBytes)
16+
}

cmd/api_v2_camera_motion.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package cmd
2+
3+
import "github.com/dansimau/huecfg/pkg/jsonutil"
4+
5+
type apiV2CameraMotionCmd struct {
6+
Get *apiV2CameraMotionGetCmd `command:"get"`
7+
Put *apiV2CameraMotionPutCmd `command:"put"`
8+
}
9+
10+
type apiV2CameraMotionGetCmd struct {
11+
Arguments struct {
12+
ID string `description:"ID of the camera motion" optional:"true"`
13+
} `positional-args:"true" positional-arg-name:"camera-motion-ID"`
14+
}
15+
16+
func (c *apiV2CameraMotionGetCmd) Execute(args []string) error {
17+
huev2 := cmd.getHueAPIV2()
18+
19+
var respBytes []byte
20+
var err error
21+
22+
if c.Arguments.ID != "" {
23+
respBytes, err = huev2.GetCameraMotion(c.Arguments.ID)
24+
} else {
25+
respBytes, err = huev2.GetCameraMotions()
26+
}
27+
28+
if err != nil {
29+
return err
30+
}
31+
32+
return jsonutil.PrintBytes(respBytes)
33+
}
34+
35+
type apiV2CameraMotionPutCmd struct {
36+
Data string `long:"data" description:"JSON data to send" default:"-"`
37+
38+
Arguments struct {
39+
ID string `description:"ID of the camera motion"`
40+
} `positional-args:"true" required:"true" positional-arg-name:"camera-motion-ID"`
41+
}
42+
43+
func (c *apiV2CameraMotionPutCmd) Execute(args []string) error {
44+
huev2 := cmd.getHueAPIV2()
45+
46+
respBytes, err := huev2.PutCameraMotion(c.Arguments.ID, c.Data)
47+
if err != nil {
48+
return err
49+
}
50+
51+
return jsonutil.PrintBytes(respBytes)
52+
}

cmd/api_v2_contact.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package cmd
2+
3+
import "github.com/dansimau/huecfg/pkg/jsonutil"
4+
5+
type apiV2ContactCmd struct {
6+
Get *apiV2ContactGetCmd `command:"get"`
7+
Put *apiV2ContactPutCmd `command:"put"`
8+
}
9+
10+
type apiV2ContactGetCmd struct {
11+
Arguments struct {
12+
ID string `description:"ID of the contact sensor" optional:"true"`
13+
} `positional-args:"true" positional-arg-name:"contact-ID"`
14+
}
15+
16+
func (c *apiV2ContactGetCmd) Execute(args []string) error {
17+
huev2 := cmd.getHueAPIV2()
18+
19+
var respBytes []byte
20+
var err error
21+
22+
if c.Arguments.ID != "" {
23+
respBytes, err = huev2.GetContact(c.Arguments.ID)
24+
} else {
25+
respBytes, err = huev2.GetContacts()
26+
}
27+
28+
if err != nil {
29+
return err
30+
}
31+
32+
return jsonutil.PrintBytes(respBytes)
33+
}
34+
35+
type apiV2ContactPutCmd struct {
36+
Data string `long:"data" description:"JSON data to send" default:"-"`
37+
38+
Arguments struct {
39+
ID string `description:"ID of the contact sensor"`
40+
} `positional-args:"true" required:"true" positional-arg-name:"contact-ID"`
41+
}
42+
43+
func (c *apiV2ContactPutCmd) Execute(args []string) error {
44+
huev2 := cmd.getHueAPIV2()
45+
46+
respBytes, err := huev2.PutContact(c.Arguments.ID, c.Data)
47+
if err != nil {
48+
return err
49+
}
50+
51+
return jsonutil.PrintBytes(respBytes)
52+
}

cmd/api_v2_device_power.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package cmd
2+
3+
import "github.com/dansimau/huecfg/pkg/jsonutil"
4+
5+
type apiV2DevicePowerCmd struct {
6+
Get *apiV2DevicePowerGetCmd `command:"get"`
7+
Put *apiV2DevicePowerPutCmd `command:"put"`
8+
}
9+
10+
type apiV2DevicePowerGetCmd struct {
11+
Arguments struct {
12+
ID string `description:"ID of the device power" optional:"true"`
13+
} `positional-args:"true" positional-arg-name:"device-power-ID"`
14+
}
15+
16+
func (c *apiV2DevicePowerGetCmd) Execute(args []string) error {
17+
huev2 := cmd.getHueAPIV2()
18+
19+
var respBytes []byte
20+
var err error
21+
22+
if c.Arguments.ID != "" {
23+
respBytes, err = huev2.GetDevicePower(c.Arguments.ID)
24+
} else {
25+
respBytes, err = huev2.GetDevicePowers()
26+
}
27+
28+
if err != nil {
29+
return err
30+
}
31+
32+
return jsonutil.PrintBytes(respBytes)
33+
}
34+
35+
type apiV2DevicePowerPutCmd struct {
36+
Data string `long:"data" description:"JSON data to send" default:"-"`
37+
38+
Arguments struct {
39+
ID string `description:"ID of the device power"`
40+
} `positional-args:"true" required:"true" positional-arg-name:"device-power-ID"`
41+
}
42+
43+
func (c *apiV2DevicePowerPutCmd) Execute(args []string) error {
44+
huev2 := cmd.getHueAPIV2()
45+
46+
respBytes, err := huev2.PutDevicePower(c.Arguments.ID, c.Data)
47+
if err != nil {
48+
return err
49+
}
50+
51+
return jsonutil.PrintBytes(respBytes)
52+
}

cmd/api_v2_device_software_updates.go

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package cmd
2+
3+
import "github.com/dansimau/huecfg/pkg/jsonutil"
4+
5+
type apiV2DeviceSoftwareUpdateCmd struct {
6+
Get *apiV2DeviceSoftwareUpdateGetCmd `command:"get"`
7+
Put *apiV2DeviceSoftwareUpdatePutCmd `command:"put"`
8+
}
9+
10+
type apiV2DeviceSoftwareUpdateGetCmd struct {
11+
Arguments struct {
12+
ID string `description:"ID of the device software update" optional:"true"`
13+
} `positional-args:"true" positional-arg-name:"device-software-update-ID"`
14+
}
15+
16+
func (c *apiV2DeviceSoftwareUpdateGetCmd) Execute(args []string) error {
17+
huev2 := cmd.getHueAPIV2()
18+
19+
var respBytes []byte
20+
var err error
21+
22+
if c.Arguments.ID != "" {
23+
respBytes, err = huev2.GetDeviceSoftwareUpdate(c.Arguments.ID)
24+
} else {
25+
respBytes, err = huev2.GetDeviceSoftwareUpdates()
26+
}
27+
28+
if err != nil {
29+
return err
30+
}
31+
32+
return jsonutil.PrintBytes(respBytes)
33+
}
34+
35+
type apiV2DeviceSoftwareUpdatePutCmd struct {
36+
Data string `long:"data" description:"JSON data to send" default:"-"`
37+
38+
Arguments struct {
39+
ID string `description:"ID of the device software update"`
40+
} `positional-args:"true" required:"true" positional-arg-name:"device-software-update-ID"`
41+
}
42+
43+
func (c *apiV2DeviceSoftwareUpdatePutCmd) Execute(args []string) error {
44+
huev2 := cmd.getHueAPIV2()
45+
46+
respBytes, err := huev2.PutDeviceSoftwareUpdate(c.Arguments.ID, c.Data)
47+
if err != nil {
48+
return err
49+
}
50+
51+
return jsonutil.PrintBytes(respBytes)
52+
}

0 commit comments

Comments
 (0)