Beispiel #1
0
            public void ContextSetup()
            {
                var groupId = Guid.NewGuid();

                _masterModel = new MasterModel();
                var project = _masterModel.CreateProject(x => x.Name = "Existing Project");

                project.CreateGroup(x => x.Id = groupId)
                .AddLight(new Light(new ZWaveValueIdentity(1, 11, 123)))
                .AddLight(new Light(new ZWaveValueIdentity(1, 12, 123)));

                _zWaveIdentity = new ZWaveValueIdentity(1, 14, 123);
                var unassignedLights = new[]
                {
                    new Light(new ZWaveValueIdentity(1, 51, 123)),
                    new Light(_zWaveIdentity),
                    new Light(new ZWaveValueIdentity(1, 53, 123))
                };

                _masterModel.AddUnassignedLights(unassignedLights);

                var repository = S <IMasterModelRepository>();

                repository.Stub(x => x.GetCurrent()).Return(_masterModel);

                var updater = new LightModelUpdater(repository);

                updater.Update(_zWaveIdentity, groupId, LightColor.Red.Value);
            }
        public StubSetModelStatusFromNetworkSwitches StubStatus(ZWaveValueIdentity identity, SwitchState switchState)
        {
            var key = MakeKey(identity);

            _stubStates[key] = switchState;
            return(this);
        }
Beispiel #3
0
            public void ContextSetup()
            {
                _group    = new MasterModel().CreateProject().CreateGroup();
                _identity = new ZWaveValueIdentity(1, 2, 123);
                _light    = new Light(_identity);

                _group.AddLight(_light);
                _group.AddLight(_light);
            }
        private Light FindLight(ZWaveValueIdentity identity, MasterModel masterModel)
        {
            var light = masterModel.AllLights
                        .SingleOrDefault(x => x.ZWaveIdentity.Equals(identity));

            if (light == null)
            {
                throw new InvalidOperationException(
                          string.Format("Could not find light with identity: {0}", identity));
            }
            return(light);
        }
Beispiel #5
0
            public void ContextSetup()
            {
                var zWaveIdentity = new ZWaveValueIdentity(11, 23, 222);

                _light            = new Light(zWaveIdentity);
                _model            = new MasterModel();
                _destinationGroup = _model.CreateProject().CreateGroup();

                _model.AddUnassignedLight(_light);

                _model.AssignLightToGroup(zWaveIdentity, _destinationGroup.Id);
            }
Beispiel #6
0
            public void ContextSetup()
            {
                var model = new MasterModel();

                _fooGroup = model.CreateProject().CreateGroup();
                _barGroup = model.CreateProject().CreateGroup();

                var zWaveIdentity = new ZWaveValueIdentity(1, 2, 123);

                _light = new Light(zWaveIdentity);
                _fooGroup.AddLight(_light);

                model.AssignLightToGroup(zWaveIdentity, _barGroup.Id);
            }
Beispiel #7
0
        public ActionResult ToggleSwitchState(uint homeId, byte nodeId, ulong valueId, SwitchState currentState)
        {
            var zWaveIdentity = new ZWaveValueIdentity(homeId, nodeId, valueId);
            var newState      = currentState == SwitchState.On ? SwitchState.Off : SwitchState.On;
            var result        = _zWaveNetwork.SetSwitchState(zWaveIdentity, newState);

            if (result.IsSuccessful)
            {
                return(Json(new { isSuccessful = true, newState = newState.ToString() }));
            }
            else
            {
                return(Json(new { isSuccessful = false, errorMessage = result.Message }));
            }
        }
