hue

package module
v1.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 25 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Go module for Hue API access

GoDoc Build Coverage Go Report Card

Hue API

The Hue Smart Home system provides a REST API to access Hue Smart Home bridges to evaluate and control the connected devices. This library provides the Go wrapper for this API. It is based on the Hue API's OpenAPI specification provided by the OpenHue project.

Versioning

The package main version (major.minor) matches the version of the OpenAPI specification the package version is based on.

License

This project is subject to the the Apache License, Version 2.0. See LICENSE information for details.

Documentation

Overview

generated from api.gen.go

Index

Constants

View Source
const DefaultTimeout time.Duration = 60 * time.Second

DefaultTimeout defines a suitable default for timeout related functions.

Variables

View Source
var ErrBridgeClientFailure = errors.New("bridge client call failure")

ErrBridgeClientFailure indicates a system error while invoking the bridge client.

View Source
var ErrBridgeNotAvailable = errors.New("bridge not available")

ErrBridgeNotAvailable indicates a bridge is currently not available.

View Source
var ErrHueAPIFailure = errors.New("api failure")

ErrHueAPIFailure indicates an API call has failed with an API error.

View Source
var ErrNotAuthenticated = errors.New("not authenticated")

ErrNotAuthenticated indicates bridge access has not yet been authenticated

View Source
var ErrNotAuthorized = errors.New("authorization missing or expired")

ErrNotAuthorized indicates the necessary authorization for remote access is either missing or has expired.

Functions

This section is empty.

Types

type AddressBridgeLocator

type AddressBridgeLocator struct {
	// contains filtered or unexported fields
}

AddressBridgeLocator locates a local bridge via a well-known address.

Use NewAddressBridgeLocator to create a new instance. As this locator is looking at exactly one bridge, a Query call will return not more than one brigde.

func NewAddressBridgeLocator

func NewAddressBridgeLocator(address string) (*AddressBridgeLocator, error)

NewAddressBridgeLocator creates a new AddressBridgeLocator for accessing a local bridge via a well-known address.

Example:

locator, _ := hue.NewAddressBridgeLocator("196.168.1.127")
bridges, _ := locator.Locate(hue.DefaultTimeout)
for _, bridge := range bridges {
	client, _ := bridge.NewClient(new hue.NewLocalAuthenticator(""), hue.DefaultTimeout)
	// make sure linking button is pressed before invoking Authenticate
	hostname, _ := os.Hostnamee()
	deviceType := "MyApp#" + hostname
	generateClientKey := true
	request := hueapi.AuthenticateJSONRequestBody{
		Devicetype:        &deviceType,
		Generateclientkey: &generateClientKey,
	}
	response, _ := client.Authenticate(request)
	if response.response.HTTPResponse.StatusCode == http.StatusOK {
		success := (*rsp.JSON200)[0].Success
		fmt.Println("Bridge id: ", bridge.BridgeId)
		fmt.Println("Username: ", *rspSuccess.Username)
	}
	// Authentication username is automatically picked up by the client. All API calls are now possible.
	getDevicesResponse, _ := client.GetDevices()
}

// If Bridge Id and Username are already known, this can be shortened to

locator, _ := hue.NewAddressBridgeLocator("196.168.1.127")
bridge, _ := locator.Lookup("0123456789ABCDEF", hue.DefaultTimeout)
client, _ := bridge.NewClient(hue.NewLocalAuthenticator("secret username token"), hue.DefaultTimeout)
getDevicesResponse, _ := client.GetDevices()

func (*AddressBridgeLocator) Lookup

func (locator *AddressBridgeLocator) Lookup(bridgeId string, timeout time.Duration) (*Bridge, error)

func (*AddressBridgeLocator) Name

func (locator *AddressBridgeLocator) Name() string

func (*AddressBridgeLocator) NewClient

func (locator *AddressBridgeLocator) NewClient(bridge *Bridge, authenticator BridgeAuthenticator, timeout time.Duration) (BridgeClient, error)

func (*AddressBridgeLocator) Query

func (locator *AddressBridgeLocator) Query(timeout time.Duration) ([]*Bridge, error)

type Bridge

type Bridge struct {
	// Locator refers to the locator instance used to identify this bridge.
	Locator BridgeLocator
	// Name contains the name of the bridge.
	Name string
	// SoftwareVersion contains the version of the bridge SW.
	SoftwareVersion string
	// ApiVersion contains the version of the bridge API.
	ApiVersion string
	// HardwareAddress contains the Hardware (MAC) address of the bridge.
	HardwareAddress net.HardwareAddr
	// BridgeId contains the id of the bridge.
	BridgeId string
	// ReplacesBridgeId contains optionally the id of the bridge replaced by this one.
	ReplacesBridgeId string
	// ModelId contains the id of the bridge model.
	ModelId string
	// Url contains the URL used to access the bridge.
	Url *url.URL
}

Bridge contains the general bridge attributes as well the BridgeLocator instance used to locate this bridge.

func (*Bridge) NewClient

func (bridge *Bridge) NewClient(authenticator BridgeAuthenticator, timeout time.Duration) (BridgeClient, error)

NewClient creates a new BridgeClient suitable for accessing the bridge services.

func (*Bridge) String

func (bridge *Bridge) String() string

String gets the bridge's signature string.

type BridgeAuthenticator added in v0.0.11

