开发您的第一个插件此文档形容如何开发一个简略插件,面向插件开发者。
开发前先浏览插件设计概要:智汀家庭云-开发指南Golang: 插件模块
插件实现获取sdk
go get github.com/zhiting-tech/smartassistant定义设施
package pluginimport "github.com/zhiting-tech/smartassistant/pkg/plugin/sdk/instance"type Device struct {Light instance.LightBulbInfo0 instance.Info// 依据理论设施性能组合定义 }func NewDevice() *Device {return &Device{ Light: instance.NewLightBulb(), Info0: instance.NewInfo(),} }实现设施接口
package pluginimport ("github.com/zhiting-tech/smartassistant/pkg/plugin/sdk/instance""github.com/zhiting-tech/smartassistant/pkg/plugin/sdk/server" )type Device struct {Light instance.LightBulbInfo0 instance.Info// 依据理论设施性能组合定义identity stringch server.WatchChan } func NewDevice() *Device {return &Device{Light: instance.NewLightBulb(),Info0: instance.NewInfo(),ch: make(server.WatchChan, 10),}} func (d *Device) Info() plugin.DeviceInfo { // 该办法返回设施的次要信息return d.identity }func (d *Device) Setup() error {// 设置设施的属性和相干配置(比方设施id、型号、厂商等,以及设施的属性更新触发函数)d.Info0.Identity.SetString("123456")d.Info0.Model.SetString("model")d.Info0.Manufacturer.SetString("manufacturer")d.LightBulb.Brightness.SetRange(1, 100)d.LightBulb.ColorTemp.SetRange(1000, 5000)d.LightBulb.Power.SetUpdateFunc(d.update("power"))d.LightBulb.Brightness.SetUpdateFunc(d.update("brightness"))d.LightBulb.ColorTemp.SetUpdateFunc(d.update("color_temp"))return nil}
func (d *Device) Update() error {// 该办法在获取设施所有属性值时调用,通过调用attribute.SetBool()等办法更新d.LightBulb.Power.SetString("on")d.LightBulb.Brightness.SetInt(100)d.LightBulb.ColorTemp.SetInt(2000)return nil}func (d *Device) Close() error {// 自定义退出相干资源的回收
...