github.com/e154/smart-home@v0.17.2-0.20240311175135-e530a6e5cd45/tests/models/common.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 models 20 21 import ( 22 "context" 23 24 "github.com/e154/smart-home/adaptors" 25 "github.com/e154/smart-home/common" 26 m "github.com/e154/smart-home/models" 27 ) 28 29 // NetAttr ... 30 func NetAttr() m.Attributes { 31 return m.Attributes{ 32 "s": { 33 Name: "s", 34 Type: common.AttributeString, 35 }, 36 "d": { 37 Name: "d", 38 Type: common.AttributeEncrypted, 39 }, 40 "p": { 41 Name: "p", 42 Type: common.AttributePoint, 43 }, 44 "i": { 45 Name: "i", 46 Type: common.AttributeInt, 47 }, 48 "f": { 49 Name: "f", 50 Type: common.AttributeFloat, 51 }, 52 "b": { 53 Name: "b", 54 Type: common.AttributeBool, 55 }, 56 "m": { 57 Name: "m", 58 Type: common.AttributeMap, 59 Value: m.Attributes{ 60 "s2": { 61 Name: "s2", 62 Type: common.AttributeString, 63 }, 64 "i2": { 65 Name: "i2", 66 Type: common.AttributeInt, 67 }, 68 "f2": { 69 Name: "f2", 70 Type: common.AttributeFloat, 71 }, 72 "b2": { 73 Name: "b2", 74 Type: common.AttributeBool, 75 }, 76 "m2": { 77 Name: "m2", 78 Type: common.AttributeMap, 79 Value: m.Attributes{ 80 "s3": { 81 Name: "s3", 82 Type: common.AttributeString, 83 }, 84 "i3": { 85 Name: "i3", 86 Type: common.AttributeInt, 87 }, 88 "f3": { 89 Name: "f3", 90 Type: common.AttributeFloat, 91 }, 92 "b3": { 93 Name: "b3", 94 Type: common.AttributeBool, 95 }, 96 }, 97 }, 98 }, 99 }, 100 } 101 102 } 103 104 func NetSettings() m.Attributes { 105 return m.Attributes{ 106 "s": { 107 Name: "s", 108 Type: common.AttributeString, 109 Value: "s", 110 }, 111 } 112 113 } 114 115 // AddPlugin ... 116 func AddPlugin(adaptors *adaptors.Adaptors, name string, opts ...m.AttributeValue) (err error) { 117 plugin := &m.Plugin{ 118 Name: name, 119 Version: "0.0.1", 120 Enabled: true, 121 System: true, 122 } 123 if len(opts) > 0 { 124 plugin.Settings = opts[0] 125 } 126 err = adaptors.Plugin.CreateOrUpdate(context.Background(), plugin) 127 return 128 }