tuyable

package
v0.0.0-...-8eec0ff Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BLEConnectTimeout is the timeout for connecting to a BLE device
	BLEConnectTimeout = 25 * time.Second
	// ResponseWaitTimeout is the timeout for waiting for a response from the device
	ResponseWaitTimeout = 15 * time.Second

	// GattMTU is the maximum size of a GATT packet
	// https://developer.tuya.com/en/docs/iot-device-dev/tuya-ble-sdk-user-guide?id=K9h5zc4e5djd9#title-6-MTU
	GattMTU = 20
)
View Source
const (
	ManufacturerID = 0x07D0
)

Variables

View Source
var DiscoverServiceUUID = ble.UUID16(0xa201)

Functions

This section is empty.

Types

type DPType

type DPType byte

DPType represents a type of a data point in the Tuya BLE protocol

const (
	DPTypeRaw    DPType = 0x00
	DPTypeBool   DPType = 0x01
	DPTypeValue  DPType = 0x02
	DPTypeString DPType = 0x03
	DPTypeEnum   DPType = 0x04
	DPTypeBitmap DPType = 0x05
)

func (DPType) String

func (t DPType) String() string

func (DPType) Valid

func (t DPType) Valid() bool

type DataPoint

type DataPoint struct {
	ID    byte
	Type  DPType
	Value interface{}
}

DataPoint represents a device data point

func NewDataPoint

func NewDataPoint(id byte, t DPType, v interface{}) DataPoint

NewDataPoint creates a new DataPoint instance

func ParseDataPoint

func ParseDataPoint(id byte, t DPType, rawValue []byte) (DataPoint, error)

func (*DataPoint) Payload

func (d *DataPoint) Payload() ([]byte, error)

Payload constructs a FUN_SENDER_DP command payload out of the DataPoint

func (*DataPoint) Validate

func (d *DataPoint) Validate() error

Validate validates the DataPoint

type Device

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

Device represents a Tuya BLE device

func NewDevice

func NewDevice(address, name, uuid, deviceID, localKey string, logger *slog.Logger) (*Device, error)

NewDevice creates a new Device instance

func (*Device) Connect

func (d *Device) Connect(ctx context.Context) error

Connect connects to the Tuya BLE device

func (*Device) Disconnect

func (d *Device) Disconnect() error

Disconnect disconnects from the Tuya BLE device

func (*Device) GetAddress

func (d *Device) GetAddress() string

GetAddress returns the device address

func (*Device) GetDatapoint

func (d *Device) GetDatapoint(id byte) (DataPoint, bool)

GetDatapoint returns the requested data point

func (*Device) GetName

func (d *Device) GetName() string

GetName returns the device name

func (*Device) Pair

func (d *Device) Pair() error

Pair initiates the pairing process with the device

func (*Device) SetDatapoint

func (d *Device) SetDatapoint(dp DataPoint) error

SetDatapointValue sets the value of a data point

func (*Device) SetDatapoints

func (d *Device) SetDatapoints(datapoints []DataPoint) error

SetDatapoints sets multiple data points at once

func (*Device) Update

func (d *Device) Update() error

Update updates the device information

type DiscoveredDevice

type DiscoveredDevice struct {
	LocalName       string
	Address         string
	IsBound         bool
	ProtocolVersion byte
	UUID            []byte
	RSSI            int
}

func (DiscoveredDevice) ID

func (d DiscoveredDevice) ID() string

type Discoverer

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

func NewDiscoverer

func NewDiscoverer(logger *slog.Logger) *Discoverer

func (*Discoverer) Discover

func (d *Discoverer) Discover() (<-chan *DiscoveredDevice, func())

func (*Discoverer) DiscoverDevice

func (d *Discoverer) DiscoverDevice(ctx context.Context, address string) (*DiscoveredDevice, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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