type BridgeAuthenticator interface {
	// AuthenticateRequest authenticates the given request.
	AuthenticateRequest(ctx context.Context, req *http.Request) error
	// Authenticated is called with the response of an Authenticate API call and updates this instance's authentication credentials.
	Authenticated(rsp *api.AuthenticateResponse)
	// Authentication returns the user name used to authenticate towards the bridge. Error ErrNotAuthenticated indicates, bridge access
	// has not yet been authenticated.
	Authentication() (string, error)
}

BridgeAuthenticator injects the necessary authentication credentials into an bridge API call.

type BridgeClient added in v0.0.2

type BridgeClient interface {
	MiddlewareClient
	// Authenticate API call
	Authenticate(ctx context.Context, body api.AuthenticateJSONRequestBody) (*api.AuthenticateResponse, error)
	// GetResources API call
	GetResources(ctx context.Context) (*api.GetResourcesResponse, error)
	// GetBehaviorInstances API call
	GetBehaviorInstances(ctx context.Context) (*api.GetBehaviorInstancesResponse, error)
	// GetBehaviorInstance API call
	GetBehaviorInstance(ctx context.Context, behaviorInstanceId string) (*api.GetBehaviorInstanceResponse, error)
	// UpdateBehaviorInstance API call
	UpdateBehaviorInstance(ctx context.Context, behaviorInstanceId string, body api.UpdateBehaviorInstanceJSONRequestBody) (*api.UpdateBehaviorInstanceResponse, error)
	// GetBehaviorScripts API call
	GetBehaviorScripts(ctx context.Context) (*api.GetBehaviorScriptsResponse, error)
	// GetBehaviorScript API call
	GetBehaviorScript(ctx context.Context, behaviorScriptId string) (*api.GetBehaviorScriptResponse, error)
	// UpdateBehaviorScript API call
	UpdateBehaviorScript(ctx context.Context, behaviorScriptId string, body api.UpdateBehaviorScriptJSONRequestBody) (*api.UpdateBehaviorScriptResponse, error)
	// GetBellButtons API call
	GetBellButtons(ctx context.Context) (*api.GetBellButtonsResponse, error)
	// GetBellButton API call
	GetBellButton(ctx context.Context, bellButtonId string) (*api.GetBellButtonResponse, error)
	// UpdateBellButton API call
	UpdateBellButton(ctx context.Context, bellButtonId string, body api.UpdateBellButtonJSONRequestBody) (*api.UpdateBellButtonResponse, error)
	// GetBridges API call
	GetBridges(ctx context.Context) (*api.GetBridgesResponse, error)
	// GetBridge API call
	GetBridge(ctx context.Context, bridgeId string) (*api.GetBridgeResponse, error)
	// UpdateBridge API call
	UpdateBridge(ctx context.Context, bridgeId string, body api.UpdateBridgeJSONRequestBody) (*api.UpdateBridgeResponse, error)
	// GetBridgeHomes API call
	GetBridgeHomes(ctx context.Context) (*api.GetBridgeHomesResponse, error)
	// GetBridgeHome API call
	GetBridgeHome(ctx context.Context, bridgeHomeId string) (*api.GetBridgeHomeResponse, error)
	// GetButtons API call
	GetButtons(ctx context.Context) (*api.GetButtonsResponse, error)
	// GetButton API call
	GetButton(ctx context.Context, buttonId string) (*api.GetButtonResponse, error)
	// UpdateButton API call
	UpdateButton(ctx context.Context, buttonId string, body api.UpdateButtonJSONRequestBody) (*api.UpdateButtonResponse, error)
	// GetCameraMotions API call
	GetCameraMotions(ctx context.Context) (*api.GetCameraMotionsResponse, error)
	// GetCameraMotion API call
	GetCameraMotion(ctx context.Context, cameraMotionId string) (*api.GetCameraMotionResponse, error)
	// UpdateCameraMotion API call
	UpdateCameraMotion(ctx context.Context, cameraMotionId string, body api.UpdateCameraMotionJSONRequestBody) (*api.UpdateCameraMotionResponse, error)
	// GetContacts API call
	GetContacts(ctx context.Context) (*api.GetContactsResponse, error)
	// GetContact API call
	GetContact(ctx context.Context, contactId string) (*api.GetContactResponse, error)
	// UpdateContact API call
	UpdateContact(ctx context.Context, contactId string, body api.UpdateContactJSONRequestBody) (*api.UpdateContactResponse, error)
	// GetConvenienceAreaMotions API call
	GetConvenienceAreaMotions(ctx context.Context) (*api.GetConvenienceAreaMotionsResponse, error)
	// GetConvenienceAreaMotion API call
	GetConvenienceAreaMotion(ctx context.Context, convenienceAreaMotionId string) (*api.GetConvenienceAreaMotionResponse, error)
	// UpdateConvenienceAreaMotion API call
	UpdateConvenienceAreaMotion(ctx context.Context, convenienceAreaMotionId string, body api.UpdateConvenienceAreaMotionJSONRequestBody) (*api.UpdateConvenienceAreaMotionResponse, error)
	// GetDevices API call
	GetDevices(ctx context.Context) (*api.GetDevicesResponse, error)
	// DeleteDevice API call
	DeleteDevice(ctx context.Context, deviceId string) (*api.DeleteDeviceResponse, error)
	// GetDevice API call
	GetDevice(ctx context.Context, deviceId string) (*api.GetDeviceResponse, error)
	// UpdateDevice API call
	UpdateDevice(ctx context.Context, deviceId string, body api.UpdateDeviceJSONRequestBody) (*api.UpdateDeviceResponse, error)
	// GetDevicePowers API call
	GetDevicePowers(ctx context.Context) (*api.GetDevicePowersResponse, error)
	// GetDevicePower API call
	GetDevicePower(ctx context.Context, deviceId string) (*api.GetDevicePowerResponse, error)
	// GetDeviceSoftwareUpdates API call
	GetDeviceSoftwareUpdates(ctx context.Context) (*api.GetDeviceSoftwareUpdatesResponse, error)
	// GetDeviceSoftwareUpdate API call
	GetDeviceSoftwareUpdate(ctx context.Context, deviceSoftwareUpdateId string) (*api.GetDeviceSoftwareUpdateResponse, error)
	// UpdateDeviceSoftwareUpdate API call
	UpdateDeviceSoftwareUpdate(ctx context.Context, deviceSoftwareUpdateId string, body api.UpdateDeviceSoftwareUpdateJSONRequestBody) (*api.UpdateDeviceSoftwareUpdateResponse, error)
	// GetEntertainments API call
	GetEntertainments(ctx context.Context) (*api.GetEntertainmentsResponse, error)
	// GetEntertainment API call
	GetEntertainment(ctx context.Context, entertainmentId string) (*api.GetEntertainmentResponse, error)
	// UpdateEntertainment API call
	UpdateEntertainment(ctx context.Context, entertainmentId string, body api.UpdateEntertainmentJSONRequestBody) (*api.UpdateEntertainmentResponse, error)
	// GetEntertainmentConfigurations API call
	GetEntertainmentConfigurations(ctx context.Context) (*api.GetEntertainmentConfigurationsResponse, error)
	// GetEntertainmentConfiguration API call
	GetEntertainmentConfiguration(ctx context.Context, entertainmentConfigurationId string) (*api.GetEntertainmentConfigurationResponse, error)
	// UpdateEntertainmentConfiguration API call
	UpdateEntertainmentConfiguration(ctx context.Context, entertainmentConfigurationId string, body api.UpdateEntertainmentConfigurationJSONRequestBody) (*api.UpdateEntertainmentConfigurationResponse, error)
	// GetGeofenceClients API call
	GetGeofenceClients(ctx context.Context) (*api.GetGeofenceClientsResponse, error)
	// GetGeofenceClient API call
	GetGeofenceClient(ctx context.Context, geofenceClientId string) (*api.GetGeofenceClientResponse, error)
	// UpdateGeofenceClient API call
	UpdateGeofenceClient(ctx context.Context, geofenceClientId string, body api.UpdateGeofenceClientJSONRequestBody) (*api.UpdateGeofenceClientResponse, error)
	// GetGeolocations API call
	GetGeolocations(ctx context.Context) (*api.GetGeolocationsResponse, error)
	// GetGeolocation API call
	GetGeolocation(ctx context.Context, geolocationId string) (*api.GetGeolocationResponse, error)
	// UpdateGeolocation API call
	UpdateGeolocation(ctx context.Context, geolocationId string, body api.UpdateGeolocationJSONRequestBody) (*api.UpdateGeolocationResponse, error)
	// GetGroupedLights API call
	GetGroupedLights(ctx context.Context) (*api.GetGroupedLightsResponse, error)
	// GetGroupedLight API call
	GetGroupedLight(ctx context.Context, groupedLightId string) (*api.GetGroupedLightResponse, error)
	// UpdateGroupedLight API call
	UpdateGroupedLight(ctx context.Context, groupedLightId string, body api.UpdateGroupedLightJSONRequestBody) (*api.UpdateGroupedLightResponse, error)
	// GetGroupedLightLevels API call
	GetGroupedLightLevels(ctx context.Context) (*api.GetGroupedLightLevelsResponse, error)
	// GetGroupedLightLevel API call
	GetGroupedLightLevel(ctx context.Context, groupedLightLevelId string) (*api.GetGroupedLightLevelResponse, error)
	// UpdateGroupedLightLevel API call
	UpdateGroupedLightLevel(ctx context.Context, groupedLightLevelId string, body api.UpdateGroupedLightLevelJSONRequestBody) (*api.UpdateGroupedLightLevelResponse, error)
	// GetGroupedMotions API call
	GetGroupedMotions(ctx context.Context) (*api.GetGroupedMotionsResponse, error)
	// GetGroupedMotion API call
	GetGroupedMotion(ctx context.Context, groupedMotionId string) (*api.GetGroupedMotionResponse, error)
	// UpdateGroupedMotion API call
	UpdateGroupedMotion(ctx context.Context, groupedMotionId string, body api.UpdateGroupedMotionJSONRequestBody) (*api.UpdateGroupedMotionResponse, error)
	// GetHomekits API call
	GetHomekits(ctx context.Context) (*api.GetHomekitsResponse, error)
	// GetHomekit API call
	GetHomekit(ctx context.Context, homekitId string) (*api.GetHomekitResponse, error)
	// UpdateHomekit API call
	UpdateHomekit(ctx context.Context, homekitId string, body api.UpdateHomekitJSONRequestBody) (*api.UpdateHomekitResponse, error)
	// GetLights API call
	GetLights(ctx context.Context) (*api.GetLightsResponse, error)
	// GetLight API call
	GetLight(ctx context.Context, lightId string) (*api.GetLightResponse, error)
	// UpdateLight API call
	UpdateLight(ctx context.Context, lightId string, body api.UpdateLightJSONRequestBody) (*api.UpdateLightResponse, error)
	// GetLightLevels API call
	GetLightLevels(ctx context.Context) (*api.GetLightLevelsResponse, error)
	// GetLightLevel API call
	GetLightLevel(ctx context.Context, lightId string) (*api.GetLightLevelResponse, error)
	// UpdateLightLevel API call
	UpdateLightLevel(ctx context.Context, lightId string, body api.UpdateLightLevelJSONRequestBody) (*api.UpdateLightLevelResponse, error)
	// GetMatters API call
	GetMatters(ctx context.Context) (*api.GetMattersResponse, error)
	// GetMatter API call
	GetMatter(ctx context.Context, matterId string) (*api.GetMatterResponse, error)
	// UpdateMatter API call
	UpdateMatter(ctx context.Context, matterId string, body api.UpdateMatterJSONRequestBody) (*api.UpdateMatterResponse, error)
	// GetMatterFabrics API call
	GetMatterFabrics(ctx context.Context) (*api.GetMatterFabricsResponse, error)
	// GetMatterFabric API call
	GetMatterFabric(ctx context.Context, matterFabricId string) (*api.GetMatterFabricResponse, error)
	// UpdateMatterFabric API call
	UpdateMatterFabric(ctx context.Context, matterFabricId string, body api.UpdateMatterFabricJSONRequestBody) (*api.UpdateMatterFabricResponse, error)
	// GetMotionSensors API call
	GetMotionSensors(ctx context.Context) (*api.GetMotionSensorsResponse, error)
	// GetMotionSensor API call
	GetMotionSensor(ctx context.Context, motionId string) (*api.GetMotionSensorResponse, error)
	// UpdateMotionSensor API call
	UpdateMotionSensor(ctx context.Context, motionId string, body api.UpdateMotionSensorJSONRequestBody) (*api.UpdateMotionSensorResponse, error)
	// GetMotionAreaCandidates API call
	GetMotionAreaCandidates(ctx context.Context) (*api.GetMotionAreaCandidatesResponse, error)
	// GetMotionAreaCandidate API call
	GetMotionAreaCandidate(ctx context.Context, motionAreaCandidateId string) (*api.GetMotionAreaCandidateResponse, error)
	// UpdateMotionAreaCandidate API call
	UpdateMotionAreaCandidate(ctx context.Context, motionAreaCandidateId string, body api.UpdateMotionAreaCandidateJSONRequestBody) (*api.UpdateMotionAreaCandidateResponse, error)
	// GetMotionAreaConfigurations API call
	GetMotionAreaConfigurations(ctx context.Context) (*api.GetMotionAreaConfigurationsResponse, error)
	// GetMotionAreaConfiguration API call
	GetMotionAreaConfiguration(ctx context.Context, motionAreaConfigurationId string) (*api.GetMotionAreaConfigurationResponse, error)
	// UpdateMotionAreaConfiguration API call
	UpdateMotionAreaConfiguration(ctx context.Context, motionAreaConfigurationId string, body api.UpdateMotionAreaConfigurationJSONRequestBody) (*api.UpdateMotionAreaConfigurationResponse, error)
	// GetRelativeRotaries API call
	GetRelativeRotaries(ctx context.Context) (*api.GetRelativeRotariesResponse, error)
	// GetRelativeRotary API call
	GetRelativeRotary(ctx context.Context, relativeRotaryId string) (*api.GetRelativeRotaryResponse, error)
	// UpdateRelativeRotary API call
	UpdateRelativeRotary(ctx context.Context, relativeRotaryId string, body api.UpdateRelativeRotaryJSONRequestBody) (*api.UpdateRelativeRotaryResponse, error)
	// GetRooms API call
	GetRooms(ctx context.Context) (*api.GetRoomsResponse, error)
	// CreateRoom API call
	CreateRoom(ctx context.Context, body api.CreateRoomJSONRequestBody) (*api.CreateRoomResponse, error)
	// DeleteRoom API call
	DeleteRoom(ctx context.Context, roomId string) (*api.DeleteRoomResponse, error)
	// GetRoom API call
	GetRoom(ctx context.Context, roomId string) (*api.GetRoomResponse, error)
	// UpdateRoom API call
	UpdateRoom(ctx context.Context, roomId string, body api.UpdateRoomJSONRequestBody) (*api.UpdateRoomResponse, error)
	// GetScenes API call
	GetScenes(ctx context.Context) (*api.GetScenesResponse, error)
	// CreateScene API call
	CreateScene(ctx context.Context, body api.CreateSceneJSONRequestBody) (*api.CreateSceneResponse, error)
	// DeleteScene API call
	DeleteScene(ctx context.Context, sceneId string) (*api.DeleteSceneResponse, error)
	// GetScene API call
	GetScene(ctx context.Context, sceneId string) (*api.GetSceneResponse, error)
	// UpdateScene API call
	UpdateScene(ctx context.Context, sceneId string, body api.UpdateSceneJSONRequestBody) (*api.UpdateSceneResponse, error)
	// GetSecurityAreaMotions API call
	GetSecurityAreaMotions(ctx context.Context) (*api.GetSecurityAreaMotionsResponse, error)
	// GetSecurityAreaMotion API call
	GetSecurityAreaMotion(ctx context.Context, securityAreaMotionId string) (*api.GetSecurityAreaMotionResponse, error)
	// UpdateSecurityAreaMotion API call
	UpdateSecurityAreaMotion(ctx context.Context, securityAreaMotionId string, body api.UpdateSecurityAreaMotionJSONRequestBody) (*api.UpdateSecurityAreaMotionResponse, error)
	// GetServiceGroups API call
	GetServiceGroups(ctx context.Context) (*api.GetServiceGroupsResponse, error)
	// GetServiceGroup API call
	GetServiceGroup(ctx context.Context, serviceGroupId string) (*api.GetServiceGroupResponse, error)
	// UpdateServiceGroup API call
	UpdateServiceGroup(ctx context.Context, serviceGroupId string, body api.UpdateServiceGroupJSONRequestBody) (*api.UpdateServiceGroupResponse, error)
	// GetSmartScenes API call
	GetSmartScenes(ctx context.Context) (*api.GetSmartScenesResponse, error)
	// CreateSmartScene API call
	CreateSmartScene(ctx context.Context, body api.CreateSmartSceneJSONRequestBody) (*api.CreateSmartSceneResponse, error)
	// DeleteSmartScene API call
	DeleteSmartScene(ctx context.Context, sceneId string) (*api.DeleteSmartSceneResponse, error)
	// GetSmartScene API call
	GetSmartScene(ctx context.Context, sceneId string) (*api.GetSmartSceneResponse, error)
	// UpdateSmartScene API call
	UpdateSmartScene(ctx context.Context, sceneId string, body api.UpdateSmartSceneJSONRequestBody) (*api.UpdateSmartSceneResponse, error)
	// GetSpeakers API call
	GetSpeakers(ctx context.Context) (*api.GetSpeakersResponse, error)
	// GetSpeaker API call
	GetSpeaker(ctx context.Context, speakerId string) (*api.GetSpeakerResponse, error)
	// UpdateSpeaker API call
	UpdateSpeaker(ctx context.Context, speakerId string, body api.UpdateSpeakerJSONRequestBody) (*api.UpdateSpeakerResponse, error)
	// GetTampers API call
	GetTampers(ctx context.Context) (*api.GetTampersResponse, error)
	// GetTamper API call
	GetTamper(ctx context.Context, tamperId string) (*api.GetTamperResponse, error)
	// UpdateTamper API call
	UpdateTamper(ctx context.Context, tamperId string, body api.UpdateTamperJSONRequestBody) (*api.UpdateTamperResponse, error)
	// GetTemperatures API call
	GetTemperatures(ctx context.Context) (*api.GetTemperaturesResponse, error)
	// GetTemperature API call
	GetTemperature(ctx context.Context, temperatureId string) (*api.GetTemperatureResponse, error)
	// UpdateTemperature API call
	UpdateTemperature(ctx context.Context, temperatureId string, body api.UpdateTemperatureJSONRequestBody) (*api.UpdateTemperatureResponse, error)
	// GetWifiConnectivities API call
	GetWifiConnectivities(ctx context.Context) (*api.GetWifiConnectivitiesResponse, error)
	// GetWifiConnectivity API call
	GetWifiConnectivity(ctx context.Context, wifiConnectivityId string) (*api.GetWifiConnectivityResponse, error)
	// UpdateWifiConnectivity API call
	UpdateWifiConnectivity(ctx context.Context, wifiConnectivityId string, body api.UpdateWifiConnectivityJSONRequestBody) (*api.UpdateWifiConnectivityResponse, error)
	// GetZgpConnectivities API call
	GetZgpConnectivities(ctx context.Context) (*api.GetZgpConnectivitiesResponse, error)
	// GetZgpConnectivity API call
	GetZgpConnectivity(ctx context.Context, zgpConnectivityId string) (*api.GetZgpConnectivityResponse, error)
	// UpdateZgpConnectivity API call
	UpdateZgpConnectivity(ctx context.Context, zgpConnectivityId string, body api.UpdateZgpConnectivityJSONRequestBody) (*api.UpdateZgpConnectivityResponse, error)
	// GetZigbeeConnectivities API call
	GetZigbeeConnectivities(ctx context.Context) (*api.GetZigbeeConnectivitiesResponse, error)
	// GetZigbeeConnectivity API call
	GetZigbeeConnectivity(ctx context.Context, zigbeeConnectivityId string) (*api.GetZigbeeConnectivityResponse, error)
	// UpdateZigbeeConnectivity API call
	UpdateZigbeeConnectivity(ctx context.Context, zigbeeConnectivityId string, body api.UpdateZigbeeConnectivityJSONRequestBody) (*api.UpdateZigbeeConnectivityResponse, error)
	// GetZigbeeDeviceDiscoveries API call
	GetZigbeeDeviceDiscoveries(ctx context.Context) (*api.GetZigbeeDeviceDiscoveriesResponse, error)
	// GetZigbeeDeviceDiscovery API call
	GetZigbeeDeviceDiscovery(ctx context.Context, zigbeeDeviceDiscoveryId string) (*api.GetZigbeeDeviceDiscoveryResponse, error)
	// UpdateZigbeeDeviceDiscovery API call
	UpdateZigbeeDeviceDiscovery(ctx context.Context, zigbeeDeviceDiscoveryId string, body api.UpdateZigbeeDeviceDiscoveryJSONRequestBody) (*api.UpdateZigbeeDeviceDiscoveryResponse, error)
	// GetZones API call
	GetZones(ctx context.Context) (*api.GetZonesResponse, error)
	// CreateZone API call
	CreateZone(ctx context.Context, body api.CreateZoneJSONRequestBody) (*api.CreateZoneResponse, error)
	// DeleteZone API call
	DeleteZone(ctx context.Context, zoneId string) (*api.DeleteZoneResponse, error)
	// GetZone API call
	GetZone(ctx context.Context, zoneId string) (*api.GetZoneResponse, error)
	// UpdateZone API call
	UpdateZone(ctx context.Context, zoneId string, body api.UpdateZoneJSONRequestBody) (*api.UpdateZoneResponse, error)
	// GetEventStream API call
	GetEventStream(ctx context.Context, params *api.GetEventStreamParams) (*api.GetEventStreamResponse, error)
}