Beispiel #8
0
            public void Should_find_a_light_by_homeId_and_nodeId_and_valueId()
            {
                var model = new MasterModel();

                var project1 = model.CreateProject(x => x.Name = "1");

                var group1_1   = project1.CreateGroup(x => x.Name = "1.1");
                var light1_1_1 = group1_1.AddLight(new Light(new ZWaveValueIdentity(11, 1, 123)));
                var light1_1_2 = group1_1.AddLight(new Light(new ZWaveValueIdentity(11, 2, 123)));
                var light1_1_3 = group1_1.AddLight(new Light(new ZWaveValueIdentity(11, 3, 123)));

                var group1_2   = project1.CreateGroup(x => x.Name = "1.2");
                var light1_2_1 = group1_2.AddLight(new Light(new ZWaveValueIdentity(12, 1, 123)));
                var light1_2_2 = group1_2.AddLight(new Light(new ZWaveValueIdentity(12, 2, 123)));
                var light1_2_3 = group1_2.AddLight(new Light(new ZWaveValueIdentity(12, 3, 123)));

                var group1_3   = project1.CreateGroup(x => x.Name = "1.3");
                var light1_3_1 = group1_3.AddLight(new Light(new ZWaveValueIdentity(13, 1, 123)));
                var light1_3_2 = group1_3.AddLight(new Light(new ZWaveValueIdentity(13, 2, 123)));
                var light1_3_3 = group1_3.AddLight(new Light(new ZWaveValueIdentity(13, 3, 123)));

                var project2 = model.CreateProject(x => x.Name = "1");

                var group2_1   = project2.CreateGroup(x => x.Name = "2.1");
                var light2_1_1 = group2_1.AddLight(new Light(new ZWaveValueIdentity(21, 1, 123)));
                var light2_1_2 = group2_1.AddLight(new Light(new ZWaveValueIdentity(21, 2, 123)));
                var light2_1_3 = group2_1.AddLight(new Light(new ZWaveValueIdentity(21, 3, 123)));

                var group2_2   = project2.CreateGroup(x => x.Name = "2.2");
                var light2_2_1 = group2_2.AddLight(new Light(new ZWaveValueIdentity(22, 1, 123)));

                _expectedIdentity = new ZWaveValueIdentity(22, 2, 111);
                var light2_2_2   = group2_2.AddLight(new Light(_expectedIdentity));
                var light2_2_2_2 = group2_2.AddLight(new Light(new ZWaveValueIdentity(22, 2, 222)));
                var light2_2_3   = group2_2.AddLight(new Light(new ZWaveValueIdentity(22, 3, 123)));

                var group2_3   = project2.CreateGroup(x => x.Name = "2.3");
                var light2_3_1 = group2_3.AddLight(new Light(new ZWaveValueIdentity(23, 1, 123)));
                var light2_3_2 = group2_3.AddLight(new Light(new ZWaveValueIdentity(23, 2, 123)));
                var light2_3_3 = group2_3.AddLight(new Light(new ZWaveValueIdentity(23, 3, 123)));


                var found = model.FindLight(_expectedIdentity);

                found.ZWaveIdentity.ShouldEqual(_expectedIdentity);
                found.ParentGroup.ShouldBeSameAs(group2_2);
                found.ParentGroup.ParentProject.ShouldBeSameAs(project2);
            }
Beispiel #9
0
            public void ContextSetup()
            {
                _destinationGroupId = Guid.NewGuid();
                _zWaveIdentity      = new ZWaveValueIdentity(1, 14, 123);

                var existingMasterModel = new MasterModel();
                var project             = existingMasterModel.CreateProject(x => x.Name = "Existing Project");

                project.CreateGroup(x => x.Id = _destinationGroupId)
                .AddLight(new Light(new ZWaveValueIdentity(1, 11, 123)))
                .AddLight(new Light(new ZWaveValueIdentity(1, 12, 123)));
                project.CreateGroup()
                .AddLight(new Light(new ZWaveValueIdentity(1, 13, 123)))
                .AddLight(new Light(_zWaveIdentity));

                project.CreateGroup()
                .AddLight(new Light(new ZWaveValueIdentity(1, 15, 123)))
                .AddLight(new Light(new ZWaveValueIdentity(1, 16, 123)));

                project.CreateGroup()
                .AddLight(new Light(new ZWaveValueIdentity(2, 13, 123)))
                .AddLight(new Light(new ZWaveValueIdentity(2, 14, 123)));

                var project2 = existingMasterModel.CreateProject(x => x.Name = "Existing Project 2");

                project2.CreateGroup()
                .AddLight(new Light(new ZWaveValueIdentity(1, 21, 123)))
                .AddLight(new Light(new ZWaveValueIdentity(1, 22, 123)));

                var project3 = existingMasterModel.CreateProject(x => x.Name = "Existing Project 3");

                project3.CreateGroup()
                .AddLight(new Light(new ZWaveValueIdentity(1, 31, 123)))
                .AddLight(new Light(new ZWaveValueIdentity(1, 32, 123)));


                var repository = new StubMasterModelRepository();

                repository.UseCurrentModel(existingMasterModel);

                var updater = new LightModelUpdater(repository);

                updater.Update(_zWaveIdentity, _destinationGroupId, LightColor.Red.Value);

                _saved = repository.LastSaved;
            }
