plugin

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2022 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Package plugin 插件模块

Index

Constants

This section is empty.

Variables

View Source
var NotExistErr = errors.New("plugin not exist")

Functions

func ArchiveURL

func ArchiveURL(pluginID string, req *http.Request) string

ArchiveURL 插件的前端压缩包地址

func BuildFromDir

func BuildFromDir(path, tag string) (imageID string, err error)

BuildFromDir 从源码编译镜像

func BuildFromTar

func BuildFromTar(tarPath string) (imageID string, err error)

BuildFromTar 从源码tar压缩包中build镜像

func ConcatPluginPath added in v1.9.1

func ConcatPluginPath(pluginID string, paths ...string) string

func DefaultOnDeviceStateChange

func DefaultOnDeviceStateChange(d entity.Device, attr entity.Attribute) error

func DeviceLogoURL added in v1.9.1

func DeviceLogoURL(req *http.Request, d entity.Device) string

DeviceLogoURL 设备Logo图片地址

func DisconnectDevice added in v1.5.0

func DisconnectDevice(identity, pluginID string, authParams map[string]string) error

func EndPointsManager

func EndPointsManager() (manager endpoints.Manager, err error)

func GetInfoFromDeviceAttrs added in v1.5.0

func GetInfoFromDeviceAttrs(pluginID string, das DeviceInstances) (d entity.Device, err error)

func GetInstanceControlAttributes

func GetInstanceControlAttributes(instance Instance) (attributes []entity.Attribute)

GetInstanceControlAttributes 获取实例的控制属性

func LogoURL

func LogoURL(req *http.Request, pluginID, model, logo string) string

LogoURL Logo图片地址

func NewClient

func NewClient(callbacks ...OnDeviceStateChange) *client

func NewDiscovery

func NewDiscovery(cli *client) *discovery

func NewManager

func NewManager() *manager

func OTA added in v1.9.1

func OTA(areaID uint64, pluginID, identity, firmwareURL string) (err error)

OTA 更新插件的设备的固件

func PluginURL

func PluginURL(d entity.Device, req *http.Request, token string) string

PluginURL 返回设备的插件控制页url

func RelativeControlPath

func RelativeControlPath(d entity.Device, token string) string

RelativeControlPath 返回设备的插件控制页相对路径

func RemoveDevice

func RemoveDevice(deviceID int) (err error)

RemoveDevice 删除设备,断开相关连接和回收资源

func RunPlugin added in v1.5.0

func RunPlugin(plg Plugin) (containerID string, err error)

RunPlugin 运行插件

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 Attribute

type Attribute struct {
	server.Attribute
	CanControl bool `json:"can_control"`
}

type Client

