Exemplo n.º 1
0
        public async Task RegisterNewDeviceTypeSettingTest()
        {
            //Arrange
            var dbConnection = new UnitTestDbConnection();

            Database.SetInitializer(new CreateFreshDbInitializer());
            var adapterBuilder    = new AdapterSettingBuilder(dbConnection, CancellationToken.None);
            var deviceType        = UnitTesting.CreateFakeDeviceType();
            var deviceTypeSetting = new DeviceTypeSetting
            {
                Name       = "Device type Setting 1",
                ValueType  = DataType.STRING,
                Value      = "Hello World",
                DeviceType = deviceType
            };

            //act
            var result = await adapterBuilder.RegisterDeviceTypeSettingAsync(deviceTypeSetting);

            DeviceTypeSetting setting;

            using (var context = new ZvsContext(dbConnection))
            {
                setting = await context.DeviceTypeSettings.FirstOrDefaultAsync();
            }

            //assert
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError);
            Assert.IsNotNull(setting, "Setting not saved!");
            Assert.IsTrue(setting.Name == deviceTypeSetting.Name, "Device type setting name mismatch");
        }
Exemplo n.º 2
0
        public async Task RegisterRemovedDeviceTypeSettingOptionTest()
        {
            //Arrange
            var dbConnection = new UnitTestDbConnection();

            Database.SetInitializer(new CreateFreshDbInitializer());

            var adapterBuilder    = new AdapterSettingBuilder(dbConnection, CancellationToken.None);
            var deviceType        = UnitTesting.CreateFakeDeviceType();
            var deviceTypeSetting = new DeviceTypeSetting
            {
                Name       = "Device Type Setting 1",
                ValueType  = DataType.STRING,
                Value      = "Hello World",
                DeviceType = deviceType
            };
            var option1 = new DeviceTypeSettingOption
            {
                Name = "Option 1",
            };
            var option2 = new DeviceTypeSettingOption
            {
                Name = "Option 2",
            };

            deviceTypeSetting.Options.Add(option1);
            deviceTypeSetting.Options.Add(option2);
            using (var context = new ZvsContext(dbConnection))
            {
                context.DeviceTypeSettings.Add(deviceTypeSetting);
                await context.SaveChangesAsync();
            }

            deviceTypeSetting.Options.Remove(option2);

            //act
            var result = await adapterBuilder.RegisterDeviceTypeSettingAsync(deviceTypeSetting);

            DeviceTypeSetting setting;

            using (var context = new ZvsContext(dbConnection))
            {
                setting = await context.DeviceTypeSettings
                          .Include(o => o.Options)
                          .FirstOrDefaultAsync();
            }

            //assert
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError);
            Assert.IsNotNull(setting, "Setting not found");
            Assert.IsTrue(setting.Options.Count == 1, "Expected 2 options");
            Assert.IsTrue(setting.Options[0].Name == option1.Name, "Name mismatch");
        }
        public async Task RegisterRemovedDeviceTypeSettingOptionTest()
        {
            //Arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "asb-RegisterRemovedDeviceTypeSettingOptionTest" };
            Database.SetInitializer(new CreateFreshDbInitializer());

            var adapterBuilder = new AdapterSettingBuilder(dbConnection, CancellationToken.None);
            var deviceType = UnitTesting.CreateFakeDeviceType();
            var deviceTypeSetting = new DeviceTypeSetting
            {
                Name = "Device Type Setting 1",
                ValueType = DataType.STRING,
                Value = "Hello World",
                DeviceType = deviceType
            };
            var option1 = new DeviceTypeSettingOption
            {
                Name = "Option 1",
            };
            var option2 = new DeviceTypeSettingOption
            {
                Name = "Option 2",
            };
            deviceTypeSetting.Options.Add(option1);
            deviceTypeSetting.Options.Add(option2);
            using (var context = new ZvsContext(dbConnection))
            {
                context.DeviceTypeSettings.Add(deviceTypeSetting);
                await context.SaveChangesAsync();
            }

            deviceTypeSetting.Options.Remove(option2);

            //act
            var result = await adapterBuilder.RegisterDeviceTypeSettingAsync(deviceTypeSetting);

            DeviceTypeSetting setting;
            using (var context = new ZvsContext(dbConnection))
            {
                setting = await context.DeviceTypeSettings
                    .Include(o => o.Options)
                    .FirstOrDefaultAsync();
            }

            //assert 
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError);
            Assert.IsNotNull(setting, "Setting not found");
            Assert.IsTrue(setting.Options.Count == 1, "Expected 2 options");
            Assert.IsTrue(setting.Options[0].Name == option1.Name, "Name mismatch");
        }
        public async Task RegisterNoUpdateDeviceTypeSettingTest()
        {
            //Arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "asb-RegisterNoUpdateDeviceTypeSettingTest" };
            Database.SetInitializer(new CreateFreshDbInitializer());

            var adapterBuilder = new AdapterSettingBuilder(dbConnection, CancellationToken.None);
            var deviceType = UnitTesting.CreateFakeDeviceType();
            var deviceTypeSetting = new DeviceTypeSetting
            {
                Name = "Device Type Setting 1",
                ValueType = DataType.STRING,
                Value = "Hello World",
                DeviceType =  deviceType
            };

            using (var context = new ZvsContext(dbConnection))
            {
                context.DeviceTypeSettings.Add(deviceTypeSetting);
                await context.SaveChangesAsync();
            }

            //act
            var result = await adapterBuilder.RegisterDeviceTypeSettingAsync(deviceTypeSetting);

            DeviceTypeSetting setting;
            using (var context = new ZvsContext(dbConnection))
            {
                setting = await context.DeviceTypeSettings.FirstOrDefaultAsync();
            }

            //assert 
            Console.WriteLine(result.Message);
            Assert.IsFalse(result.HasError);
            Assert.IsNotNull(setting, "Setting not found");
            Assert.IsTrue(setting.Value == deviceTypeSetting.Value, "Device type setting name mismatch");
        }