BridgeClient provides the Hue API functions provided by a bridge.

type BridgeLocator

type BridgeLocator interface {
	// Name gets the name of the locator.
	Name() string
	// Query locates all accessible bridges.
	//
	// An empty collection is returned, in case no bridge could be located.
	Query(timeout time.Duration) ([]*Bridge, error)
	// Lookup locates the bridge for the given bridge id.
	//
	// An error is returned in case the bridge is not available.
	Lookup(bridgeId string, timeout time.Duration) (*Bridge, error)
	// NewClient create a new bridge client for accessing the given bridge's services.
	NewClient(bridge *Bridge, authenticator BridgeAuthenticator, timeout time.Duration) (BridgeClient, error)
}

BridgeLocator provides the necessary functions to identify and access bridge instances.

type CloudBridgeLocator

type CloudBridgeLocator struct {
	// DiscoveryEndpointUrl defines the discovery endpoint URL to use. This URL defaults to https://discovery.meethue.com and may be
	// overwritten for local testing.
	DiscoveryEndpointUrl *url.URL
	// TlsConfig defines the TLS configuration to use for accessing the endpoint URL. If nil, the standard options are used.
	TlsConfig *tls.Config
	// contains filtered or unexported fields
}

CloudBridgeLocator locates local bridges via the Hue Cloud's Discovery endpoint.

