コード例 #1
0
 public override async Task OnDeviceTypesCreating(DeviceTypeBuilder deviceTypeBuilder)
 {
     //Sensors
     DeviceType sensor_dt = new DeviceType
         {
             UniqueIdentifier = "MQTT Device",
             Name = "MQTT Device",
             ShowInList = true
         };
     SensorTypeId = await deviceTypeBuilder.RegisterAsync(sensor_dt);
 }
コード例 #2
0
        public async Task Initialize(IFeedback<LogEntry> log, IEntityContextConnection entityContextConnection)
        {
            EntityContextConnection = entityContextConnection;
            Log = log;

            DeviceValueBuilder = new DeviceValueBuilder(entityContextConnection);
            DeviceCommandBuilder = new DeviceCommandBuilder(entityContextConnection);

            var dtb = new DeviceTypeBuilder(entityContextConnection);
            await OnDeviceTypesCreating(dtb);

            var sb = new AdapterSettingBuilder(entityContextConnection, CancellationToken);
            await OnSettingsCreating(sb);
        }
コード例 #3
0
        public async Task Initialize(IFeedback <LogEntry> log, IEntityContextConnection entityContextConnection)
        {
            EntityContextConnection = entityContextConnection;
            Log = log;

            DeviceValueBuilder   = new DeviceValueBuilder(entityContextConnection);
            DeviceCommandBuilder = new DeviceCommandBuilder(entityContextConnection);

            var dtb = new DeviceTypeBuilder(entityContextConnection);

            await OnDeviceTypesCreating(dtb);

            var sb = new AdapterSettingBuilder(entityContextConnection, CancellationToken);

            await OnSettingsCreating(sb);
        }
コード例 #4
0
ファイル: Adapter.cs プロジェクト: m19brandon/zVirtualScenes
        public override async Task OnDeviceTypesCreating(DeviceTypeBuilder deviceTypeBuilder)
        {
            //Dimmer Type Devices
            var dimmerDt = new DeviceType
            {
                UniqueIdentifier = MiLightDeviceTypes.Color.ToString(),
                Name = "MiLight Color Light",
                ShowInList = true
            };
            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "Z1TURNON",
                Name = "Zone 1, Turn On",
                ArgumentType = DataType.NONE,
                CustomData1 = "On",
                CustomData2 = "One",
                Description = "Turns Zone 1 On."
            });
            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "Z1TURNOFF",
                Name = "Zone 1, Turn Off",
                CustomData1 = "Off",
                CustomData2 = "One",
                ArgumentType = DataType.NONE,
                Description = "Turns Zone 1 Off."
            });
            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "Z2TURNON",
                Name = "Zone 2, Turn On",
                ArgumentType = DataType.NONE,
                CustomData1 = "On",
                CustomData2 = "Two",
                Description = "Turns Zone 2 On."
            });
            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "Z2TURNOFF",
                Name = "Zone 2, Turn Off",
                CustomData1 = "Off",
                CustomData2 = "Two",
                ArgumentType = DataType.NONE,
                Description = "Turns Zone 2 Off."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "Z3TURNON",
                Name = "Zone 3, Turn On",
                ArgumentType = DataType.NONE,
                CustomData1 = "On",
                CustomData2 = "Three",
                Description = "Turns Zone 3 On."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "Z3TURNOFF",
                Name = "Zone 3, Turn Off",
                CustomData1 = "Off",
                CustomData2 = "Three",
                ArgumentType = DataType.NONE,
                Description = "Turns Zone 3 Off."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "Z4TURNON",
                Name = "Zone 4, Turn On",
                ArgumentType = DataType.NONE,
                CustomData1 = "On",
                CustomData2 = "Four",
                Description = "Turns Zone 4 On."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "Z4TURNOFF",
                Name = "Zone 4, Turn Off",
                CustomData1 = "Off",
                CustomData2 = "Four",
                ArgumentType = DataType.NONE,
                Description = "Turns Zone 4 Off."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "ALLOFF",
                Name = "All Off",
                CustomData1 = "AllOff",
                CustomData2 = "",
                ArgumentType = DataType.NONE,
                Description = "Turns All Zones Off."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "ALLON",
                Name = "All On",
                CustomData1 = "AllOn",
                CustomData2 = "",
                ArgumentType = DataType.NONE,
                Description = "Turns All Zones On."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "HUE",
                Name = "Hue",
                CustomData1 = "Hue",
                CustomData2 = "",
                ArgumentType = DataType.DECIMAL,
                Description = "Changes the current zone the specified hue."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "SETBRIGHTNESS",
                Name = "SetBrightness",
                CustomData1 = "SetBrightness",
                CustomData2 = "",
                ArgumentType = DataType.INTEGER,
                Description = "Changes the current zone the specified brightness."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "EFFECTDOWN",
                Name = "Previous effect",
                ArgumentType = DataType.NONE,
                CustomData1 = "EffectDown",
                CustomData2 = "",
                Description = "Changes the current zone to the previous effect."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "EFFECTUP",
                Name = "Next Effect",
                CustomData1 = "EffectUp",
                CustomData2 = "",
                ArgumentType = DataType.NONE,
                Description = "Changes the current zone to the next effect."
            });

            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "SPEEDDOWN",
                Name = "Slower speed",
                ArgumentType = DataType.NONE,
                CustomData1 = "SpeedDown",
                CustomData2 = "",
                Description = "Changes the current effect to a slower speed."
            });
            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "SPEEDUP",
                Name = "Faster Speed",
                CustomData1 = "SpeedUp",
                CustomData2 = "",
                ArgumentType = DataType.NONE,
                Description = "Changes the current effect to a faster speed."
            });

            var dimmerSaveResult = await deviceTypeBuilder.RegisterAsync(AdapterGuid, dimmerDt, CancellationToken);
            if (dimmerSaveResult.HasError)
                await
                    Log.ReportErrorFormatAsync(CancellationToken,
                        "An error occured when registering the OpenZWave dimmer device type. {0}",
                        dimmerSaveResult.Message);

            using (var context = new ZvsContext(EntityContextConnection))
            {
                DimmerTypeId =
                    await
                        context.DeviceTypes.Where(o => o.UniqueIdentifier == MiLightDeviceTypes.Color.ToString())
                            .Select(o => o.Id)
                            .FirstOrDefaultAsync();
            }

            await base.OnDeviceTypesCreating(deviceTypeBuilder);
        }
