Documentation
¶
Overview ¶
Package plugin 插件模块
Index ¶
- Variables
- func ArchiveURL(pluginID string, req *http.Request) string
- func BuildFromDir(path, tag string) (imageID string, err error)
- func BuildFromTar(tarPath string) (imageID string, err error)
- func DefaultOnDeviceStateChange(d entity.Device, attr entity.Attribute) error
- func DisconnectDevice(identity, pluginID string, authParams map[string]string) error
- func EndPointsManager() (manager endpoints.Manager, err error)
- func GetControlAttributeByID(d entity.Device, instanceID int, attr string) (attribute entity.Attribute, err error)
- func GetControlAttributes(d entity.Device) (attributes []entity.Attribute, err error)
- func GetInfoFromDeviceAttrs(pluginID string, das DeviceAttributes) (d entity.Device, err error)
- func GetInstanceControlAttributes(instance Instance) (attributes []entity.Attribute)
- func LogoURL(req *http.Request, d entity.Device) string
- func NewClient(callbacks ...OnDeviceStateChange) *client
- func NewDiscovery(cli *client) *discovery
- func NewManager() *manager
- func PluginBasePath(path string) (plgPath string)
- func PluginURL(d entity.Device, req *http.Request, token string) string
- func RelativeControlPath(d entity.Device, token string) string
- func RemoveDevice(deviceID int) (err error)
- func RunPlugin(plg Plugin) (containerID string, err error)
- func SetAttributes(areaID uint64, pluginID, identity string, data json.RawMessage) (err error)
- func SetGlobalClient(c Client)
- func SetGlobalManager(m Manager)
- func StaticURL(pluginID, relativePath string, req *http.Request) string
- func UpdateShadowReported(d entity.Device, attr entity.Attribute) (err error)
- type Attribute
- type Client
- type Device
- type DeviceAttributes
- type DeviceConfig
- type DeviceInfo
- type DeviceType
- type DiscoverResponse
- type Info
- type Instance
- type Manager
- type OnDeviceStateChange
- type Plugin
- func (p Plugin) Install() (err error)
- func (p Plugin) IsAdded() bool
- func (p Plugin) IsDevelopment() bool
- func (p Plugin) IsNewest() bool
- func (p Plugin) IsRunning() bool
- func (p Plugin) Remove() (err error)
- func (p Plugin) Up() (err error)
- func (p Plugin) Update() (err error)
- func (p Plugin) UpdateOrInstall() (err error)
- type PluginConfig
Constants ¶
This section is empty.
Variables ¶
View Source
var NotExistErr = errors.New("plugin not exist")
Functions ¶
func BuildFromDir ¶
BuildFromDir 从源码编译镜像
func BuildFromTar ¶
BuildFromTar 从源码tar压缩包中build镜像
func DisconnectDevice ¶ added in v1.5.0
func EndPointsManager ¶
func GetControlAttributeByID ¶
func GetControlAttributeByID(d entity.Device, instanceID int, attr string) (attribute entity.Attribute, err error)
GetControlAttributeByID 获取设备属性(不包括设备型号、厂商等属性)
func GetControlAttributes ¶
GetControlAttributes 获取设备属性(不包括设备型号、厂商等属性)
func GetInfoFromDeviceAttrs ¶ added in v1.5.0
func GetInfoFromDeviceAttrs(pluginID string, das DeviceAttributes) (d entity.Device, err error)
func GetInstanceControlAttributes ¶
GetInstanceControlAttributes 获取实例的控制属性
func NewClient ¶
func NewClient(callbacks ...OnDeviceStateChange) *client
func NewDiscovery ¶
func NewDiscovery(cli *client) *discovery
func NewManager ¶
func NewManager() *manager
func PluginBasePath ¶ added in v1.5.0
PluginBasePath 根据配置文件config.json确定插件包准确目录
func RelativeControlPath ¶
RelativeControlPath 返回设备的插件控制页相对路径
func SetAttributes ¶
func SetAttributes(areaID uint64, pluginID, identity string, data json.RawMessage) (err error)
SetAttributes 通过插件设置设备的属性
func SetGlobalClient ¶
func SetGlobalClient(c Client)
func SetGlobalManager ¶
func SetGlobalManager(m Manager)
Types ¶
type Client ¶
type Client interface {
DevicesDiscover(ctx context.Context) <-chan DiscoverResponse
GetAttributes(device entity.Device) (DeviceAttributes, error)
SetAttributes(device entity.Device, data json.RawMessage) (result []byte, err error)
HealthCheck(entity.Device) error
IsOnline(entity.Device) bool
// Connect 连接设备
Connect(identity, pluginID string, authParams map[string]string) (DeviceAttributes, error)
// Disconnect 与设备断开连接
Disconnect(identity, pluginID string, authParams map[string]string) error
// DeviceConfig 设备的配置
DeviceConfig(entity.Device) DeviceConfig
// DeviceConfigs 所有设备的配置
DeviceConfigs() []DeviceConfig
}
Client 与插件服务交互的客户端
func GetGlobalClient ¶
func GetGlobalClient() Client
type Device ¶
type Device struct {
Model string `json:"model" yaml:"model"`
Name string `json:"name" yaml:"name"`
Type DeviceType `json:"type" yaml:"type"` // 设备类型
Logo string `json:"logo" yaml:"logo"` // 设备logo相对路径
Control string `json:"control" yaml:"control"` // 设备控制页面相对路径
Provisioning string `json:"provisioning" yaml:"provisioning"` // 设备置网页面相对路径
}
type DeviceAttributes ¶
type DeviceAttributes struct {
Identity string `json:"identity"`
Instances []Instance `json:"instances"`
Online bool `json:"online"`
}
func ConnectDevice ¶ added in v1.5.0
func ConnectDevice(identity, pluginID string, authParams map[string]string) (das DeviceAttributes, err error)
func GetUserDeviceAttributes ¶
func GetUserDeviceAttributes(areaID uint64, userID int, pluginID, identity string) (das DeviceAttributes, err error)
GetUserDeviceAttributes 获取用户设备的属性(包括权限)
type DeviceConfig ¶ added in v1.5.0
type DeviceInfo ¶ added in v1.5.0
type DeviceInfo struct {
Model string `json:"model" validate:"required"`
Name string `json:"name" validate:"required"`
Logo string `json:"logo" validate:"required"` // 设备logo相对路径
Control string `json:"control" validate:"required"` // 设备控制页面相对路径
Provisioning string `json:"provisioning"` // 设备置网页面相对路径
}
type DeviceType ¶
type DeviceType string
const ( TypeLight DeviceType = "light" // 灯 TypeSwitch DeviceType = "switch" // 开关 TypeOutlet DeviceType = "outlet" // 插座 TypeRoutingGateway DeviceType = "routing_gateway" // 路由网关 TypeSecurity DeviceType = "security" // 安防 )
type DiscoverResponse ¶
type Manager ¶
type Manager interface {
// LoadPlugins 加载并返回所有插件
LoadPlugins() (map[string]*Plugin, error)
// GetPlugin 加载并返回插件
GetPlugin(id string) (*Plugin, error)
}
Manager 与SC服务交互获取插件信息
func GetGlobalManager ¶
func GetGlobalManager() Manager
type OnDeviceStateChange ¶
type Plugin ¶
type Plugin struct {
ID string `json:"id" yaml:"id"`
Name string `json:"name" yaml:"name"`
Image string `json:"image" yaml:"image"`
Version string `json:"version" yaml:"version"`
Brand string `json:"brand" yaml:"brand"`
Info string `json:"info" yaml:"info"`
DownloadURL string `json:"download_url" yaml:"download_url"` // 插件静态文件下载地址
SupportDevices []*Device `json:"support_devices" yaml:"support_devices"`
Source string `json:"source" yaml:"source"` // 插件来源
AreaID uint64 `json:"area_id" yaml:"area_id"`
}
func GetPluginConfig ¶ added in v1.5.0
GetPluginConfig 获取插件配置
func LoadPluginFromZip ¶
LoadPluginFromZip 从压缩包中加载插件
func NewFromEntity ¶ added in v1.5.0
func NewFromEntity(p entity.PluginInfo) Plugin
func (Plugin) UpdateOrInstall ¶ added in v1.5.0
type PluginConfig ¶ added in v1.5.0
type PluginConfig struct {
Name string `json:"name" validate:"required"` // 插件名称
Version string `json:"version" validate:"required"` // 版本
Info string `json:"info"` // 介绍
SupportDevices []DeviceInfo `json:"support_devices" validate:"required"` // 支持的设备
}
func LoadPluginConfig ¶ added in v1.5.0
func LoadPluginConfig(path string) (plg PluginConfig, err error)
LoadPluginConfig 加载插件配置
func (PluginConfig) Validate ¶ added in v1.5.0
func (p PluginConfig) Validate() error
Source Files
¶
Click to show internal directories.
Click to hide internal directories.