Use NewCloudBridgeLocator to create a new instance.

func NewCloudBridgeLocator

func NewCloudBridgeLocator() *CloudBridgeLocator

NewCloudBridgeLocator creates a new CloudBridgeLocator for discovering local bridges via the Hue Cloud's Discovery endpoint.

Only bridges registered in the cloud are locatable via this BridgeLocator.

Example:

locator := hue.NewCloudBridgeLocator()
bridges, _ := locator.Locate(hue.DefaultTimeout)
for _, bridge := range bridges {
	client, _ := bridge.NewClient(new hue.NewLocalAuthenticator(""), hue.DefaultTimeout)
	// make sure linking button is pressed before invoking Authenticate
	hostname, _ := os.Hostnamee()
	deviceType := "MyApp#" + hostname
	generateClientKey := true
	request := hueapi.AuthenticateJSONRequestBody{
		Devicetype:        &deviceType,
		Generateclientkey: &generateClientKey,
	}
	response, _ := client.Authenticate(request)
	if response.response.HTTPResponse.StatusCode == http.StatusOK {
		success := (*rsp.JSON200)[0].Success
		fmt.Println("Bridge id: ", bridge.BridgeId)
		fmt.Println("Username: ", *rspSuccess.Username)
	}
	// Authentication username is automatically picked up by the client. All API calls are now possible.
	getDevicesResponse, _ := client.GetDevices()
}

