addon

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

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

Go to latest
Published: Sep 20, 2021 License: MIT Imports: 10 Imported by: 0

README

package main

import (
	addon "github.com/galenliu/gateway-addon"
	"log"
)

type ExampleAdapter struct {
	*addon.Adapter
}

// StartPairing 客户端配对时,回调的方法
func (a *ExampleAdapter) StartPairing(timeout float64) {
	log.Printf("adapter:(%s)- StartPairing() not implemented", a.GetID())
}

// CancelPairing 客户端取消配对时回调的方法
func (a *ExampleAdapter) CancelPairing() {

	log.Printf("adapter:(%s)- CancelPairing() not implemented", a.GetID())

}

type ExampleDevice struct {
	*addon.Device
}

type ExampleProperty struct {
	*addon.Property
}

Documentation

Index

Constants

View Source
const (
	Aid = "adapterId"
	Pid = "pluginId"
	Did = "deviceId"
)
View Source
const (
	TypeString  = "string"
	TypeBoolean = "boolean"
	TypeInteger = "integer"
	TypeNumber  = "number"

	UnitHectopascal = "hectopascal"
	UnitKelvin      = "kelvin"
	UnitPercentage  = "percentage"
	UnitArcDegrees  = "arcdegrees"
	UnitCelsius     = "celsius"
	UnitLux         = "lux"
	UnitSeconds     = "seconds"
	UnitPPM         = "ppm"

	AlarmProperty                    = "AlarmProperty"
	BarometricPressureProperty       = "BarometricPressureProperty"
	ColorModeProperty                = "ColorModeProperty"
	ColorProperty                    = "ColorProperty"
	ColorTemperatureProperty         = "ColorTemperatureProperty"
	ConcentrationProperty            = "ConcentrationProperty"
	CurrentProperty                  = "CurrentProperty"
	DensityProperty                  = "DensityProperty"
	FrequencyProperty                = "FrequencyProperty"
	HeatingCoolingProperty           = "HeatingCoolingProperty"
	HumidityProperty                 = "HumidityProperty"
	ImageProperty                    = "ImageProperty"
	InstantaneousPowerFactorProperty = "InstantaneousPowerFactorProperty"
	InstantaneousPowerProperty       = "InstantaneousPowerProperty"
	LeakProperty                     = "LeakProperty"
	LevelProperty                    = "LevelProperty"
	LockedProperty                   = "LockedProperty"
	MotionProperty                   = "MotionProperty"

	Alarm                    = "Alarm"
	AirQualitySensor         = "AirQualitySensor"
	BarometricPressureSensor = "BarometricPressureSensor"
	BinarySensor             = "BinarySensor"
	Camera                   = "Camera"
	ColorControl             = "ColorControl"
	ColorSensor              = "ColorSensor"
	DoorSensor               = "DoorSensor"
	EnergyMonitor            = "EnergyMonitor"
	HumiditySensor           = "HumiditySensor"
	LeakSensor               = "LeakSensor"
	Light                    = "Light"
	Lock                     = "Lock"
	MotionSensor             = "MotionSensor"
	MultiLevelSensor         = "MultiLevelSensor"
	MultiLevelSwitch         = "MultiLevelSwitch"
	OnOffSwitch              = "OnOffSwitch"
	SmartPlug                = "SmartPlug"
	SmokeSensor              = "SmokeSensor"
	TemperatureSensor        = "TemperatureSensor"
	Thermostat               = "Thermostat"
	VideoCamera              = "VideoCamera"

	Context = "https://webthings.io/schemas"

	OpenProperty              = "OpenProperty"
	PushedProperty            = "PushedProperty"
	SmokeProperty             = "SmokeProperty"
	TargetTemperatureProperty = "TargetTemperatureProperty"
	TemperatureProperty       = "TemperatureProperty"
	ThermostatModeProperty    = "ThermostatModeProperty"
	VideoProperty             = "VideoProperty"
	VoltageProperty           = "VoltageProperty"
)
View Source
const (
	AdapterAddedNotification           = 4096
	AdapterCancelPairingCommand        = 4100
	AdapterCancelRemoveDeviceCommand   = 4105
	AdapterPairingPromptNotification   = 4101
	AdapterRemoveDeviceRequest         = 4103
	AdapterRemoveDeviceResponse        = 4104
	AdapterStartPairingCommand         = 4099
	AdapterUnloadRequest               = 4097
	AdapterUnloadResponse              = 4098
	AdapterUnpairingPromptNotification = 4102
	ApiHandlerAddedNotification        = 20480
	ApiHandlerApiRequest               = 20483
	ApiHandlerApiResponse              = 20484
	ApiHandlerUnloadRequest            = 20481
	ApiHandlerUnloadResponse           = 20482
	DeviceActionStatusNotification     = 8201
	DeviceAddedNotification            = 8192
	DeviceConnectedStateNotification   = 8197
	DeviceDebugCommand                 = 8206
	DeviceEventNotification            = 8200
	DevicePropertyChangedNotification  = 8199
	DeviceRemoveActionRequest          = 8202
	DeviceRemoveActionResponse         = 8203
	DeviceRequestActionRequest         = 8204
	DeviceRequestActionResponse        = 8205
	DeviceSavedNotification            = 8207
	DeviceSetCredentialsRequest        = 8195
	DeviceSetCredentialsResponse       = 8196
	DeviceSetPinRequest                = 8193
	DeviceSetPinResponse               = 8194
	DeviceSetPropertyCommand           = 8198
	MockAdapterAddDeviceRequest        = 61440
	MockAdapterAddDeviceResponse       = 61441
	MockAdapterClearStateRequest       = 61446
	MockAdapterClearStateResponse      = 61447
	MockAdapterPairDeviceCommand       = 61444
	MockAdapterRemoveDeviceRequest     = 61442
	MockAdapterRemoveDeviceResponse    = 61443
	MockAdapterUnpairDeviceCommand     = 61445
	NotifierAddedNotification          = 12288
	NotifierUnloadRequest              = 12289
	NotifierUnloadResponse             = 12290
	OutletAddedNotification            = 16384
	OutletNotifyRequest                = 16386
	OutletNotifyResponse               = 16387
	OutletRemovedNotification          = 16385
	PluginErrorNotification            = 4
	PluginRegisterRequest              = 0
	PluginRegisterResponse             = 1
	PluginUnloadRequest                = 2
	PluginUnloadResponse               = 3
)
View Source
const (
	Disconnect = "Disconnect"
	Connected  = "Connected"
	Registered = "Registered"
)
View Source
const IpcDefaultPort = "9500"

