github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/system/initial/local_migrations/m_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) 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 local_migrations 20 21 import ( 22 "context" 23 24 "github.com/e154/smart-home/plugins/onvif" 25 26 "github.com/e154/smart-home/plugins/alexa" 27 "github.com/e154/smart-home/plugins/cgminer" 28 "github.com/e154/smart-home/plugins/cpuspeed" 29 "github.com/e154/smart-home/plugins/email" 30 "github.com/e154/smart-home/plugins/hdd" 31 "github.com/e154/smart-home/plugins/html5_notify" 32 "github.com/e154/smart-home/plugins/logs" 33 "github.com/e154/smart-home/plugins/memory" 34 "github.com/e154/smart-home/plugins/memory_app" 35 "github.com/e154/smart-home/plugins/messagebird" 36 "github.com/e154/smart-home/plugins/modbus_rtu" 37 "github.com/e154/smart-home/plugins/modbus_tcp" 38 "github.com/e154/smart-home/plugins/moon" 39 "github.com/e154/smart-home/plugins/mqtt" 40 "github.com/e154/smart-home/plugins/node" 41 "github.com/e154/smart-home/plugins/notify" 42 "github.com/e154/smart-home/plugins/scene" 43 "github.com/e154/smart-home/plugins/sensor" 44 "github.com/e154/smart-home/plugins/slack" 45 "github.com/e154/smart-home/plugins/sun" 46 "github.com/e154/smart-home/plugins/telegram" 47 "github.com/e154/smart-home/plugins/triggers" 48 "github.com/e154/smart-home/plugins/twilio" 49 "github.com/e154/smart-home/plugins/updater" 50 "github.com/e154/smart-home/plugins/uptime" 51 "github.com/e154/smart-home/plugins/version" 52 "github.com/e154/smart-home/plugins/weather_met" 53 "github.com/e154/smart-home/plugins/weather_owm" 54 "github.com/e154/smart-home/plugins/webpush" 55 "github.com/e154/smart-home/plugins/zigbee2mqtt" 56 57 "github.com/e154/smart-home/adaptors" 58 m "github.com/e154/smart-home/models" 59 ) 60 61 type MigrationPlugins struct { 62 adaptors *adaptors.Adaptors 63 } 64 65 func NewMigrationPlugins(adaptors *adaptors.Adaptors) *MigrationPlugins { 66 return &MigrationPlugins{ 67 adaptors: adaptors, 68 } 69 } 70 71 func (n *MigrationPlugins) Up(ctx context.Context, adaptors *adaptors.Adaptors) error { 72 if adaptors != nil { 73 n.adaptors = adaptors 74 } 75 n.addPlugin("alexa", false, false, true, alexa.Version) 76 n.addPlugin("cgminer", false, false, true, cgminer.Version) 77 n.addPlugin("cpuspeed", true, false, false, cpuspeed.Version) 78 n.addPlugin("email", true, false, true, email.Version) 79 n.addPlugin("messagebird", false, false, true, messagebird.Version) 80 n.addPlugin("modbus_rtu", false, false, true, modbus_rtu.Version) 81 n.addPlugin("modbus_tcp", false, false, true, modbus_tcp.Version) 82 n.addPlugin("moon", true, false, true, moon.Version) 83 n.addPlugin("memory", true, false, false, memory.Version) 84 n.addPlugin("memory_app", true, false, false, memory_app.Version) 85 n.addPlugin("hdd", true, false, true, hdd.Version) 86 n.addPlugin("logs", true, false, false, logs.Version) 87 n.addPlugin("version", true, false, false, version.Version) 88 n.addPlugin("node", true, true, true, node.Version) 89 n.addPlugin("notify", true, true, false, notify.Version) 90 n.addPlugin("scene", true, false, true, scene.Version) 91 n.addPlugin("sensor", true, false, true, sensor.Version) 92 n.addPlugin("slack", true, false, true, slack.Version) 93 n.addPlugin("sun", true, false, true, sun.Version) 94 n.addPlugin("telegram", true, false, true, telegram.Version) 95 n.addPlugin("triggers", true, true, false, triggers.Version) 96 n.addPlugin("twilio", false, false, true, twilio.Version) 97 n.addPlugin("updater", true, false, false, updater.Version) 98 n.addPlugin("uptime", true, false, false, uptime.Version) 99 n.addPlugin("weather_met", false, false, true, weather_met.Version) 100 n.addPlugin("weather_owm", false, false, true, weather_owm.Version) 101 n.addPlugin("mqtt", true, false, true, mqtt.Version) 102 n.addPlugin("zigbee2mqtt", false, false, true, zigbee2mqtt.Version) 103 n.addPlugin("html5_notify", true, false, false, html5_notify.Version) 104 n.addPlugin("webpush", true, false, false, webpush.Version) 105 n.addPlugin("onvif", false, false, true, onvif.Version) 106 return nil 107 } 108 109 func (n *MigrationPlugins) addPlugin(name string, enabled, system, actor bool, version string) (node *m.Plugin) { 110 _ = n.adaptors.Plugin.CreateOrUpdate(context.Background(), &m.Plugin{ 111 Name: name, 112 Version: version, 113 Enabled: enabled, 114 System: system, 115 Actor: actor, 116 }) 117 return 118 }