kasa

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: MIT Imports: 10 Imported by: 0

README

Kasa Go

Version License

Go library to remotely control TP-Link devices using their cloud web service so they can be controlled from outside the network.

Installation

go get github.com/ivanbeldad/kasa-go

Devices Supported

Device Type
HS100 Smart Plug
HS103 Smart Plug
HS110 Smart Plug
HS200 Smart Light Switch
Smart Plugs
Method Description
GetInfo Get information about the smart plug
TurnOn Turn on the device
TurnOff Turn off the device
SwitchOnOff Change the state of the device
Reboot Power off the device and power on after a few seconds
GetAlias Get the name of the device
ScanAPs Scan near access points and return info about them

Example

api, err := kasa.Connect("tplink@mail.com", "myStrongPassword")
if err != nil {
  log.Fatal(err)
}
hs100, err := api.GetHS100("livingroom")
if err != nil {
  log.Fatal(err)
}
err = hs100.TurnOn()
if err != nil {
  log.Fatal(err)
}
fmt.Print("Living Room turned on successfully!")

License

Kasa Go is open-sourced software licensed under the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AP

type AP struct {
	SSID    string `json:"ssid,omitempty"`
	KeyType int    `json:"key_type,omitempty"`
}

AP Access Point near the device

func (AP) String

func (ap AP) String() (s string)

type API

type API interface {
	GetDevicesInfo() ([]DeviceInfo, error)
	GetHS100(alias string) (HS100, error)
	GetHS103(alias string) (HS103, error)
	GetHS110(alias string) (HS110, error)
	GetHS200(alias string) (HS200, error)
}

API Public interface to get information, devices and interact with them

func Connect

func Connect(username, password string) (API, error)

Connect Create an authenticated API

type DeviceInfo

type DeviceInfo struct {
	SwVer      string  `json:"sw_ver,omitempty"`
	HwVer      string  `json:"hw_ver,omitempty"`
	Type       string  `json:"type,omitempty"`
	Model      string  `json:"model,omitempty"`
	Mac        string  `json:"mac,omitempty"`
	DeviceID   string  `json:"deviceId,omitempty"`
	HwID       string  `json:"hwId,omitempty"`
	FwID       string  `json:"fwId,omitempty"`
	OemID      string  `json:"oemId,omitempty"`
	Alias      string  `json:"alias,omitempty"`
	DeviceName string  `json:"dev_name,omitempty"`
	IconHash   string  `json:"icon_hash,omitempty"`
	ActiveMode string  `json:"active_mode,omitempty"`
	Feature    string  `json:"feature,omitempty"`
	RelayState int     `json:"relay_state,omitempty"`
	OnTime     int     `json:"on_time,omitempty"`
	Updating   int     `json:"updating,omitempty"`
	Rssi       int     `json:"rssi,omitempty"`
	LedOff     int     `json:"led_off,omitempty"`
	Latitude   float64 `json:"latitude,omitempty"`
	Longitude  float64 `json:"longitude,omitempty"`
}

DeviceInfo Get all the information about a device

func (DeviceInfo) String

func (d DeviceInfo) String() string

type HS100

type HS100 SmartPlug

HS100 Allow to interact with the SmartPlug HS100

type HS103 added in v1.1.2

type HS103 SmartPlug

HS103 Allow to interact with the SmartPlug HS103

type HS110

type HS110 SmartPlug

HS110 Allow to interact with the SmartPlug HS110

type HS200

type HS200 SmartPlug

HS200 Allow to interact with the SmartPlug HS200

type SmartPlug

type SmartPlug interface {
	GetAlias() string
	GetInfo() (DeviceInfo, error)
	TurnOn() error
	TurnOff() error
	SwitchOnOff() error
	Reboot() error
	ScanAPs() ([]AP, error)
}

SmartPlug Allow to interact with either the SmartPlug HS100 and HS110

Jump to

Keyboard shortcuts

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