type Client interface {
	DevicesDiscover(ctx context.Context) <-chan DiscoverResponse
	GetAttributes(device entity.Device) (DeviceInstances, error)
	SetAttributes(device entity.Device, data json.RawMessage) (result []byte, err error)
	IsOnline(entity.Device) bool

	OTA(d entity.Device, firmwareURL string) error

	// Connect 连接设备
	Connect(identity, pluginID string, authParams map[string]string) (DeviceInstances, 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 Config added in v1.9.1

type Config struct {
	Name           string         `yaml:"name" json:"name" validate:"required"`                       // 插件名称
	Version        string         `yaml:"version" json:"version" validate:"required"`                 // 版本
	Info           string         `yaml:"info" json:"info"`                                           // 介绍
	SupportDevices []DeviceConfig `yaml:"support_devices" json:"support_devices" validate:"required"` // 支持的设备
}

Config 插件配置

func LoadPluginConfig added in v1.5.0

func LoadPluginConfig(path string) (plg Config, err error)

LoadPluginConfig 加载插件配置

func (Config) ID added in v1.9.1

func (p Config) ID() string

ID 根据配置生成插件ID

func (Config) Validate added in v1.9.1

func (p Config) Validate() error

type DeviceConfig added in v1.5.0

type DeviceConfig struct {
	Model string     `json:"model" yaml:"model"`
	Name  string     `json:"name" yaml:"name"`
	Type  DeviceType `json:"type" yaml:"type"` // 设备类型

	Control      string `json:"control" yaml:"control"`           // 设备控制页面相对路径
	Provisioning string `json:"provisioning" yaml:"provisioning"` // 设备置网页面相对路径
	PluginID     string `json:"-"`
}

DeviceConfig 插件设备配置

type DeviceInfo added in v1.5.0

type DeviceInfo struct {
	Identity     string
	Model        string
	Manufacturer string
	Version      string
}

type DeviceInstances added in v1.9.1

type DeviceInstances struct {
	Identity  string     `json:"identity"`
	Instances []Instance `json:"instances"`

	// OTASupport 是否支持OTA
	OTASupport bool `json:"ota_support"`
}

func ConnectDevice added in v1.5.0

func ConnectDevice(identity, pluginID string, authParams map[string]string) (das DeviceInstances, err error)

func (DeviceInstances) GetInfo added in v1.9.1

func (das DeviceInstances) GetInfo() (d DeviceInfo, err error)

GetInfo 获取设备基础信息

type DeviceType

type DeviceType string
const (
	TypeLight          DeviceType = "light"           // 照明
	TypeSwitch         DeviceType = "switch"          // 开关
	TypeOutlet         DeviceType = "outlet"          // 插座
	TypeRoutingGateway DeviceType = "routing_gateway" // 路由网关
	TypeSecurity       DeviceType = "security"        // 安防
	TypeSensor         DeviceType = "sensor"          // 传感器
	TypeLifeElectric   DeviceType = "life_electric"   // 生活电器

	TypeLamp             DeviceType = "lamp"               // 台灯
	TypeCeilingLamp      DeviceType = "ceiling_lamp"       // 吸顶灯
	TypeBulb             DeviceType = "bulb"               // 灯泡
	TypeLightStrip       DeviceType = "light_strip"        // 灯带
	TypePendantLight     DeviceType = "pendant_light"      // 吊灯
	TypeBedSideLamp      DeviceType = "bedside_lamp"       // 夜灯
	TypeNightLight       DeviceType = "night_light"        // 床头灯
	TypeFanLamp          DeviceType = "fan_lamp"           // 风扇灯
	TypeDownLight        DeviceType = "down_light"         // 简射灯
	TypeMagneticRailLamp DeviceType = "magnetic_rail_lamp" // 磁吸轨道灯

	TypeOneKeySwitch    DeviceType = "one_key_switch"   // 单键开关
	TypeTwoKeySwitch    DeviceType = "two_key_switch"   // 双键开关
	TypeThreeKeySwitch  DeviceType = "three_key_switch" // 三键开关
	TypeDWirelessSwitch DeviceType = "wireless_switch"  // 无线开关

	TypeConverter  DeviceType = "converter"   // 转换器
	TypeWallPlug   DeviceType = "wall_plug"   // 入墙插座
	TypePowerStrip DeviceType = "power_strip" // 排座

	TypeRouter       DeviceType = "router"        // 路由器
	TypeWifiRepeater DeviceType = "wifi_repeater" // wifi信号放大器
	TypeGateway      DeviceType = "gateway"       // 网关

	TypeCamera           DeviceType = "camera"            // 摄像头
	TypePeepholeDoorbell DeviceType = "peephole_doorbell" // 猫眼门铃
	TypeDoorLock         DeviceType = "door_lock"         // 门锁

	TypeCurtain DeviceType = "curtain" // 窗帘电机

	TypeTemperatureAndHumiditySensor DeviceType = "temperature_humidity_sensor" // 温湿度传感器
	TypeHumanSensors                 DeviceType = "human_sensor"                // 人体传感器
	TypeSmokeSensor                  DeviceType = "smoke_sensor"                // 烟雾传感器
	TypeGasSensor                    DeviceType = "gas_sensor"                  // 燃气传感器
	TypeWindowDoorSensor             DeviceType = "window_door_sensor"          // 门窗传感器
	TypeWaterLeakSensor              DeviceType = "water_leak_sensor"           // 水浸传感器
	TypeIlluminanceSensor            DeviceType = "illuminance_sensor"          // 光照度传感器
	TypeDynamicAndStaticSensor       DeviceType = "dynamic_static_sensor"       // 动静传感器
)

type DiscoverResponse

type DiscoverResponse struct {
	Name         string `json:"name"`
	Identity     string `json:"identity"`
	Model        string `json:"model"`
	Manufacturer string `json:"manufacturer"`
	PluginID     string `json:"plugin_id"`
	LogoURL      string `json:"logo_url"`
	AuthRequired bool   `json:"auth_required"`
}

type Info

type Info struct {
	Control      string `json:"control" yaml:"control"`           // 设备控制页面相对路径
	Provisioning string `json:"provisioning" yaml:"provisioning"` // 设备置网页面相对路径
	Compress     string `json:"compress" yaml:"compress"`         // 压缩包地址
}

type Instance

type Instance struct {
	Type       string      `json:"type"`
	InstanceId int         `json:"instance_id"`
	Attributes []Attribute `json:"attributes"`
}

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 OnDeviceStateChange func(d entity.Device, attr entity.Attribute) error

type Plugin

type Plugin struct {
	Config `yaml:",inline"`
	ID     string `json:"id" yaml:"id"`
	Brand  string `json:"brand" yaml:"brand"`
	Image  string `json:"image" yaml:"image"`
	Source string `json:"source" yaml:"source"` // 插件来源
	AreaID uint64 `json:"area_id" yaml:"area_id"`
}

Plugin 插件详情

func GetPluginConfig added in v1.5.0

func GetPluginConfig(addr, pluginID string) (config Plugin, err error)

GetPluginConfig 获取插件配置

func LoadPluginFromZip

func LoadPluginFromZip(path string, areaID uint64) (plg Plugin, err error)

LoadPluginFromZip 从压缩包中加载插件

func NewFromEntity added in v1.5.0

func NewFromEntity(p entity.PluginInfo) Plugin

func (Plugin) Install

func (p Plugin) Install() (err error)

Install 安装并且启动插件

func (Plugin) IsAdded

func (p Plugin) IsAdded() bool

func (Plugin) IsDevelopment

func (p Plugin) IsDevelopment() bool

IsDevelopment 是否开发者上传的插件

func (Plugin) IsNewest

func (p Plugin) IsNewest() bool

func (Plugin) IsRunning

func (p Plugin) IsRunning() bool

func (Plugin) Remove

func (p Plugin) Remove() (err error)

Remove 删除插件

func (Plugin) StopAndRemovePluginImage added in v1.9.1

func (p Plugin) StopAndRemovePluginImage() (err error)

StopAndRemovePluginImage 停止插件容器并删除插件镜像

func (Plugin) Up

func (p Plugin) Up() (err error)

Up 启动插件

func (Plugin) Update

func (p Plugin) Update() (err error)

Update 更新插件

func (Plugin) UpdateOrInstall added in v1.5.0

func (p Plugin) UpdateOrInstall() (err error)

Directories

Path Synopsis
Package docker 提供与本机 Docker 守护进程交互的功能;包括镜像管理,容器启动
Package docker 提供与本机 Docker 守护进程交互的功能;包括镜像管理,容器启动

Jump to

Keyboard shortcuts

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