// If Bridge Id and Username are already known, this can be shortened to

locator := hue.NewCloudBridgeLocator()
bridge, _ := locator.Lookup("0123456789ABCDEF", hue.DefaultTimeout)
client, _ := bridge.NewClient(hue.NewLocalAuthenticator("secret username token"), hue.DefaultTimeout)
getDevicesResponse, _ := client.GetDevices()

func (*CloudBridgeLocator) Lookup

func (locator *CloudBridgeLocator) Lookup(bridgeId string, timeout time.Duration) (*Bridge, error)

func (*CloudBridgeLocator) Name

func (locator *CloudBridgeLocator) Name() string

func (*CloudBridgeLocator) NewClient

func (locator *CloudBridgeLocator) NewClient(bridge *Bridge, authenticator BridgeAuthenticator, timeout time.Duration) (BridgeClient, error)

func (*CloudBridgeLocator) Query

func (locator *CloudBridgeLocator) Query(timeout time.Duration) ([]*Bridge, error)

type LocalBridgeAuthenticator added in v0.0.11

type LocalBridgeAuthenticator struct {
	// ClientKey contains the client key returned by a successful Authenticate API call. This attribute is not required
	// for the actual authentication. After a successful Authenticate API call it is provied for informational purposes.
	ClientKey string
	// UserName contains used to authenticate towards a bridge. This user name must be previously been created via a successful [Authenticate] API call.
	//
	// [Authenticate]: https://developers.meethue.com/develop/hue-api/7-configuration-api/#create-user
	UserName string
	// contains filtered or unexported fields
}

