github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/plugins/messagebird/plugin.go (about) 1 // This file is part of the Smart Home 2 // Program complex distribution https://github.com/e154/smart-home 3 // Copyright (C) 2016-2023, Filippov Alex 4 // 5 // This library is free software: you can redistribute it and/or 6 // modify it under the terms of the GNU Lesser General Public 7 // License as published by the Free Software Foundation; either 8 // version 3 of the License, or (at your option) any later version. 9 // 10 // This library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 // Library General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public 16 // License along with this library. If not, see 17 // <https://www.gnu.org/licenses/>. 18 19 package messagebird 20 21 import ( 22 "context" 23 "embed" 24 25 "github.com/e154/smart-home/system/supervisor" 26 27 "github.com/e154/smart-home/common/logger" 28 29 m "github.com/e154/smart-home/models" 30 "github.com/e154/smart-home/plugins/notify" 31 ) 32 33 var ( 34 log = logger.MustGetLogger("plugins.messagebird") 35 ) 36 37 var _ supervisor.Pluggable = (*plugin)(nil) 38 39 //go:embed Readme.md 40 //go:embed Readme.ru.md 41 var F embed.FS 42 43 func init() { 44 supervisor.RegisterPlugin(Name, New) 45 } 46 47 type plugin struct { 48 *supervisor.Plugin 49 } 50 51 // New ... 52 func New() supervisor.Pluggable { 53 p := &plugin{ 54 Plugin: supervisor.NewPlugin(), 55 } 56 p.F = F 57 return p 58 } 59 60 // Load ... 61 func (p *plugin) Load(ctx context.Context, service supervisor.Service) (err error) { 62 if err = p.Plugin.Load(ctx, service, p.ActorConstructor); err != nil { 63 return 64 } 65 return 66 } 67 68 // Unload ... 69 func (p *plugin) Unload(ctx context.Context) (err error) { 70 if err = p.Plugin.Unload(ctx); err != nil { 71 return 72 } 73 return nil 74 } 75 76 // ActorConstructor ... 77 func (p *plugin) ActorConstructor(entity *m.Entity) (actor supervisor.PluginActor, err error) { 78 actor = NewActor(entity, p.Service) 79 return 80 } 81 82 // Name ... 83 func (p *plugin) Name() string { 84 return Name 85 } 86 87 // Type ... 88 func (p *plugin) Type() supervisor.PluginType { 89 return supervisor.PluginInstallable 90 } 91 92 // Depends ... 93 func (p *plugin) Depends() []string { 94 return []string{notify.Name} 95 } 96 97 // Version ... 98 func (p *plugin) Version() string { 99 return Version 100 } 101 102 // Options ... 103 func (p *plugin) Options() m.PluginOptions { 104 return m.PluginOptions{ 105 Actors: true, 106 ActorAttrs: NewAttr(), 107 ActorSetts: NewSettings(), 108 } 109 }