コード例 #5
0
 public virtual Task OnDeviceTypesCreating(DeviceTypeBuilder deviceTypeBuilder)
 {
     return(Task.FromResult(0));
 }
コード例 #6
0
        public override async Task OnDeviceTypesCreating(DeviceTypeBuilder deviceTypeBuilder)
        {
            //Controller Type Devices
            var controllerDt = new DeviceType
            {
                UniqueIdentifier = OpenzWaveDeviceTypes.Controller.ToString(),
                Name = "OpenZWave Controller",
                ShowInList = true
            };
            controllerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "RESET",
                Name = "Reset Controller",
                ArgumentType = DataType.NONE,
                Description = "Erases all Z-Wave network settings from your controller. Argument2 = DeviceId."
            });
            controllerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "ADDDEVICE",
                Name = "Add Device to Network",
                ArgumentType = DataType.NONE,
                Description = "Adds a ZWave Device to your network. Argument2 = DeviceId."
            });
            controllerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "AddController",
                Name = "Add Controller to Network",
                ArgumentType = DataType.NONE,
                Description = "Adds a ZWave Controller to your network. Argument2 = DeviceId."
            });
            controllerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "CreateNewPrimary",
                Name = "Create New Primary",
                ArgumentType = DataType.NONE,
                Description = "Puts the target controller into receive configuration mode. Argument2 = DeviceId."
            });
            controllerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "ReceiveConfiguration",
                Name = "Receive Configuration",
                ArgumentType = DataType.NONE,
                Description = "Receives the network configuration from another controller. Argument2 = DeviceId."
            });
            controllerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "RemoveController",
                Name = "Remove Controller",
                ArgumentType = DataType.NONE,
                Description = "Removes a Controller from your network. Argument2 = DeviceId."
            });
            controllerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "RemoveDevice",
                Name = "Remove Device",
                ArgumentType = DataType.NONE,
                Description = "Removes a Device from your network. Argument2 = DeviceId."
            });
            controllerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "TransferPrimaryRole",
                Name = "Transfer Primary Role",
                ArgumentType = DataType.NONE,
                Description = "Transfers the primary role to another controller. Argument2 = DeviceId."
            });
            controllerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "HasNodeFailed",
                Name = "Has Node Failed",
                ArgumentType = DataType.NONE,
                Description = "Tests whether a node has failed. Argument2 = DeviceId."
            });
            controllerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "RemoveFailedNode",
                Name = "Remove Failed Node",
                ArgumentType = DataType.NONE,
                Description = "Removes the failed node from the controller's list. Argument2 = DeviceId."
            });
            controllerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "ReplaceFailedNode",
                Name = "Replace Failed Node",
                ArgumentType = DataType.NONE,
                Description = "Tests the failed node. Argument2 = DeviceId."
            });
            var result = await deviceTypeBuilder.RegisterAsync(AdapterGuid, controllerDt, CancellationToken);
            if (result.HasError)
                await
                    Log.ReportErrorFormatAsync(CancellationToken,
                        "An error occured when registering the OpenZWave controller device type. {0}", result.Message);


            //Switch Type Devices
            var switchDt = new DeviceType
            {
                UniqueIdentifier = OpenzWaveDeviceTypes.Switch.ToString(),
                Name = "OpenZWave Binary",
                ShowInList = true
            };
            switchDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "TURNON",
                Name = "Turn On",
                ArgumentType = DataType.NONE,
                Description = "Activates a switch. Argument2 = DeviceId."
            });
            switchDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "TURNOFF",
                Name = "Turn Off",
                ArgumentType = DataType.NONE,
                Description = "Deactivates a switch. Argument2 = DeviceId."
            });
            switchDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "MOMENTARY",
                Name = "Turn On for X milliseconds",
                ArgumentType = DataType.INTEGER,
                Description =
                    "Turns a device on for the specified number of milliseconds and then turns the device back off. Argument2 = DeviceId."
            });
            var switchSaveResult = await deviceTypeBuilder.RegisterAsync(AdapterGuid, switchDt, CancellationToken);
            if (switchSaveResult.HasError)
                await
                    Log.ReportErrorFormatAsync(CancellationToken,
                        "An error occured when registering the OpenZWave switch device type. {0}",
                        switchSaveResult.Message);

            //Dimmer Type Devices
            var dimmerDt = new DeviceType
            {
                UniqueIdentifier = OpenzWaveDeviceTypes.Dimmer.ToString(),
                Name = "OpenZWave Dimmer",
                ShowInList = true
            };
            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "TURNON",
                Name = "Turn On",
                ArgumentType = DataType.NONE,
                Description = "Activates a dimmer. Argument2 = DeviceId."
            });
            dimmerDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "TURNOFF",
                Name = "Turn Off",
                ArgumentType = DataType.NONE,
                Description = "Deactivates a dimmer. Argument2 = DeviceId."
            });

            var dimmerPresetCmd = new DeviceTypeCommand
            {
                UniqueIdentifier = "SETPRESETLEVEL",
                Name = "Set Level",
                ArgumentType = DataType.LIST,
                Description = "Sets a dimmer to a preset level. Argument2 = DeviceId."
            };
            dimmerPresetCmd.Options.Add(new CommandOption { Name = "0%" });
            dimmerPresetCmd.Options.Add(new CommandOption { Name = "20%" });
            dimmerPresetCmd.Options.Add(new CommandOption { Name = "40%" });
            dimmerPresetCmd.Options.Add(new CommandOption { Name = "60%" });
            dimmerPresetCmd.Options.Add(new CommandOption { Name = "80%" });
            dimmerPresetCmd.Options.Add(new CommandOption { Name = "100%" });
            dimmerPresetCmd.Options.Add(new CommandOption { Name = "255" });
            dimmerDt.Commands.Add(dimmerPresetCmd);
            var dimmerSaveResult = await deviceTypeBuilder.RegisterAsync(AdapterGuid, dimmerDt, CancellationToken);
            if (dimmerSaveResult.HasError)
                await
                    Log.ReportErrorFormatAsync(CancellationToken,
                        "An error occured when registering the OpenZWave dimmer device type. {0}",
                        dimmerSaveResult.Message);

            //Thermostat Type Devices
            var thermoDt = new DeviceType
            {
                UniqueIdentifier = OpenzWaveDeviceTypes.Thermostat.ToString(),
                Name = "OpenZWave Thermostat",
                ShowInList = true
            };
            thermoDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "SETENERGYMODE",
                Name = "Set Energy Mode",
                ArgumentType = DataType.NONE,
                Description = "Set thermostat to Energy Mode. Argument2 = DeviceId."
            });
            thermoDt.Commands.Add(new DeviceTypeCommand
            {
                UniqueIdentifier = "SETCONFORTMODE",
                Name = "Set Comfort Mode",
                ArgumentType = DataType.NONE,
                Description = "Set thermostat to Comfort Mode. (Run) Argument2 = DeviceId."
            });
            var thermoSaveResult = await deviceTypeBuilder.RegisterAsync(AdapterGuid, thermoDt, CancellationToken);
            if (thermoSaveResult.HasError)
                await
                    Log.ReportErrorFormatAsync(CancellationToken,
                        "An error occured when registering the OpenZWave thermostat device type. {0}",
                        thermoSaveResult.Message);

            var unknwonDt = new DeviceType
            {
                UniqueIdentifier = OpenzWaveDeviceTypes.Unknown.ToString(),
                Name = "OpenZWave Unknown",
                ShowInList = true
            };
            var unknownSaveResult = await deviceTypeBuilder.RegisterAsync(AdapterGuid, unknwonDt, CancellationToken);
            if (unknownSaveResult.HasError)
                await
                    Log.ReportErrorFormatAsync(CancellationToken,
                        "An error occured when registering the OpenZWave unknwon device type. {0}",
                        unknownSaveResult.Message);

            //Door Lock Type Devices
            var lockDt = new DeviceType
            {
                UniqueIdentifier = OpenzWaveDeviceTypes.Doorlock.ToString(),
                Name = "OpenZWave Door lock",
                ShowInList = true
            };
            var lockSaveResult = await deviceTypeBuilder.RegisterAsync(AdapterGuid, lockDt, CancellationToken);
            if (lockSaveResult.HasError)
                await
                    Log.ReportErrorFormatAsync(CancellationToken,
                        "An error occured when registering the OpenZWave door lock device type. {0}",
                        lockSaveResult.Message);

            //Sensors
            var sensorDt = new DeviceType
            {
                UniqueIdentifier = OpenzWaveDeviceTypes.Sensor.ToString(),
                Name = "OpenZWave Sensor",
                ShowInList = true
            };
            var sensorSaveResult = await deviceTypeBuilder.RegisterAsync(AdapterGuid, sensorDt, CancellationToken);
            if (sensorSaveResult.HasError)
                await
                    Log.ReportErrorFormatAsync(CancellationToken,
                        "An error occured when registering the OpenZWave sensor device type. {0}",
                        sensorSaveResult.Message);
            using (var context = new ZvsContext(EntityContextConnection))
            {
                ControllerTypeId = await context.DeviceTypes.Where(o => o.UniqueIdentifier == OpenzWaveDeviceTypes.Controller.ToString()).Select(o => o.Id).FirstOrDefaultAsync();
                SwitchTypeId = await context.DeviceTypes.Where(o => o.UniqueIdentifier == OpenzWaveDeviceTypes.Switch.ToString()).Select(o => o.Id).FirstOrDefaultAsync();
                DimmerTypeId = await context.DeviceTypes.Where(o => o.UniqueIdentifier == OpenzWaveDeviceTypes.Dimmer.ToString()).Select(o => o.Id).FirstOrDefaultAsync();
                ThermoTypeId = await context.DeviceTypes.Where(o => o.UniqueIdentifier == OpenzWaveDeviceTypes.Thermostat.ToString()).Select(o => o.Id).FirstOrDefaultAsync();
                UnknownTypeId = await context.DeviceTypes.Where(o => o.UniqueIdentifier == OpenzWaveDeviceTypes.Unknown.ToString()).Select(o => o.Id).FirstOrDefaultAsync();
                LockTypeId = await context.DeviceTypes.Where(o => o.UniqueIdentifier == OpenzWaveDeviceTypes.Doorlock.ToString()).Select(o => o.Id).FirstOrDefaultAsync();
                SensorTypeId = await context.DeviceTypes.Where(o => o.UniqueIdentifier == OpenzWaveDeviceTypes.Sensor.ToString()).Select(o => o.Id).FirstOrDefaultAsync();
            }
        }
コード例 #7
0
 public virtual Task OnDeviceTypesCreating(DeviceTypeBuilder deviceTypeBuilder)
 {
     return Task.FromResult(0);
 }