LocalBridgeAuthenticator contains the necessary attributes to authenticate towards a local bridge.

func NewLocalBridgeAuthenticator added in v0.0.11

func NewLocalBridgeAuthenticator(userName string) *LocalBridgeAuthenticator

NewLocalBridgeAuthenticator creates a new LocalBridgeAuthenticator suitable for authenticating towards a local bridge.

The user name must be empty or previously been created via a successful Authenticate API call. Everytime a successful Authenticate API call is performed, the user name will be overwritten by the returned user name.

func (*LocalBridgeAuthenticator) AuthenticateRequest added in v0.0.11

func (authenticator *LocalBridgeAuthenticator) AuthenticateRequest(ctx context.Context, req *http.Request) error

func (*LocalBridgeAuthenticator) Authenticated added in v0.0.11

func (authenticator *LocalBridgeAuthenticator) Authenticated(rsp *api.AuthenticateResponse)

func (*LocalBridgeAuthenticator) Authentication added in v0.0.13

func (authenticator *LocalBridgeAuthenticator) Authentication() (string, error)

type MdnsBridgeLocator

type MdnsBridgeLocator struct {
	// Limit defines the maxmimum number of bridges to return during a [BridgeLocator.Query] call. 0 means no limit.
	// As mDNS is working asynchronously, a query normally continues until the given timeout is reached. If a limit is
	// set, a query is complete as soon as the limit is reached.
	Limit int
	// contains filtered or unexported fields
}

