miio

package module
v0.0.0-...-f4a0e58 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: MIT Imports: 17 Imported by: 0

README

go-miio

Xiaomi IoT devices protocol implementation. Mainly created for go-home.

Credits

Gateway implementation is based on xuebing1110 work.

Standalone devices are using protocol implementation by nickw444

Supported devices

Gateway-enabled
  • Temperature/humidity sensors
  • Switches
  • Motion sensors
  • Magnets
  • Gateway LED
Standalone
  • Vacuum

Protocol

Check full protocol specs here.

Full Vacuum specs are here.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// LOGGER implementation.
	LOGGER = newLogger()
)

Functions

This section is empty.

Types

type ClickType

type ClickType int

ClickType represents Xiaomi switch state.

const (
	// ClickNo describes no click.
	ClickNo ClickType = iota
	// ClickSingle describes single click.
	ClickSingle
	// ClickDouble describes double click.
	ClickDouble
	// ClickLongPress describes the beginning of a long click.
	ClickLongPress
	// ClickLongRelease describes the end of a long click.
	ClickLongRelease
)

type DeviceUpdateMessage

type DeviceUpdateMessage struct {
	ID    string
	State interface{}
}

DeviceUpdateMessage contains data about an update.

type Gateway

type Gateway struct {
	XiaomiDevice

	State      *GatewayState
	UpdateChan chan *DeviceUpdateMessage

	Sensors  map[string]*SensorHT
	Magnets  map[string]*Magnet
	Motions  map[string]*Motion
	Switches map[string]*Switch
	// contains filtered or unexported fields
}

Gateway represents a Xiaomi gateway.

func NewGateway

func NewGateway(deviceIP, aesKey string) (*Gateway, error)

NewGateway creates a new gateway.

func (*Gateway) GetUpdateMessage

func (g *Gateway) GetUpdateMessage() *DeviceUpdateMessage

GetUpdateMessage returns a state update message.

func (*Gateway) Off

func (g *Gateway) Off() error

Off turns the gateway off.

func (*Gateway) On

func (g *Gateway) On() error

On turns the gateway on.

func (*Gateway) SetBrightness

func (g *Gateway) SetBrightness(br uint8) error

SetBrightness sets the LED light brightness.

func (*Gateway) SetColor

func (g *Gateway) SetColor(c color.Color) error

SetColor sets the LED light color.

func (*Gateway) Stop

func (g *Gateway) Stop()

Stop stops the gateway.

func (*Gateway) UpdateState

func (g *Gateway) UpdateState()

UpdateState updates the gateway state.

type GatewayState

type GatewayState struct {
	On         bool
	RGB        color.Color
	Brightness uint8
	// contains filtered or unexported fields
}

GatewayState defines the gateway state.

type IDevice

type IDevice interface {
	Stop()
	GetUpdateMessage() *DeviceUpdateMessage
	SetRawState(map[string]interface{})
	UpdateState()
}

IDevice defines Xiaomi device.

type ILogger

type ILogger interface {
	SetLevel(level LogLevel) error
	Debug(format string, v ...interface{})
	Info(format string, v ...interface{})
	Warn(format string, v ...interface{})
	Error(format string, v ...interface{})
	Fatal(format string, v ...interface{})
}

ILogger defines a logger interface.

type LogLevel

type LogLevel int
const (
	LogLevelFatal LogLevel = iota
	LogLevelError
	LogLevelWarn
	LogLevelInfo
	LogLevelDebug
)

type Magnet

type Magnet struct {
	XiaomiDevice

	ID      string
	Gateway *Gateway
	State   *MagnetState
}

Magnet defines a Xiaomi magnet.

func (*Magnet) GetUpdateMessage

func (m *Magnet) GetUpdateMessage() *DeviceUpdateMessage

GetUpdateMessage returns device's state update message.

func (*Magnet) Stop

func (m *Magnet) Stop()

Stops is not uses for gateway devices.

func (*Magnet) UpdateState

func (m *Magnet) UpdateState()

UpdateState performs a device update.

type MagnetState

type MagnetState struct {
	Opened  bool
	Battery float32
}

MagnetState describes a state of the magnet.

type Motion

type Motion struct {
	XiaomiDevice

	ID      string
	Gateway *Gateway
	State   *MotionState
}

Motion defines a Xiaomi motion sensor.

func (*Motion) GetUpdateMessage

func (m *Motion) GetUpdateMessage() *DeviceUpdateMessage

GetUpdateMessage returns device's state update message.

func (*Motion) Stop

func (m *Motion) Stop()

Stops is not uses for gateway devices.

func (*Motion) UpdateState

func (m *Motion) UpdateState()

UpdateState performs a device update.

type MotionState

type MotionState struct {
	Battery    float32
	HasMotion  bool
	LastMotion time.Time
}

MotionState describes a state of the motion sensor.

type SensorHT

type SensorHT struct {
	XiaomiDevice

	ID      string
	Gateway *Gateway
	State   *SensorHTState
}

SensorHT defines a Xiaomi humidity-temperature sensor.

func (*SensorHT) GetUpdateMessage

func (s *SensorHT) GetUpdateMessage() *DeviceUpdateMessage

GetUpdateMessage returns device's state update message.

func (*SensorHT) Stop

func (s *SensorHT) Stop()

Stops is not uses for gateway devices.

func (*SensorHT) UpdateState

func (s *SensorHT) UpdateState()

UpdateState performs a device update.

type SensorHTState

type SensorHTState struct {
	Temperature float64
	Humidity    float64
	Battery     float32
}

SensorHTState describes a state of the humidity-temperature sensor.

type Switch

