tuya

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

To be updated if new logical devices are created

Index

Constants

View Source
const (
	CodeMsgSet        = 7
	CodeMsgStatus     = 10
	CodeMsgPing       = 9
	CodeMsgAutoStatus = 8
	CodeMsgRefresh    = 18
)

Code for tuya messages

View Source
const (
	SwitchOff          = 0
	SwitchOn           = 1
	SwitchUndetermined = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Appliance

type Appliance struct {
	Version string
	// contains filtered or unexported fields
}

the appliance proxies the hardware device

func (*Appliance) GetDevice

func (d *Appliance) GetDevice() Device

func (*Appliance) MakeBaseMsg

func (d *Appliance) MakeBaseMsg() map[string]interface{}

create base messages

func (*Appliance) ProcessResponse

func (d *Appliance) ProcessResponse(code int, b []byte)

func (*Appliance) RefreshMsg

func (d *Appliance) RefreshMsg() map[string]interface{}

Status message should be encrypted by the version

func (*Appliance) SendCommand

func (d *Appliance) SendCommand(cmd int, jdata interface{}) error

Send message unencrypted

func (*Appliance) SendEncryptedCommand

func (d *Appliance) SendEncryptedCommand(cmd int, jdata interface{}) error

-------------------------------

func (*Appliance) SendEncryptedRefresh

func (d *Appliance) SendEncryptedRefresh(cmd int, jdata interface{}) error

func (*Appliance) SendStatusRequest

func (d *Appliance) SendStatusRequest(cmd int, jdata []byte) error

func (*Appliance) StatusMsg

func (d *Appliance) StatusMsg() []byte

Status message should be encrypted by the version

func (*Appliance) String

func (d *Appliance) String() string

type BaseDevice

type BaseDevice struct {
	sync.Mutex

	App *Appliance
	// contains filtered or unexported fields
}

to be embedded in Device

func (*BaseDevice) Init

func (b *BaseDevice) Init(typ string, a *Appliance, c *configurationData)

BaseDevice initialization to be invoked during configation

func (*BaseDevice) Name

func (b *BaseDevice) Name() string

func (*BaseDevice) Notify

func (b *BaseDevice) Notify(code int, status []byte, d Device)

func (*BaseDevice) Subscribe

func (b *BaseDevice) Subscribe(c SyncChannel) int64

func (*BaseDevice) Type

func (b *BaseDevice) Type() string

Implementation of Device interface provided by BaseDevice

func (*BaseDevice) Unsubscribe

func (b *BaseDevice) Unsubscribe(key int64)

type Device

type Device interface {
	Type() string
	Name() string
	Subscribe(SyncChannel) int64
	Unsubscribe(int64)
	Configure(*Appliance, *configurationData)
	ProcessResponse(int, []byte)
	Init(string, *Appliance, *configurationData)
}

type DeviceManager

type DeviceManager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewDeviceManager

func NewDeviceManager(jdata string) *DeviceManager

func NewDeviceManagerRaw

func NewDeviceManagerRaw() *DeviceManager

func (*DeviceManager) ApplianceCount

func (dm *DeviceManager) ApplianceCount() int

-------------------------------------------

func (*DeviceManager) ApplianceKeys

func (dm *DeviceManager) ApplianceKeys() []string

-------------------------------------------

func (*DeviceManager) Configure

func (dm *DeviceManager) Configure(jdata string)

-------------------------------------------

func (*DeviceManager) DefineDevice

func (dm *DeviceManager) DefineDevice(Name, GwId, Key, Ip, Version string, device Device)

-------------------------------------------

func (*DeviceManager) DeviceKeys

func (dm *DeviceManager) DeviceKeys() []string

-------------------------------------------

func (*DeviceManager) GetAppliance

func (dm *DeviceManager) GetAppliance(key string) (*Appliance, bool)

-------------------------------------------

func (*DeviceManager) GetDevice

func (dm *DeviceManager) GetDevice(key string) (Device, bool)

-------------------------------------------

type ISwitch

type ISwitch struct {
	BaseDevice
	// contains filtered or unexported fields
}

func (*ISwitch) Configure

func (s *ISwitch) Configure(a *Appliance, c *configurationData)

Device implementation

func (*ISwitch) ProcessResponse

func (s *ISwitch) ProcessResponse(code int, data []byte)

func (*ISwitch) Set

func (s *ISwitch) Set(on bool) error

func (*ISwitch) SetN

func (s *ISwitch) SetN(on bool, dps int) error

func (*ISwitch) SetNW

func (s *ISwitch) SetNW(on bool, dps int, delay time.Duration) (bool, error)

func (*ISwitch) SetW

func (s *ISwitch) SetW(on bool, delay time.Duration) (bool, error)

func (*ISwitch) Status

func (s *ISwitch) Status() (bool, error)

func (*ISwitch) StatusW

func (s *ISwitch) StatusW(delay time.Duration) (bool, error)

func (*ISwitch) TuyaGetStatus

func (s *ISwitch) TuyaGetStatus(delay time.Duration) ([]byte, error)

func (*ISwitch) TuyaRefresh

func (s *ISwitch) TuyaRefresh(delay time.Duration) ([]byte, error)

type Switch

type Switch interface {
	Set(bool) error
	SetN(bool, int) error
	SetW(bool, time.Duration) (bool, error)
	SetNW(bool, int, time.Duration) (bool, error)
	Status() (bool, error)
	StatusW(time.Duration) (bool, error)
	TuyaRefresh(time.Duration) ([]byte, error)
	TuyaGetStatus(time.Duration) ([]byte, error)
}

type SyncChannel

type SyncChannel chan SyncMsg

func MakeSyncChannel

func MakeSyncChannel() SyncChannel

type SyncMsg

type SyncMsg struct {
	Code   int
	Status []byte
	Dev    Device
}

Jump to

Keyboard shortcuts

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