MdnsBridgeLocator locates local bridges via via Multicast DNS (mDNS).

Use NewMDNSBridgeLocator to create a new instance.

func NewMDNSBridgeLocator

func NewMDNSBridgeLocator() *MdnsBridgeLocator

NewMDNSBridgeLocator creates a new MdnsBridgeLocator for discovering bridges via Multicast DNS (mDNS).

Example:

locator := NewMDNSBridgeLocator()
bridges, _ := locator.Locate(hue.DefaultTimeout)
for _, bridge := range bridges {
	client, _ := bridge.NewClient(new hue.NewLocalAuthenticator(""), hue.DefaultTimeout)
	// make sure linking button is pressed before invoking Authenticate
	hostname, _ := os.Hostnamee()
	deviceType := "MyApp#" + hostname
	generateClientKey := true
	request := hueapi.AuthenticateJSONRequestBody{
		Devicetype:        &deviceType,
		Generateclientkey: &generateClientKey,
	}
	response, _ := client.Authenticate(request)
	if response.response.HTTPResponse.StatusCode == http.StatusOK {
		success := (*rsp.JSON200)[0].Success
		fmt.Println("Bridge id: ", bridge.BridgeId)
		fmt.Println("Username: ", *rspSuccess.Username)
	}
	// Authentication username is automatically picked up by the client. All API calls are now possible.
	getDevicesResponse, _ := client.GetDevices()
}

// If Bridge Id and Username are already known, this can be shortened to

locator := hue.NewMDNSBridgeLocator()
bridge, _ := locator.Lookup("0123456789ABCDEF", hue.DefaultTimeout)
client, _ := bridge.NewClient(hue.NewLocalAuthenticator("secret username token"), hue.DefaultTimeout)
getDevicesResponse, _ := client.GetDevices()

func (*MdnsBridgeLocator) Lookup

func (locator *MdnsBridgeLocator) Lookup(bridgeId string, timeout time.Duration) (*Bridge, error)

func (*MdnsBridgeLocator) Name

func (locator *MdnsBridgeLocator) Name() string

func (*MdnsBridgeLocator) NewClient

func (locator *MdnsBridgeLocator) NewClient(bridge *Bridge, authenticator BridgeAuthenticator, timeout time.Duration) (BridgeClient, error)

func (*MdnsBridgeLocator) Query

func (locator *MdnsBridgeLocator) Query(timeout time.Duration) ([]*Bridge, error)

type MiddlewareClient added in v1.1.0

type MiddlewareClient interface {
	// Bridge gets the bridge instance this client accesses.
	Bridge() *Bridge
	// Url gets URL used to access the bridge services.
	Url() *url.URL
	// HttpClient gets the underlying http client used to access the bridge.
	HttpClient() *http.Client
}

type RemoteBridgeAuthenticator added in v0.0.11

type RemoteBridgeAuthenticator struct {
	ClientKey string
	UserName  string
	// contains filtered or unexported fields
}

RemoteBridgeAuthenticator is used to authenticate towards a remote bridge.

func NewRemoteBridgeAuthenticator added in v0.0.11

func NewRemoteBridgeAuthenticator(remoteSession RemoteSession, userName string) *RemoteBridgeAuthenticator

NewRemoteBridgeAuthenticator creates a new RemoteBridgeAuthenticator suitable for authenticating towards a remote bridge.

The user name must be previously been created via a successful Authenticate API call. In difference to a local Authenticate calls, where the bridge's link button is pressed physically to acknowledge acccess, the remote variant is acknowledged by invoking RemoteBridgeAuthenticator.EnableLinking prior to the Authenticate API call.

The given RemoteSession argument represents the authorization to use for accessing the Cloud API. The RemoteBridgeLocator used to locate the remote bridge and authorize the remote access provides this RemoteSession.

The user name must be empty or previously been created via a successful Authenticate API call. Everytime a successful Authenticate API call is performed, the user name will be overwritten by the returned user name.

func (*RemoteBridgeAuthenticator) AuthenticateRequest added in v0.0.11

func (authenticator *RemoteBridgeAuthenticator) AuthenticateRequest(ctx context.Context, req *http.Request) error

func (*RemoteBridgeAuthenticator) Authenticated added in v0.0.11

func (authenticator *RemoteBridgeAuthenticator) Authenticated(rsp *api.AuthenticateResponse)

func (*RemoteBridgeAuthenticator) Authentication added in v0.0.13

func (authenticator *RemoteBridgeAuthenticator) Authentication() (string, error)

func (*RemoteBridgeAuthenticator) Authorization added in v0.0.20

func (authenticator *RemoteBridgeAuthenticator) Authorization() (string, error)

func (*RemoteBridgeAuthenticator) EnableLinking added in v0.0.11

func (authenticator *RemoteBridgeAuthenticator) EnableLinking(bridge *Bridge) error

EnableLinking must be called prior to a Authenticate API call to acknoledge the user registration.

type RemoteBridgeLocator

