public void TestPropertyNotFound()
        {
            var node = new NodeInstance
            {
            };

            Assert.Equal(nameof(NodeInstance), node.TypeInfo);
            Assert.Throws <PropertyNotFoundException>(() => node.GetProperty("asdf"));
        }
示例#2
0
        public override Task <IList <NodeInstance> > Scan()
        {
            var devices = Driver.LoadDevices();
            IList <NodeInstance> ret = new List <NodeInstance>();

            foreach (var device in devices)
            {
                if (Devices.Any(a => a.Container.DeviceId == device.Id))
                {
                    continue;
                }

                NodeInstance node = null;
                switch (device.ApplicationType)
                {
                case DeviceType.Remote:
                    break;

                case DeviceType.Unknown:
                    break;

                case DeviceType.Light:
                    node = DriverContext.NodeTemplateFactory.CreateNodeInstance(IkeaTradfriFactory.LightContainerGuid);

                    var lightNode = DriverContext.NodeTemplateFactory.CreateNodeInstance(IkeaTradfriFactory.LightGuid);
                    node.InverseThis2ParentNodeInstanceNavigation.Add(lightNode);

                    var lighColorNode = DriverContext.NodeTemplateFactory.CreateNodeInstance(IkeaTradfriFactory.LightColorGuid);
                    node.InverseThis2ParentNodeInstanceNavigation.Add(lighColorNode);

                    var lightDimmerNode = DriverContext.NodeTemplateFactory.CreateNodeInstance(IkeaTradfriFactory.LightDimmerGuid);
                    node.InverseThis2ParentNodeInstanceNavigation.Add(lightDimmerNode);
                    break;

                case DeviceType.PowerOutlet:
                    node = DriverContext.NodeTemplateFactory.CreateNodeInstance(IkeaTradfriFactory.RelayContainerGuid);

                    var stateNode = DriverContext.NodeTemplateFactory.CreateNodeInstance(IkeaTradfriFactory.RelayGuid);
                    node.InverseThis2ParentNodeInstanceNavigation.Add(stateNode);
                    break;
                }

                if (node != null)
                {
                    var idProp = node.GetProperty(IkeaTradfriFactory.DeviceIdPropertyKey);
                    idProp.Value = device.Id;
                    node.Name    = device.Name;

                    ret.Add(node);
                }
            }

            return(Task.FromResult(ret));
        }
        public void TestPropertyBoolean()
        {
            var node = new NodeInstance
            {
                PropertyInstance = new List <PropertyInstance>
                {
                    CreatePropertyInstance("test", false, PropertyTemplateType.Bool)
                }
            };
            var prop = node.GetProperty("test");

            Assert.NotNull(prop.ValueBool);
            Assert.False(prop.ValueBool.Value);
        }
示例#4
0
        public override async Task <IList <NodeInstance> > Scan()
        {
            var devices = await Driver.LoadDevices();

            IList <NodeInstance> ret = new List <NodeInstance>();

            DriverContext.Logger.LogDebug($"Found {devices.Count} devices");
            foreach (var device in devices)
            {
                DriverContext.Logger.LogDebug($"Working on device {device.ID}, {device.Name} with Type {device.DeviceType}");
                if (Devices.Any(a => a.Container.DeviceId == device.ID))
                {
                    continue;
                }

                NodeInstance node = null;
                switch (device.DeviceType)
                {
                case DeviceType.Remote:
                    break;

                case DeviceType.Light:
                    node = DriverContext.NodeTemplateFactory.CreateNodeInstance(IkeaTradfriFactory.LightContainerGuid);

                    var lightNode = DriverContext.NodeTemplateFactory.CreateNodeInstance(IkeaTradfriFactory.LightGuid);
                    node.InverseThis2ParentNodeInstanceNavigation.Add(lightNode);

                    break;

                case DeviceType.ControlOutlet:
                    node = DriverContext.NodeTemplateFactory.CreateNodeInstance(IkeaTradfriFactory.RelayContainerGuid);
                    break;
                }

                if (node != null)
                {
                    var idProp = node.GetProperty(IkeaTradfriFactory.DeviceIdPropertyKey);
                    idProp.Value = device.ID;
                    node.Name    = device.Name;

                    ret.Add(node);
                }
            }

            return(ret);
        }