public override async Task OnSettingsCreating(PluginSettingBuilder settingBuilder)
        {
            var annouceoptionssetting = new PluginSetting
            {
                Name = "Announce options",
                Value = "Level",
                ValueType = DataType.LIST,
                Description = "Select the values you would like announced."
            };
            annouceoptionssetting.Options.Add(new PluginSettingOption { Name = "Switch Level" });
            annouceoptionssetting.Options.Add(new PluginSettingOption { Name = "Dimmer Level" });
            annouceoptionssetting.Options.Add(new PluginSettingOption { Name = "Thermostat Operating State and Temp" });
            annouceoptionssetting.Options.Add(new PluginSettingOption { Name = "All of the above" });
            annouceoptionssetting.Options.Add(new PluginSettingOption { Name = "Custom" });

            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(annouceoptionssetting, o => o.AnnounceOptionSetting);

            var customsetting = new PluginSetting
           {
               Name = "Announce on custom values",
               Value = "dimmer:Basic, thermostat:Temperature, switch:Basic, thermostat:Operating State",
               ValueType = DataType.STRING,
               Description = "Include all values you would like announced. (DEVICE_TYPE_NAME:VALUE_LABEL_NAME) Comma Separated."
           };

            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(customsetting, o => o.CustomAnnounceSetting);
        }
        public async Task RegisterPluginSettingPluginTest()
        {
            //Arrange 
            var dbConnection = new UnitTestDbConnection();
            Database.SetInitializer(new CreateFreshDbInitializer());
            var pluginBuilder = new PluginSettingBuilder(dbConnection, CancellationToken.None);
            var dbPlugin = UnitTesting.CreateFakePlugin();
            using (var context = new ZvsContext(dbConnection))
            {
                context.Plugins.Add(dbPlugin);
                await context.SaveChangesAsync();
            }
            var plugin = new StubUnitTestPlugin
            {
                PluginGuidGet = () => dbPlugin.PluginGuid
            };

            var pluginSetting = new PluginSetting
            {
                Name = "Plugin Setting 1",
                ValueType = DataType.STRING,
                Value = "Hello World"
            };
               
            //act
            var result = await pluginBuilder.Plugin(plugin).RegisterPluginSettingAsync(pluginSetting, o => o.PropertyTest);

            Plugin a;
            using (var context = new ZvsContext(dbConnection))
            {
                a = await context.Plugins
                    .Include(o=> o.Settings)
                    .FirstOrDefaultAsync(o => o.PluginGuid == dbPlugin.PluginGuid);
            }

            //assert 
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError);
            Assert.IsTrue(a.Settings.Count == 1, "Expected 1 plugin setting");
            Assert.IsTrue(a.Settings[0].Name == pluginSetting.Name, "Plugin setting name mismatch");
        }