Variables

This section is empty.

Functions

func MessageTypeToString

func MessageTypeToString(mt int) string

Types

type Action

type Action struct {
	Name     string `json:"name"`
	DeviceId string `json:"deviceId,omitempty"`
}

func NewAction

func NewAction() *Action

func NewActionFromString

func NewActionFromString(data string) *Action

func (*Action) AsDict

func (a *Action) AsDict() Map

func (*Action) MarshalJson

func (a *Action) MarshalJson() []byte

type Adapter

type Adapter struct {
	Devices map[string]IDevice

	Id string

	IsPairing bool
	// contains filtered or unexported fields
}

func NewAdapter

func NewAdapter(adapterId, adapterName string) *Adapter

func (*Adapter) CancelPairing

func (a *Adapter) CancelPairing()

func (*Adapter) GetID

func (a *Adapter) GetID() string

func (*Adapter) GetName

func (a *Adapter) GetName() string

func (*Adapter) HandleDeviceAdded

func (a *Adapter) HandleDeviceAdded(device IDevice)

func (*Adapter) HandleDeviceRemoved

func (a *Adapter) HandleDeviceRemoved(device IDevice)

func (*Adapter) HandleDeviceSaved

func (a *Adapter) HandleDeviceSaved(device IDevice)

func (*Adapter) Running

func (a *Adapter) Running() bool

func (*Adapter) Send

func (a *Adapter) Send(mt int, data map[string]interface{})

func (*Adapter) SendError

func (a *Adapter) SendError(message string)

