github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/plugins/twilio/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 twilio 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.twilio") 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 actor *Actor 50 } 51 52 // New ... 53 func New() supervisor.Pluggable { 54 p := &plugin{ 55 Plugin: supervisor.NewPlugin(), 56 } 57 p.F = F 58 return p 59 } 60 61 // Load ... 62 func (p *plugin) Load(ctx context.Context, service supervisor.Service) (err error) { 63 if err = p.Plugin.Load(ctx, service, p.ActorConstructor); err != nil { 64 return 65 } 66 return 67 } 68 69 // Unload ... 70 func (p *plugin) Unload(ctx context.Context) (err error) { 71 if err = p.Plugin.Unload(ctx); err != nil { 72 return 73 } 74 return nil 75 } 76 77 // ActorConstructor ... 78 func (p *plugin) ActorConstructor(entity *m.Entity) (actor supervisor.PluginActor, err error) { 79 actor = NewActor(entity, p.Service) 80 return 81 } 82 83 // Name ... 84 func (p *plugin) Name() string { 85 return Name 86 } 87 88 // Type ... 89 func (p *plugin) Type() supervisor.PluginType { 90 return supervisor.PluginInstallable 91 } 92 93 // Depends ... 94 func (p *plugin) Depends() []string { 95 return []string{notify.Name} 96 } 97 98 // Version ... 99 func (p *plugin) Version() string { 100 return Version 101 } 102 103 // Options ... 104 func (p *plugin) Options() m.PluginOptions { 105 return m.PluginOptions{ 106 Actors: true, 107 ActorAttrs: NewAttr(), 108 ActorSetts: NewSettings(), 109 } 110 }