示例#3
0
        public override async Task OnSettingsCreating(PluginSettingBuilder settingBuilder)
        {
            var annouceoptionssetting = new PluginSetting
            {
                Name = "Host",
                Value = "mqtt.myserver.com",
                ValueType = DataType.STRING,
                Description = "Enter the Host name for the broker."
            };

            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(annouceoptionssetting, o => o.HostSetting);


            var portSetting = new PluginSetting
            {
                Name = "Port",
                Value = "1883",
                ValueType = DataType.INTEGER,
                Description = "Enter the port for the broker."
            };

            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(portSetting, o => o.Port);


            var userNameSetting = new PluginSetting
            {
                Name = "Username",
                Value = "admin",
                ValueType = DataType.STRING,
                Description = "Enter the username for the broker."
            };

            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(userNameSetting, o => o.UserName);


            var passwordSetting = new PluginSetting
            {
                Name = "Password",
                Value = "brokerpassword",
                ValueType = DataType.STRING,
                Description = "Enter the password for the broker."
            };

            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(passwordSetting, o => o.Password);


            var topicSetting = new PluginSetting
            {
                Name = "Topic",
                Value = "zvirtual/{NodeNumber}/events",
                ValueType = DataType.STRING,
                Description = "Enter the topic for changes to be published to, on the broker."
            };

            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(topicSetting, o => o.TopicFormat);



            var floodTopicSetting = new PluginSetting
            {
                Name = "Flood Topic",
                Value = "zvirtual/events",
                ValueType = DataType.STRING,
                Description = "Enter the topic name for all messages to get pushed to."
            };

            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(floodTopicSetting, o => o.FloodTopic);


            var controlTopicSetting = new PluginSetting
            {
                Name = "Device Control Topic",
                Value = "zvirtual/control",
                ValueType = DataType.STRING,
                Description = "Enter the control topic for all devices."
            };

            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(controlTopicSetting, o => o.ControlTopicFormat);


        }
        public override async Task OnSettingsCreating(PluginSettingBuilder settingBuilder)
        {
            var portSetting = new PluginSetting
                {
                    Name = "Port",
                    Value = (1337).ToString(),
                    ValueType = DataType.INTEGER,
                    Description = "LightSwitch will listen for connections on this port."
                };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(portSetting, o => o.PortSetting);

            var maxConnSetting = new PluginSetting
                {
                    Name = "Max Conn.",
                    Value = (200).ToString(),
                    ValueType = DataType.INTEGER,
                    Description = "The maximum number of connections allowed."
                };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(maxConnSetting, o => o.MaxConnectionsSettings);

            var verboseSettings = new PluginSetting
                 {
                     Name = "Verbose Logging",
                     Value = false.ToString(),
                     ValueType = DataType.BOOL,
                     Description = "(Writes all server client communication to the log for debugging.)"
                 };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(verboseSettings, o => o.VerboseSetting);

            var passwordSetting = new PluginSetting
                 {
                     Name = "Password",
                     Value = "ChaNgeMe444",
                     ValueType = DataType.STRING,
                     Description = "The password clients must use to connect to the LightSwitch server. "
                 };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(passwordSetting, o => o.PasswordSetting);

            var sortSetting = new PluginSetting
                {
                    Name = "Sort Device List",
                    Value = true.ToString(),
                    ValueType = DataType.BOOL,
                    Description = "(Alphabetically sorts the device list.)"
                };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(sortSetting, o => o.SortListSetting);

            var bonjourSetting = new PluginSetting
             {
                 Name = "Publish ZeroConf/Bonjour",
                 Value = false.ToString(),
                 ValueType = DataType.BOOL,
                 Description = "Zero configuration networking allows clients on your network to detect and connect to your LightSwitch server automatically."
             };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(bonjourSetting, o => o.UseBonjourSetting);

        }
