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 ConcatPluginPath(pluginID string, paths ...string) string
- func DefaultOnDeviceStateChange(d entity.Device, attr entity.Attribute) error
- func DeviceLogoURL(req *http.Request, d entity.Device) string
- func DisconnectDevice(identity, pluginID string, authParams map[string]string) error
- func EndPointsManager() (manager endpoints.Manager, err error)
- func GetInfoFromDeviceAttrs(pluginID string, das DeviceInstances) (d entity.Device, err error)
- func GetInstanceControlAttributes(instance Instance) (attributes []entity.Attribute)
- func LogoURL(req *http.Request, pluginID, model, logo string) string
- func NewClient(callbacks ...OnDeviceStateChange) *client
- func NewDiscovery(cli *client) *discovery
- func NewManager() *manager
- func OTA(areaID uint64, pluginID, identity, firmwareURL string) (err error)
- 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)
- type Attribute
- type Client
- type Config
- type DeviceConfig
- type DeviceInfo
- type DeviceInstances
- 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) StopAndRemovePluginImage() (err error)
- func (p Plugin) Up() (err error)
- func (p Plugin) Update() (err error)
- func (p Plugin) UpdateOrInstall() (err error)
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 ConcatPluginPath ¶ added in v1.9.1
func DeviceLogoURL ¶ added in v1.9.1
DeviceLogoURL 设备Logo图片地址
func DisconnectDevice ¶ added in v1.5.0
func EndPointsManager ¶
func GetInfoFromDeviceAttrs ¶ added in v1.5.0
func GetInfoFromDeviceAttrs(pluginID string, das DeviceInstances) (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 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) (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
LoadPluginConfig 加载插件配置
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"` // 设备类型 Logo string `json:"logo" yaml:"logo"` // 设备logo相对路径 Control string `json:"control" yaml:"control"` // 设备控制页面相对路径 Provisioning string `json:"provisioning" yaml:"provisioning"` // 设备置网页面相对路径 PluginID string `json:"-"` }
DeviceConfig 插件设备配置
type DeviceInfo ¶ added in v1.5.0
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 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 { 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
GetPluginConfig 获取插件配置
func LoadPluginFromZip ¶
LoadPluginFromZip 从压缩包中加载插件
func NewFromEntity ¶ added in v1.5.0
func NewFromEntity(p entity.PluginInfo) Plugin
func (Plugin) StopAndRemovePluginImage ¶ added in v1.9.1
StopAndRemovePluginImage 停止插件容器并删除插件镜像
func (Plugin) UpdateOrInstall ¶ added in v1.5.0
Source Files ¶
Click to show internal directories.
Click to hide internal directories.