Beispiel #10
0
            public void ContextSetup()
            {
                var model = new MasterModel();
                var group = model.CreateProject().CreateGroup();

                _identity1 = new ZWaveValueIdentity(1, 11, 123);
                _identity2 = new ZWaveValueIdentity(2, 22, 123);
                _identity3 = new ZWaveValueIdentity(3, 33, 123);
                _identity4 = new ZWaveValueIdentity(4, 44, 123);

                group
                .AddLight(new Light(_identity1))
                .AddLight(new Light(_identity2));
                model.AddUnassignedLights(new[] { new Light(_identity3), new Light(_identity4) });

                _result = model.AllLights;
            }
            public void ContextSetup()
            {
                var repo = S <IMasterModelRepository>();

                _model = new MasterModel();
                var group = _model.CreateProject().CreateGroup();

                _identityForOffSwitch = new ZWaveValueIdentity(3, 11, 123);
                group.AddLight(new Light(_identityForOffSwitch));
                group.AddLight(new Light(new ZWaveValueIdentity(3, 22, 123)));
                group.AddLight(new Light(new ZWaveValueIdentity(3, 33, 123)));
                group.AddLight(new Light(new ZWaveValueIdentity(3, 44, 123)));
                repo.Stub(x => x.GetCurrent()).Return(_model);

                _setModelStatusFromNetworkSwitches = new StubSetModelStatusFromNetworkSwitches().DefaultStatus(SwitchState.On).StubStatus(_identityForOffSwitch, SwitchState.Off);

                var statusProvider = new SystemStatusProvider(repo, _setModelStatusFromNetworkSwitches);

                _result = statusProvider.GetSystemStatus();
            }
        public void Update(ZWaveValueIdentity identity, Guid groupId, int colorId)
        {
            var masterModel = _masterModelRepository.GetCurrent();
            var light       = FindLight(identity, masterModel);

            //Set color
            light.Color = LightColor.FromValue(colorId);

            //Set group
            if (groupId == Guid.Empty)
            {
                light.Unassign();
                masterModel.AddUnassignedLight(light);
            }
            else
            {
                masterModel.AssignLightToGroup(identity, groupId);
            }

            //Save
            _masterModelRepository.Save(masterModel);
        }
Beispiel #13
0
            public void ContextSetup()
            {
                var masterModel = new MasterModel();
                var project     = masterModel.CreateProject(x => x.Name = "Existing Project");

                var zWaveIdentity = new ZWaveValueIdentity(1, 11, 5555);

                project.CreateGroup().AddLight(new Light(zWaveIdentity)
                {
                    Color = LightColor.Yellow
                });

                var repository = new StubMasterModelRepository();

                repository.UseCurrentModel(masterModel);

                var updater = new LightModelUpdater(repository);

                updater.Update(zWaveIdentity, Guid.Empty, LightColor.Red.Value);

                _lastSaved = repository.LastSaved;
            }
Beispiel #14
0
        public ZWaveOperationResult SetSwitchState(ZWaveValueIdentity identity, SwitchState state)
        {
            var node = _nodeList.AllNodes.SingleOrDefault(x => x.NodeIdentity.Equals(identity.NodeIdentity));

            if (node == null)
            {
                var message = string.Format("Could not locate a node with HomeId {0} and NodeId {1}",
                                            identity.HomeId, identity.NodeId);
                return(ZWaveOperationResult.Fail(message));
            }

            var value = node.Values.SingleOrDefault(x => x.GetId().Equals(identity.ValueId));

            if (value == null)
            {
                var message = string.Format("Could not locate a value for {0}", identity);
                return(ZWaveOperationResult.Fail(message));
            }

            var switchValueBool = state == SwitchState.On;

            _manager.SetValue(value, switchValueBool);
            return(ZWaveOperationResult.Success);
        }
Beispiel #15
0
 public ZWaveOperationResult SetSwitchState(ZWaveValueIdentity identity, SwitchState state)
 {
     _switches[identity] = state;
     return(ZWaveOperationResult.Success);
 }
Beispiel #16
0
 public Light(ZWaveValueIdentity identity)
 {
     SwitchState   = SwitchState.Unknown;
     Color         = LightColor.Unknown;
     ZWaveIdentity = identity;
 }
Beispiel #17
0
 private void VerifySwitchState(ZWaveValueIdentity zWaveIdentity, SwitchState switchState)
 {
     _switches.Single(x => x.ZWaveIdentity.Equals(zWaveIdentity)).SwitchState.ShouldEqual(switchState);
 }
 private static string MakeKey(ZWaveValueIdentity identity)
 {
     return(identity.ToString());
 }
Beispiel #19
0
 public ZWaveSwitch(ZWaveValueIdentity identity)
 {
     ZWaveIdentity = identity;
 }
Beispiel #20
0
 public ZWaveOperationResult SetSwitchState(ZWaveValueIdentity identity, SwitchState state)
 {
     return(ZWaveOperationResult.Fail("ZWave Network is not connected."));
 }
Beispiel #21
0
 protected bool Equals(ZWaveValueIdentity other)
 {
     return(HomeId == other.HomeId && NodeId == other.NodeId && ValueId == other.ValueId);
 }