tradfri

package module
v0.0.0-...-6fd385a Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: MIT Imports: 9 Imported by: ? modules, 0 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

About

IKEA Trådfri library for go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadRequest         = errors.New("bad request")
	ErrNotFound           = errors.New("not found")
	ErrInvalidCredentials = errors.New("identifier/psk is incorrect")
)

Functions

func Authenticate

func Authenticate(addr, initPSK string) (string, string, error)

Authenticate connects to the given address with the give PSK (which can be found underneath the IKEA TRADFRI Gateway. On a successfull connection we'll return a new identity and PSK which should be used for further access to the gateway.

Types

type AuthenticateReq

type AuthenticateReq struct {
	Identity string `json:"9090"`
}

AuthenticateReq contains the data model that should be sent to the IKEA Trådfri gateway to retrieve a new identifier/PSK pair.

type AuthenticateResp

type AuthenticateResp struct {
	PSK     string `json:"9091"`
	Version string `json:"9029"`
}

AuthenticateResp contains the data model that is returned by the IKEA Trådfri gateway on a successfull authentication.

type Bulb

type Bulb struct {
	JSON []byte

	Info         Info `json:"3"`
	LightControl []struct {
		Color    string `json:"5706"`
		ColorHue int    `json:"5707"`
		ColorSat int    `json:"5708"`
		ColorX   int    `json:"5709"`
		ColorY   int    `json:"5710"`
		Power    int    `json:"5850"`
		Dim      int    `json:"5851"`
		Mireds   int    `json:"5711"`
		Duration int    `json:"5712"`
	} `json:"3311"`
	ApplicationType int    `json:"5750"`
	Name            string `json:"9001"`
	CreatedAt       int    `json:"9002"`
	ID              int    `json:"9003"`
	ReachableState  int    `json:"9019"`
	LastSeen        int    `json:"9020"`
	OTAUpdateState  int    `json:"9054"`
}

Bulb contains the data structure that the Gateway returns when a bulb device is requested.

type ControlOutlet

type ControlOutlet struct {
	JSON []byte

	Info Info `json:"3"`
	Plug struct {
		Power int `json:"5850"`
		Dim   int `json:"5851"`
		ID    int `json:"9003"`
	}
	ApplicationType int    `json:"5750"`
	Name            string `json:"9001"`
	CreatedAt       int    `json:"9002"`
	ID              int    `json:"9003"`
	ReachableState  int    `json:"9019"`
	LastSeen        int    `json:"9020"`
	OTAUpdateState  int    `json:"9054"`
}

type Device

type Device struct {
	JSON []byte

	Info           Info   `json:"3"`
	Name           string `json:"9001"`
	CreatedAt      int    `json:"9002"`
	ID             int    `json:"9003"`
	ReachableState int    `json:"9019"`
	LastSeen       int    `json:"9020"`
}

Device contains the structure of an unknown IKEA Trådfri device.

func (*Device) IsBulb

func (d *Device) IsBulb() bool

IsBulb checks whether or not the device is a bulb or not.

func (*Device) IsControlOutlet

func (d *Device) IsControlOutlet() bool

IsControlOutlet checks whether or not the device is a control outlet or not.

type Gateway

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

Gateway.

func Connect

func Connect(addr, identifier, psk string) (*Gateway, error)

Connect initializes a new connection to the given address with the identifier and psk, if the connection is successful we'll return a new instance of the gateway, if not an error is returned.

func (*Gateway) GetBulb

func (gw *Gateway) GetBulb(id int) (*Bulb, error)

GetBulb gets the bulb with the given ID from the gateway, if the requested device isn't a bulb or if it doesn't exist an error is returned. Otherwise a filled Bulb object is returned.

func (*Gateway) GetControlOutlet

func (gw *Gateway) GetControlOutlet(id int) (*ControlOutlet, error)

GetControlOutlet gets the control outlet with the given id.

func (*Gateway) GetDevice

func (gw *Gateway) GetDevice(id int) (*Device, error)

GetDevice fetches the device with the given ID.

func (*Gateway) ListDeviceIDs

func (gw *Gateway) ListDeviceIDs() ([]int, error)

ListDevices retrieves a list of all the device ids that has been connected to the gateway.

type Info

type Info struct {
	Manufacturer          string `json:"0"`
	Model                 string `json:"1"`
	Serial                string `json:"2"`
	FirmwareVersion       string `json:"3"`
	AvailablePowerSources int    `json:"6"`
	BatteryLevel          int    `json:"9"`
}

Info contains the common structure that all IKEA Trådfri devices share.

Jump to

Keyboard shortcuts

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