Exemplo n.º 5
0
        public override async Task OnSettingsCreating(AdapterSettingBuilder settingBuilder)
        {
            var comSetting = new AdapterSetting
             {
                 Name = "Com Port",
                 Value = (3).ToString(CultureInfo.InvariantCulture),
                 ValueType = DataType.COMPORT,
                 Description = "The COM port that your z-wave controller is assigned to."
             };

            var pollIntSetting = new AdapterSetting
           {
               Name = "Polling interval",
               Value = (360).ToString(CultureInfo.InvariantCulture),
               ValueType = DataType.INTEGER,
               Description = "The frequency in which devices are polled for level status on your network.  Set high to avoid excessive network traffic. "
           };

            var comPortSettingResult = await settingBuilder.Adapter(this).RegisterAdapterSettingAsync(comSetting, o => o.ComportSetting);
            if (comPortSettingResult.HasError)
                await
                    Log.ReportErrorFormatAsync(CancellationToken,
                        "An error occured when registering the comport adapter setting. {0}", comPortSettingResult.Message);

            var pollIntSettingResult = await settingBuilder.Adapter(this).RegisterAdapterSettingAsync(pollIntSetting, o => o.PollingIntervalSetting);
            if (pollIntSettingResult.HasError)
                await
                    Log.ReportErrorFormatAsync(CancellationToken,
                        "An error occured when registering the polling adapter setting. {0}", pollIntSettingResult.Message);

            var dimmerOnResult = await settingBuilder.RegisterDeviceTypeSettingAsync(new DeviceTypeSetting
            {
                UniqueIdentifier = OpenzWaveDeviceTypeSettings.DefaultDimmerOnLevel.ToString(),
                DeviceTypeId = DimmerTypeId,
                Name = "Default Level",
                Description = "Level that an device is set to when using the 'ON' command.",
                Value = "99",//default value
                ValueType = DataType.BYTE
            });
            if (dimmerOnResult.HasError)
                await Log.ReportErrorFormatAsync(CancellationToken, "An error occured when registering the dimmer level setting. {0}", dimmerOnResult.Message);

            var repollLevelSetting = await settingBuilder.RegisterDeviceTypeSettingAsync(new DeviceTypeSetting
            {
                UniqueIdentifier = OpenzWaveDeviceTypeSettings.EnableRepollOnLevelChange.ToString(),
                DeviceTypeId = DimmerTypeId,
                Name = "Enable re-poll on level change",
                Description = "Re-poll dimmers 3 seconds after a level change is received?",
                Value = true.ToString(), //default value
                ValueType = DataType.BOOL
            });
            if (repollLevelSetting.HasError)
                await Log.ReportErrorFormatAsync(CancellationToken, "An error occured when registering the re-poll setting. {0}", repollLevelSetting.Message);

            var repollSetting = await settingBuilder.RegisterDeviceTypeSettingAsync(new DeviceTypeSetting
            {
                UniqueIdentifier = OpenzWaveDeviceTypeSettings.RepollingEnabled.ToString(),
                DeviceTypeId = DimmerTypeId,
                Name = "Enable polling for this device",
                Description = "Toggles automatic polling for a device.",
                Value = false.ToString(), //default value
                ValueType = DataType.BOOL
            });
            if (repollSetting.HasError)
                await Log.ReportErrorFormatAsync(CancellationToken, "An error occured when registering the re-poll setting. {0}", repollSetting.Message);

        }