Documentation
¶
Index ¶
- Variables
- func GetToken(ctx context.Context, address string) (string, error)
- func SetLevel(ctx context.Context, hubAddress, zoneAddress, token string, level int32) error
- func TurnOff(ctx context.Context, hubAddress, zoneAddress, token string) error
- func TurnOn(ctx context.Context, hubAddress, zoneAddress, token string) error
- func VerifyConnection(ctx context.Context, address, token string) error
- type Device
- type GIP
- type Room
- type ScanResponse
Constants ¶
This section is empty.
Variables ¶
ErrUnauthorized represents an error when the user tried to call an API but were not authorized to do so. This can occur if you try to call GetToken without pressing the "sync" button on your physical hub or if you try to make API calls without a valid token
Functions ¶
func GetToken ¶
GetToken returns the security token required to make any API calls to the ConnectedByTCP hub. In order for this function to succeed, you must press the physical "sync" button on the hub before calling this function. Calling this function without first pressing the sync button will cause a ErrUnauthorized error to be returned. The address field should be in the format "https://192.168.0.23" for example.
The context.Context instance is passed to the network code, so you can use it to set timeouts for the request. If you want to set a timeout, just call context.WithTimeout() and pass in the result. IF you want a blank context, just use context.TOOD()
IMPORTANT: It seems that every time you get a token the previous token becomes invalid, so you will need to update wherever you are using it after calling this function. Also the official app also generates tokens if you scan so things may stop working if you use the official app after getting these tokens, if so then you will need to generate a new one
func VerifyConnection ¶
VerifyConnection connects to the hub and tries to perform an API call to verify that the supplied parameters are correct. If no error is returned then the call was successful and the address and token are valid values
Types ¶
type Device ¶
type Device struct {
DID string `xml:"did"`
Known float64 `xml:"known"`
// 0 == off, 1 == on
State float64 `xml:"state"`
// Intensity level of the bulb
Level float64 `xml:"level"`
Offline float64 `xml:"offline"`
Node float64 `xml:"node"`
Port float64 `xml:"port"`
NodeType float64 `xml:"nidetype"`
Name string `xml:"name"`
ColorID float64 `xml:"colorid"`
Type string `xml:"type"`
RangeMin float64 `xml:"rangemin"`
Power float64 `xml:"power"`
PowerAvg float64 `xml:"poweravg"`
Energy float64 `xml:"energy"`
Score float64 `xml:"score"`
ProductID float64 `xml:"productid"`
ProdBrand string `xml:"prodbrand"`
ProdModel string `xml:"prodmodel"`
ProdType string `xml:"prodtype"`
ProdTypeID float64 `xml:"prodtypeid"`
ClassID float64 `xml:"classid"`
}
Device represents the device information returned by the ConnectedByTCP hub in the response to the RoomGetCarousel call
type GIP ¶
type GIP struct {
Rooms []Room `xml:"gwrcmd>gdata>gip>room"`
}
GIP represents the gip element returned by the ConnectedByTCP hub in response to the RoomGetCarousel call
func RoomGetCarousel ¶
RoomGetCarousel return the room and device information from the ConnectedByTCP hub. Call this to get room and bulb information, such as device IDs, names etc. Address should be in the form "https://192.168.0.23" for example and the token value should be the token you retried from the GetToken function call
type Room ¶
type Room struct {
Name string `xml:"name"`
Description string `xml:"desc"`
Known float64 `xml:"known"`
Type float64 `xml:"type"`
Color string `xml:"color"`
ColorID float64 `xml:"colorid"`
Image string `xml:"img"`
Power float64 `xml:"power"`
PowerAVG float64 `xml:"poweravg"`
Energy float64 `xml:"energy"`
Devices []Device `xml:"device"`
}
Room represents the room information returned by the ConnectedByTCP hub in response to the RoomGetCarousel call
type ScanResponse ¶
type ScanResponse struct {
MaxAge int
SearchType string
DeviceID string
USN string
Location string
Server string
URN string
}
ScanResponse contains information from a device that responded to a scan response
func Scan ¶
func Scan(waitTimeSeconds int) ([]ScanResponse, error)
Scan returns ScanResponse instances for each device found on the network