type Switch struct {
	XiaomiDevice

	ID      string
	Gateway *Gateway
	State   *SwitchState
}

Switch defines a Xiaomi switch.

func (*Switch) GetUpdateMessage

func (s *Switch) GetUpdateMessage() *DeviceUpdateMessage

GetUpdateMessage returns device's state update message.

func (*Switch) Stop

func (s *Switch) Stop()

Stops is not uses for gateway devices.

func (*Switch) UpdateState

func (s *Switch) UpdateState()

UpdateState performs a device update.

type SwitchState

type SwitchState struct {
	Click   ClickType
	Battery float32
}

SwitchState describes a state of the switch.

type VacError

type VacError int

VacError defines possible vacuum error.

const (
	// VacErrorNo describes no errors.
	VacErrorNo VacError = iota
	// VacErrorCharge describes error with charger.
	VacErrorCharge
	// VacErrorFull describes full dust container.
	VacErrorFull
	// VacErrorUnknown describes unknown error
	VacErrorUnknown
)

type VacState

type VacState int

VacState defines possible vacuum state.

const (
	// VacStateUnknown describes unknown state.
	VacStateUnknown VacState = iota
	// VacStateInitiating indicates that vacuum is in initializing mode.
	VacStateInitiating
	// VacStateSleeping indicates that vacuum is in a sleep mode.
	VacStateSleeping
	// VacStateWaiting indicates that vacuum is in waiting mode.
	VacStateWaiting
	// VacStateCleaning indicates that vacuums is cleaning.
	VacStateCleaning
	// VacStateReturning indicates that vacuum is returning to the dock.
	VacStateReturning
	// VacStateCharging indicates that vacuum is charging.
	VacStateCharging
	// VacStatePaused indicates that cleaning is paused.
	VacStatePaused
	// VacStateSpot indicates that vacuum is cleaning a spot.
	VacStateSpot
	//VacStateShuttingDown indicates that vacuum is shutting down.
	VacStateShuttingDown
	// VacStateUpdating indicates that vacuum is in an update mode.
	VacStateUpdating
	// VacStateDocking indicates that vacuum is in a process of docking.
	VacStateDocking
	// VacStateZone indicates that vacuum is cleaning az one.
	VacStateZone
	// VacStateFull indicates that dust bag is full.
	VacStateFull
)

type Vacuum

type Vacuum struct {
	XiaomiDevice
	State *VacuumState

	UpdateChan chan *DeviceUpdateMessage
}

Vacuum defines a Xiaomi vacuum cleaner.

func NewVacuum

func NewVacuum(deviceIP, token string) (*Vacuum, error)

NewVacuum creates a new vacuum.

func (*Vacuum) FindMe

func (v *Vacuum) FindMe() bool

FindMe sends the find me command.

func (*Vacuum) GetUpdateMessage

func (v *Vacuum) GetUpdateMessage() *DeviceUpdateMessage

GetUpdateMessage returns an update message.

func (*Vacuum) PauseCleaning

func (v *Vacuum) PauseCleaning() bool

PauseCleaning pauses the cleaning cycle.

func (*Vacuum) SetFanPower

func (v *Vacuum) SetFanPower(val uint8) bool

SetFanSpeed sets fan speed

func (*Vacuum) StartCleaning

func (v *Vacuum) StartCleaning() bool

StartCleaning starts the cleaning cycle.

func (*Vacuum) Stop

func (v *Vacuum) Stop()

Stop stops the device.

func (*Vacuum) StopCleaning

func (v *Vacuum) StopCleaning() bool

StopCleaning stops the cleaning cycle.

func (*Vacuum) StopCleaningAndDock

func (v *Vacuum) StopCleaningAndDock() bool

StopCleaningAndDock stops the cleaning cycle and returns to dock.

func (*Vacuum) UpdateState

func (v *Vacuum) UpdateState()

UpdateState performs a state update.

func (*Vacuum) UpdateStatus

func (v *Vacuum) UpdateStatus() bool

UpdateStatus requests for a state update.

type VacuumState

type VacuumState struct {
	Battery    int
	CleanArea  int
	CleanTime  int
	IsDND      bool
	IsCleaning bool
	FanPower   int
	Error      VacError
	State      VacState
}

VacuumState describes a vacuum state.

type XiaomiDevice

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

XiaomiDevice represents Xiaomi device.

func (*XiaomiDevice) GetBatteryLevel

func (d *XiaomiDevice) GetBatteryLevel(curVal float32) float32

GetBatteryLevel returns current battery level percent.

func (*XiaomiDevice) GetFieldPercentage

func (d *XiaomiDevice) GetFieldPercentage(field fldName, curVal float64) float64

GetFieldPercentage returns percent field.

func (*XiaomiDevice) GetFieldValueBool

func (d *XiaomiDevice) GetFieldValueBool(field fldName, curVal bool) bool

GetFieldValueBool returns bool value.

func (*XiaomiDevice) GetFieldValueFloat64

func (d *XiaomiDevice) GetFieldValueFloat64(field fldName, curVal float64) float64

GetFieldValueFloat64 returns float64 value.

func (*XiaomiDevice) GetFieldValueInt32

func (d *XiaomiDevice) GetFieldValueInt32(field fldName, curVal int32) int32

GetFieldValueInt32 returns int32 value.

func (*XiaomiDevice) GetFieldValueUint32

func (d *XiaomiDevice) GetFieldValueUint32(field fldName, curVal uint32) uint32

GetFieldValueUint32 returns uint32 value.

func (*XiaomiDevice) SetRawState

func (d *XiaomiDevice) SetRawState(state map[string]interface{})

Sets raw state of the device. Used for Gateway devices.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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