gosmart

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetEndPointsURI

func GetEndPointsURI(client *http.Client) (string, error)

GetEndPointsURI returns the smartthing endpoints URI. The endpoints URI is the base for all app requests.

func GetToken

func GetToken(tokenFile string, config *oauth2.Config) (*oauth2.Token, error)

GetToken returns the token for the ClientID and Secret specified in config. The function attempts to load the token from tokenFile first, and failing that, starts a full token authentication cycle with SmartThings. If tokenFile is blank, the function uses a default name under the current user's home directory. The token is saved to local disk before being returned to the caller.

This function represents the most common (and possibly convenient) way to retrieve a token for a given ClientID and Secret.

func LoadToken

func LoadToken(fname string) (*oauth2.Token, error)

LoadToken loads the token from a file on disk. If nil is used for filename a default filename user the user's directory is used.

func NewOAuthConfig

func NewOAuthConfig(client, secret string) *oauth2.Config

NewOAuthConfig creates a new oauth2.config structure with the correct parameters to use smartthings.

func SaveToken

func SaveToken(fname string, token *oauth2.Token) error

SaveToken saves the token to a file on disk. If nil is used for filename a default filename user the user's directory is used.

Types

type Attribute

type Attribute struct {
	Name        string
	Description string
	Value       float64
}

type Auth

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

Auth contains the SmartThings authentication related data.

func NewAuth

func NewAuth(port int, config *oauth2.Config) (*Auth, error)

NewAuth creates a new Auth struct

func (*Auth) FetchOAuthToken

func (g *Auth) FetchOAuthToken() (*oauth2.Token, error)

FetchOAuthToken sets up the handler and a local HTTP server and fetches an Oauth token from the smartthings website.

type Sensor

type Sensor struct {
	ID          string
	Name        string
	DisplayName string
	Attributes  []Attribute
}

func GetSensors

func GetSensors(client *http.Client, endpoint string) ([]Sensor, error)

GetSensors returns the list of devices from smartthings using the specified http.client and endpoint URI.

Jump to

Keyboard shortcuts

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