func (*Adapter) SendPairingPrompt

func (a *Adapter) SendPairingPrompt(prompt, url string, did string)

向前端UI发送提示

func (*Adapter) SendUnpairingPrompt

func (a *Adapter) SendUnpairingPrompt(prompt, url string, did string)

func (*Adapter) SetCredentials

func (a *Adapter) SetCredentials(deviceId, username, password string)

func (*Adapter) SetPin

func (a *Adapter) SetPin(deviceId string, pin interface{})

func (*Adapter) StartPairing

func (a *Adapter) StartPairing(timeout float64)

func (*Adapter) Unload

func (a *Adapter) Unload()

type AddonManager

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

func InitAddonManager

func InitAddonManager(packageName string) *AddonManager

func (*AddonManager) AddAdapters

func (m *AddonManager) AddAdapters(adapters ...IAdapter)

type Event

type Event struct {
	Name string `json:"name"`
	//Subscription *data_schema.DataSchema `json:"subscription,omitempty"`
	//Data         *data_schema.DataSchema `json:"data,omitempty"`
	//Cancellation *data_schema.DataSchema `json:"cancellation,omitempty"`
	DeviceId string `json:"deviceId"`
}

func (*Event) GetEvent

func (e *Event) GetEvent() *Event

func (*Event) MarshalJson

func (e *Event) MarshalJson() []byte

type IAction

type IAction interface {
	MarshalJson() []byte
}

type IAdapter

type IAdapter interface {
	//SendPairingPrompt(promt, url string, device *Device)
	StartPairing(timeout float64)
	CancelPairing()
	GetID() string
	GetName() string
	Unload()
	HandleDeviceSaved(device IDevice)
	HandleDeviceRemoved(device IDevice)

	Send(mt int, data map[string]interface{})
	// contains filtered or unexported methods
}

type IDevice

type IDevice interface {
	Send(int, map[string]interface{})
	GetProperty(name string) IProperty
	SetCredentials(username string, password string) error
	SetPin(pin interface{}) error
	GetDescription() string
	ToJson() string
	GetID() string
	AsDict() Map
	GetAdapterId() string
}

type IEvent

type IEvent interface {
	MarshalJson() []byte
}

type IProperty

type IProperty interface {
	SetValue(interface{})
	GetValue() interface{}
	GetName() string
	SetName(string)
	GetAtType() string
	GetType() string
	AsDict() []byte
	ToValue(interface{}) interface{}

	DoPropertyChanged(string)
	UpdateProperty(string)

	SetDeviceProxy(device IDevice)
}

type IpcClient

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

func NewClient

func NewClient(PluginId string, handler OnMessage) *IpcClient

新建一个Client,注册消息Handler

func (*IpcClient) Register

func (client *IpcClient) Register()

type Map

type Map = map[string]interface{}

type OnCancelPairingFunc

type OnCancelPairingFunc func()

type OnDeviceSavedFunc

type OnDeviceSavedFunc func(deivceId string, device *devices.Device)

type OnMessage

type OnMessage func(data []byte)

type OnSetCredentialsFunc

type OnSetCredentialsFunc func(deivceId, username, password string)

type Preferences

type Preferences struct {
	Language string `validate:"required" json:"language"`
	Units    Units  `validate:"required" json:"units"`
}

type RpcClint

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

func NewRpcClint

func NewRpcClint(addr string) (*RpcClint, error)

func (RpcClint) Close

func (c RpcClint) Close() error

type Units

type Units struct {
	Temperature string `validate:"required" json:"temperature"`
}

type UserProfile

type UserProfile struct {
	BaseDir        string `validate:"required" json:"base_dir"`
	DataDir        string `validate:"required" json:"data_dir"`
	AddonsDir      string `validate:"required" json:"addons_dir"`
	ConfigDir      string `validate:"required" json:"config_dir"`
	UploadDir      string `validate:"required" json:"upload_dir"`
	MediaDir       string `validate:"required" json:"media_dir"`
	LogDir         string `validate:"required" json:"log_dir"`
	GatewayVersion string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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