示例#5
0
        public override async Task OnSettingsCreating(PluginSettingBuilder settingBuilder)
        {
            var latSetting = new PluginSetting
            {
                UniqueIdentifier = "LAT",
                Name = "Latitude",
                Value = "37.6772222222222",
                ValueType = DataType.DECIMAL,
                Description = "Your Latitude in Decimal Notation. ex. 37.6772222222222"
            };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(latSetting, o => o.LatitudeSetting);

            var longSetting = new PluginSetting
            {
                UniqueIdentifier = "LOG",
                Name = "Longitude",
                Value = "-113.061666666667",
                ValueType = DataType.DECIMAL,
                Description = "Your Longitude in Decimal Notation. ex. -113.061666666667"
            };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(longSetting, o => o.LongitudeSetting);

            var delaySunriseSetting = new PluginSetting
            {
                UniqueIdentifier = "DELAY_SUNRISE",
                Name = "Minutes to delay sunrise",
                Value = "0",
                ValueType = DataType.DECIMAL,
                Description = "The minutes to delay sunrise as a positive or negative number"
            };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(delaySunriseSetting, o => o.SunriseDelaySetting);

            var delaySunsetSetting = new PluginSetting
            {
                UniqueIdentifier = "DELAY_SUNSET",
                Name = "Minutes to delay sunset",
                Value = "0",
                ValueType = DataType.DECIMAL,
                Description = "The minutes to delay sunset as a positive or negative number"
            };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(delaySunsetSetting, o => o.SunsetDelaySetting);
        }
        public override async Task OnSettingsCreating(PluginSettingBuilder settingBuilder)
        {
            var portSetting = new PluginSetting
                {
                    Name = "HTTP Port",
                    Value = "80",
                    ValueType = DataType.INTEGER,
                    Description = "The port that HTTP will listen for commands on."
                };

            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(portSetting, o => o.PortSetting);

            var sslSetting = new PluginSetting
                {
                    Name = "HTTP Secure (SSL)",
                    Value = true.ToString(),
                    ValueType = DataType.BOOL,
                    Description = "If the HTTP Server will be over SSL."
                };

            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(sslSetting, o => o.UseSslSetting);

            var tokenSetting = new PluginSetting
               {
                   Name = "X-zvsTokens",
                   Value = "CC2D226814CBC713134BD9D09B892F10A9, A0689CEF6BA3AD5FAFE018F2D796FF",
                   ValueType = DataType.STRING,
                   Description = "A comma delimited list of X-zvsTokens.  A valid X-zvsToken must be sent in the header of each API command to authorize access."
               };

            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(tokenSetting, o => o.TokensSettings);

            var verboseSettings = new PluginSetting
                {
                    Name = "Verbose Logging",
                    Value = false.ToString(),
                    ValueType = DataType.BOOL,
                    Description = "(Writes all server client communication to the log for debugging.)"
                };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(verboseSettings, o => o.VerboseSetting);
        }
        public async Task LoadPluginsAsyncAutoStartTest()
        {
            //Arrange 
            var dbConnection = new UnitTestDbConnection();
            Database.SetInitializer(new CreateFreshDbInitializer());

            var log = new StubIFeedback<LogEntry>
            {
                ReportAsyncT0CancellationToken = (e, c) =>
                {
                    Console.WriteLine(e.ToString());
                    return Task.FromResult(0);
                }
            };

            var plugin = new Plugin()
            {
                PluginGuid = Guid.Parse("a0f912a6-b8bb-406a-360f-1eb13f50aae4"),
                IsEnabled = true
            };
            using (var context = new ZvsContext(dbConnection))
            {
                context.Plugins.Add(plugin);
                await context.SaveChangesAsync(CancellationToken.None);
            }
            var isStarted = false;
            var unitTestingPlugin = new StubUnitTestPlugin
            {
                PluginGuidGet = () => Guid.Parse("a0f912a6-b8bb-406a-360f-1eb13f50aae4"),
                NameGet = () => "Unit Testing Plugin",
                DescriptionGet = () => "",
                OnSettingsCreatingPluginSettingBuilder = s => Task.FromResult(0),
                OnDeviceSettingsCreatingDeviceSettingBuilder = s => Task.FromResult(0),
                OnSceneSettingsCreatingSceneSettingBuilder = s => Task.FromResult(0),
                StartAsync01 = () =>
                {
                    isStarted = true;
                    return Task.FromResult(0);
                }
            };
            unitTestingPlugin.OnSettingsCreatingPluginSettingBuilder = async settingBuilder =>
            {
                var testSetting = new PluginSetting
                {
                    Name = "Test setting",
                    Value = 360.ToString(CultureInfo.InvariantCulture),
                    ValueType = DataType.INTEGER,
                    Description = "Unit testing only"
                };

                await
                    settingBuilder.Plugin(unitTestingPlugin)
                        .RegisterPluginSettingAsync(testSetting, o => o.PropertyTest);
            };

            var pluginManager = new PluginManager(new List<ZvsPlugin> { unitTestingPlugin }, dbConnection, log, new StubIAdapterManager());

            //act
            await pluginManager.StartAsync(CancellationToken.None);

            //assert 
            Assert.IsTrue(isStarted, "Plugin not started!");
        }
        public async Task RegisterPluginSettingOptionRemovedTest()
        {
            //Arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "asb-RegisterPluginSettingOptionRemovedTest" };
            Database.SetInitializer(new CreateFreshDbInitializer());
            var pluginBuilder = new PluginSettingBuilder( dbConnection, CancellationToken.None);
            var dbPlugin = UnitTesting.CreateFakePlugin();

            var pluginSetting = new PluginSetting
            {
                Name = "Plugin Setting 1",
                ValueType = DataType.STRING,
                Value = "Hello World",
                UniqueIdentifier = "PropertyTest"
            };
            dbPlugin.Settings.Add(pluginSetting);
            var option1 = new PluginSettingOption
            {
                Name = "Option 1",
            };
            var option2 = new PluginSettingOption
            {
                Name = "Option 2",
            };
            pluginSetting.Options.Add(option1);
            pluginSetting.Options.Add(option2);
            using (var context = new ZvsContext(dbConnection))
            {
                context.Plugins.Add(dbPlugin);
                await context.SaveChangesAsync();
            }
            var plugin = new StubUnitTestPlugin
            {
                PluginGuidGet = () => dbPlugin.PluginGuid
            };
            pluginSetting.Options.Remove(option2);

            //act
            var result = await pluginBuilder.Plugin(plugin).RegisterPluginSettingAsync(pluginSetting, o => o.PropertyTest);

            PluginSetting a;
            using (var context = new ZvsContext(dbConnection))
            {
                a = await context.PluginSettings
                    .Include(o => o.Options)
                    .FirstOrDefaultAsync(o => o.Id == pluginSetting.Id);
            }

            //assert 
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError);
            Assert.IsTrue(a.Options.Count == 1, "Expected 2 plugin setting options");
            Assert.IsTrue(a.Options[0].Name == option1.Name, "Plugin option name mismatch");
        }
        public async Task RegisterPluginSettingValueDonestTriggerChangedTest()
        {
            //Arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "asb-RegisterPluginSettingValueDonestTriggerChangedTest" };
            Database.SetInitializer(new CreateFreshDbInitializer());
            var pluginBuilder = new PluginSettingBuilder( dbConnection, CancellationToken.None);
            var dbPlugin = UnitTesting.CreateFakePlugin();

            var pluginSetting = new PluginSetting
            {
                Name = "Plugin Setting 1",
                ValueType = DataType.STRING,
                Value = "Hello World",
                UniqueIdentifier = "PropertyTest"
            };
            dbPlugin.Settings.Add(pluginSetting);
            using (var context = new ZvsContext(dbConnection))
            {
                context.Plugins.Add(dbPlugin);
                await context.SaveChangesAsync();
            }
            var plugin = new StubUnitTestPlugin
            {
                PluginGuidGet = () => dbPlugin.PluginGuid
            };

            pluginSetting.Value = "New value!";

            //act
            var result = await pluginBuilder.Plugin(plugin).RegisterPluginSettingAsync(pluginSetting, o => o.PropertyTest);

            Plugin a;
            using (var context = new ZvsContext(dbConnection))
            {
                a = await context.Plugins
                    .Include(o => o.Settings)
                    .FirstOrDefaultAsync(o => o.PluginGuid == dbPlugin.PluginGuid);
            }

            //assert 
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError);
            Assert.IsTrue(a.Settings.Count == 1, "Expected 1 plugin setting");
            Assert.IsTrue(a.Settings[0].Value == "Hello World", "Plugin value changed when it shouldn't!");
        }
        public async Task StopTest()
        {
            //Arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "am-StopTest" };
            Database.SetInitializer(new CreateFreshDbInitializer());
            var logEntries = new List<LogEntry>();
            var log = new StubIFeedback<LogEntry>
            {
                ReportAsyncT0CancellationToken = (e, c) =>
                {
                    logEntries.Add(e);
                    Console.WriteLine(e.ToString());
                    return Task.FromResult(0);
                }
            };

            var plugin = new Plugin()
            {
                PluginGuid = Guid.Parse("a0f912a6-b8bb-406a-360f-1eb13f50aae4"),
                IsEnabled = true
            };
            using (var context = new ZvsContext(dbConnection))
            {
                context.Plugins.Add(plugin);
                await context.SaveChangesAsync(CancellationToken.None);
            }
            var isStartedCount = 0;
            var isStoppedCount = 0;
            var unitTestingPlugin = new StubUnitTestPlugin
            {
                PluginGuidGet = () => Guid.Parse("a0f912a6-b8bb-406a-360f-1eb13f50aae4"),
                NameGet = () => "Unit Testing Plugin",
                DescriptionGet = () => "",
                OnSettingsCreatingPluginSettingBuilder = (s) => Task.FromResult(0),
                OnDeviceSettingsCreatingDeviceSettingBuilder = (s) => Task.FromResult(0),
                OnSceneSettingsCreatingSceneSettingBuilder = (s) => Task.FromResult(0),
                StartAsync01 = () =>
                {
                    isStartedCount++;
                    return Task.FromResult(0);
                },
                StopAsync01 = () =>
                {
                    isStoppedCount++;
                    return Task.FromResult(0);
                }
            };
            unitTestingPlugin.OnSettingsCreatingPluginSettingBuilder = async (settingBuilder) =>
            {
                var testSetting = new PluginSetting
                {
                    Name = "Test setting",
                    Value = 360.ToString(CultureInfo.InvariantCulture),
                    ValueType = DataType.INTEGER,
                    Description = "Unit testing only"
                };

                await
                    settingBuilder.Plugin(unitTestingPlugin)
                        .RegisterPluginSettingAsync(testSetting, o => o.PropertyTest);
            };

            var pluginManager = new PluginManager(new List<ZvsPlugin> { unitTestingPlugin }, dbConnection, log, new StubIAdapterManager());

            //act
            await pluginManager.StartAsync(CancellationToken.None);
            await pluginManager.StopAsync(CancellationToken.None);

            //assert 
            Assert.IsTrue(logEntries.All(o => o.Level == LogEntryLevel.Info), "Not all log entries are info level");
            Assert.IsTrue(isStartedCount == 1, "Plugin started too many or too few times");
            Assert.IsTrue(isStoppedCount == 1, "Plugin stopped too many or too few times");
        }
        public override async Task OnSettingsCreating(PluginSettingBuilder settingBuilder)
        {
            var apiKey = new PluginSetting
            {
                UniqueIdentifier = "APIWRITEKEY",
                Name = "Write API Key",
                Value = "",
                ValueType = DataType.STRING,
                Description = "Write API Key from your channel on https://thingspeak.com/"
            };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(apiKey, o => o.ApiKey);

            var feild1 = new PluginSetting
            {
                UniqueIdentifier = "FIELD1",
                Name = "Field1 Device",
                Value = "",
                ValueType = DataType.STRING,
                Description = "The Value will be which zVirtual Device name you want mapped to ThingSpeak's field"
            };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(feild1, o => o.Field1);

            var feild2 = new PluginSetting
            {
                UniqueIdentifier = "FIELD2",
                Name = "Field2 Device",
                Value = "",
                ValueType = DataType.STRING,
                Description = "The Value will be which zVirtual Device name you want mapped to ThingSpeak's field"
            };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(feild2, o => o.Field2);

            var feild3 = new PluginSetting
            {
                UniqueIdentifier = "FIELD3",
                Name = "Field3 Device",
                Value = "",
                ValueType = DataType.STRING,
                Description = "The Value will be which zVirtual Device name you want mapped to ThingSpeak's field"
            };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(feild3, o => o.Field3);

            var feild4 = new PluginSetting
            {
                UniqueIdentifier = "FIELD4",
                Name = "Field4 Device",
                Value = "",
                ValueType = DataType.STRING,
                Description = "The Value will be which zVirtual Device name you want mapped to ThingSpeak's field"
            };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(feild4, o => o.Field4);

            var feild5 = new PluginSetting
            {
                UniqueIdentifier = "FIELD5",
                Name = "Field5 Device",
                Value = "",
                ValueType = DataType.STRING,
                Description = "The Value will be which zVirtual Device name you want mapped to ThingSpeak's field"
            };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(feild5, o => o.Field5);

            var feild6 = new PluginSetting
            {
                UniqueIdentifier = "FIELD6",
                Name = "Field6 Device",
                Value = "",
                ValueType = DataType.STRING,
                Description = "The Value will be which zVirtual Device name you want mapped to ThingSpeak's field"
            };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(feild6, o => o.Field6);

            var feild7 = new PluginSetting
            {
                UniqueIdentifier = "FIELD7",
                Name = "Field7 Device",
                Value = "",
                ValueType = DataType.STRING,
                Description = "The Value will be which zVirtual Device name you want mapped to ThingSpeak's field"
            };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(feild7, o => o.Field7);

            var feild8 = new PluginSetting
            {
                UniqueIdentifier = "FIELD8",
                Name = "Field8 Device",
                Value = "",
                ValueType = DataType.STRING,
                Description = "The Value will be which zVirtual Device name you want mapped to ThingSpeak's field"
            };
            await settingBuilder.Plugin(this).RegisterPluginSettingAsync(feild8, o => o.Field8);
        }