type RemoteBridgeLocator struct {
	// EndpointUrl defines the [Cloud API] endpoint to use. This URL defaults to https://api.meethue.com and may be
	// overwritten for local testing.
	//
	// [Cloud API]: https://developers.meethue.com/develop/hue-api/remote-authentication-oauth/
	EndpointUrl *url.URL
	// TlsConfig defines the TLS configuration to use for accessing the endpoint URL. If nil, the standard options are used.
	TlsConfig *tls.Config
	// ClientId defines the client id of the [Remote Hue API app] to use for remote access.
	//
	// [Remote Hue API app]: https://developers.meethue.com/my-apps/
	ClientId string
	// ClientSecret defines the client secret of the [Remote Hue API app] to use for remote access.
	//
	// [Remote Hue API app]: https://developers.meethue.com/my-apps/
	ClientSecret string
	// ReferrerUrl defines the URL to redirect to after an authorization workflow has been completed. The default value nil
	// disables the redirect.
	ReferrerUrl *url.URL
	// contains filtered or unexported fields
}

RemoteBridgeLocator locates a remote bridge via the Hue Cloud API.

Use NewRemoteBridgeLocator to create a new instance.

func NewRemoteBridgeLocator

func NewRemoteBridgeLocator(clientId string, clientSecret string, redirectUrl *url.URL, tokenFile string) (*RemoteBridgeLocator, error)

NewRemoteBridgeLocator creates a new RemoteBridgeLocator for discovering a remote bridge via the Hue Cloud API.

The given client id and secret are obtaining a Hue developer account and registering a Remote Hue API app. The redirect URL must match the callback URL registered during app creation. The RemoteSession associated with the newly created locator is listening on this URL to receive the authorization credentials.

If redirect URL is nil, a localhost based URL is created dynamically. Such dynamic redirect URLs are suitable for local testing only.

If tokenFile is not empty, it must point to a file for storing authorization credentials. Such credentials are automatically restored during next start avoiding the need for a new interactive authorization workflow (unless the stored credentials have expired since last use).

Example:

clientId := "..." // as defined in app registration
clientSecret := "..." // as defined in app registration
redirectUrl, _ := url.Parse("http://127.0.0.1:9123/authorized") // as defined in app registration
locator, _ := hue.NewRemoteBridgeLocator(clientId, clientSecret, redirectUrl, "token.json")
fmt.Println("Start authorization workflow in browser via: ", locator.AuthCodeURL())
// After a successful authorization workflow token.json contains a valid token for remote access
bridges, _ := locator.Locate(hue.DefaultTimeout)
for _, bridge := range bridges {
	authenticator := new hue.NewremoteAuthenticator(locator, "")
	client, _ := bridge.NewClient(authenticator, hue.DefaultTimeout)
	authenticator.EnableLinking()
	hostname, _ := os.Hostnamee()
	deviceType := "MyApp#" + hostname
	generateClientKey := true
	request := api.AuthenticateJSONRequestBody{
		Devicetype:        &deviceType,
		Generateclientkey: &generateClientKey,
	}
	response, _ := client.Authenticate(request)
	if response.response.HTTPResponse.StatusCode == http.StatusOK {
		success := (*rsp.JSON200)[0].Success
		fmt.Println("Bridge id: ", bridge.BridgeId)
		fmt.Println("Username: ", *rspSuccess.Username)
	}
	// Authentication username is automatically picked up by the client. All API calls are now possible.
	getDevicesResponse, _ := client.GetDevices()
}

// If Bridge Id and Username are already known and a valid token file is in place, this can be shortened to

locator, _ := hue.NewRemoteBridgeLocator(clientId, clientSecret, redirectUrl, "token.json")
bridge, _ := locator.Lookup("0123456789ABCDEF", hue.DefaultTimeout)
client, _ := bridge.NewClient(hue.NewRemoteAuthenticator(locator, "secret username token"), hue.DefaultTimeout)
getDevicesResponse, _ := client.GetDevices()

func (*RemoteBridgeLocator) AuthCodeURL added in v0.0.11

func (locator *RemoteBridgeLocator) AuthCodeURL() string

func (*RemoteBridgeLocator) Authorization added in v0.0.20

func (locator *RemoteBridgeLocator) Authorization() (string, error)

func (*RemoteBridgeLocator) Authorized added in v0.0.11

func (locator *RemoteBridgeLocator) Authorized() bool

func (*RemoteBridgeLocator) Lookup

func (locator *RemoteBridgeLocator) Lookup(bridgeId string, timeout time.Duration) (*Bridge, error)

func (*RemoteBridgeLocator) Name

func (locator *RemoteBridgeLocator) Name() string

func (*RemoteBridgeLocator) NewClient

func (locator *RemoteBridgeLocator) NewClient(bridge *Bridge, authenticator BridgeAuthenticator, timeout time.Duration) (BridgeClient, error)

func (*RemoteBridgeLocator) Query

func (locator *RemoteBridgeLocator) Query(timeout time.Duration) ([]*Bridge, error)

type RemoteSession added in v0.0.11

type RemoteSession interface {
	// Authorized determines whether a remote authorization has been completed and is still valid (not expired).
	Authorized() bool
	// AuthorizationToken gets the current authorization token. The returned string can be stored to file
	// and used to restore a restoration during a call to [NewRemoteBridgeLocator]. [ErrNotAuthorized] is returned
	// in case there is not valid authorization in place.
	Authorization() (string, error)
	// AuthCodeURL gets the URL to invoke to start the [authorization workflow]. The workflow requires manual
	// interacation (e.g. login into device account and acknowledging device access) and therefore must executed
	// within a browser.
	//
	// [authorization workflow]: https://developers.meethue.com/develop/hue-api/remote-authentication-oauth/
	AuthCodeURL() string
	// contains filtered or unexported methods
}

RemoteSession represents the necessary remote authorization required to access a bridge remotely.

Directories

Path Synopsis
Package api provides primitives to interact with the openapi HTTP API.
Package api provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址