Exemple #1
0
        private async Task OnLoggedIn()
        {
            State = NestViewModelState.Loading;

            var result = await _nestWebService.UpdateTransportUrlAsync();

            if (IsErrorHandled(result.Error, result.Exception))
            {
                return;
            }

            _getStatusResult = await _nestWebService.GetFullStatusAsync();

            if (IsErrorHandled(_getStatusResult.Error, _getStatusResult.Exception))
            {
                return;
            }

            State = NestViewModelState.LoggedIn;

            UpdateViewModelFromGetStatusResult(_getStatusResult);

            _statusUpdater.CurrentStructure = _getStatusResult.Structures.ElementAt(0);
            _statusUpdater.Start();
            _statusProvider.Start();
        }
Exemple #2
0
            public async Task ShouldReturnErrorWhenGetResponseFails()
            {
                _webRequest.Setup(r => r.GetResponseAsync()).Throws(new Exception());
                _webServiceDeserializer.Setup(d => d.ParseWebServiceErrorAsync(It.IsAny <Exception>())).Returns(Task.FromResult(WebServiceError.SessionTokenExpired));

                GetStatusResult result = await _webService.GetStructureAndDeviceStatusAsync(new Structure(""));

                Assert.AreEqual(WebServiceError.SessionTokenExpired, result.Error);
            }
Exemple #3
0
            public void ShouldNotBeLoggingInOnServerNotFoundException()
            {
                var result = new GetStatusResult(WebServiceError.ServerNotFound, new Exception());
                var args   = new StatusEventArgs(result);

                _statusProvider.Raise(provider => provider.StatusUpdated += null, args);

                Assert.IsFalse(_viewModel.IsLoggingIn);
            }
Exemple #4
0
            public void ShouldNotBeLoggedInOnInvalidCredentialsException()
            {
                var result = new GetStatusResult(WebServiceError.InvalidCredentials, new Exception());
                var args   = new StatusEventArgs(result);

                _statusProvider.Raise(provider => provider.StatusUpdated += null, args);

                Assert.IsFalse(_viewModel.IsLoggedIn);
            }
Exemple #5
0
            public void ShouldClearSessionOnInvalidCredentialsException()
            {
                var result = new GetStatusResult(WebServiceError.InvalidCredentials, new Exception());
                var args   = new StatusEventArgs(result);

                _statusProvider.Raise(provider => provider.StatusUpdated += null, args);

                _sessionProvider.Verify(provider => provider.ClearSession(), "Expected session to be cleared when an InvalidCredentials exception occurs.");
            }
Exemple #6
0
            public void ShouldBeLoggingInOnSessionTokenExpiredException()
            {
                var result = new GetStatusResult(WebServiceError.SessionTokenExpired, new Exception());
                var args   = new StatusEventArgs(result);

                _statusProvider.Raise(provider => provider.StatusUpdated += null, args);

                Assert.IsTrue(_viewModel.IsLoggingIn);
            }
Exemple #7
0
            public void ShouldBeInErrorStateOnAnyOtherException()
            {
                var result = new GetStatusResult(WebServiceError.Unknown, new InvalidCastException());
                var args   = new StatusEventArgs(result);

                _statusProvider.Raise(provider => provider.StatusUpdated += null, args);

                Assert.IsTrue(_viewModel.IsInErrorState);
            }
Exemple #8
0
 public EzGetStatusResult(
     GetStatusResult result
     )
 {
     if (result.item != null)
     {
         Item = new EzStatus(result.item);
     }
 }
Exemple #9
0
            public void ShouldBeInErrorStateOnServerNotFoundException()
            {
                var result = new GetStatusResult(WebServiceError.ServerNotFound, new Exception());
                var args   = new StatusEventArgs(result);

                _statusProvider.Raise(provider => provider.StatusUpdated += null, args);

                Assert.AreEqual(_viewModel.State, NestViewModelState.Error);
            }
Exemple #10
0
            public void ShouldNotBeInErrorStateOnCanceledException()
            {
                var result = new GetStatusResult(WebServiceError.Cancelled, new Exception());
                var args   = new StatusEventArgs(result);

                _statusProvider.Raise(provider => provider.StatusUpdated += null, args);

                Assert.IsFalse(_viewModel.IsInErrorState);
            }
Exemple #11
0
            public void ShouldNotBeLoggedInOnSessionTokenExpiredException()
            {
                var result = new GetStatusResult(WebServiceError.SessionTokenExpired, new Exception());
                var args   = new StatusEventArgs(result);

                _statusProvider.Raise(provider => provider.StatusUpdated += null, args);

                Assert.AreNotEqual(_viewModel.State, NestViewModelState.LoggedIn);
            }
Exemple #12
0
            public void ShouldBeLoggingInOnInvalidCredentialsException()
            {
                var result = new GetStatusResult(WebServiceError.InvalidCredentials, new Exception());
                var args   = new StatusEventArgs(result);

                _statusProvider.Raise(provider => provider.StatusUpdated += null, args);

                Assert.AreEqual(_viewModel.State, NestViewModelState.LoggingIn);
            }
Exemple #13
0
            public void ShouldLogToAnalyticsOnException()
            {
                var expectedException = new Exception();
                var result            = new GetStatusResult(WebServiceError.Unknown, expectedException);
                var args = new StatusEventArgs(result);

                _statusProvider.Raise(provider => provider.StatusUpdated += null, args);

                _analyticsService.Verify(analytics => analytics.LogError(expectedException));
            }
Exemple #14
0
            public void ShouldSetCurrentErrorToErrorOnSessionTokenExpiredException()
            {
                var expectedError = WebServiceError.SessionTokenExpired;
                var result        = new GetStatusResult(expectedError, new Exception());
                var args          = new StatusEventArgs(result);

                _statusProvider.Raise(provider => provider.StatusUpdated += null, args);

                Assert.AreEqual(expectedError, _viewModel.CurrentError);
            }
Exemple #15
0
        public void ShouldCacheStatusOnTimerTick()
        {
            var expectedResult = new GetStatusResult(new[] { new Structure("") });

            _mockWebService.Setup(w => w.GetStructureAndDeviceStatusAsync(It.IsAny <Structure>())).Returns(Task.FromResult(expectedResult));

            _timerCallback(null);

            _mockStatusProvider.Verify(s => s.CacheStatus(expectedResult));
        }
Exemple #16
0
            public async Task ShouldReturnExceptionWhenGetResponseFails()
            {
                var expectedException = new Exception("Failed!");

                _webRequest.Setup(r => r.GetResponseAsync()).Throws(expectedException);

                GetStatusResult result = await _webService.GetStructureAndDeviceStatusAsync(new Structure(""));

                Assert.AreEqual(expectedException, result.Exception);
            }
Exemple #17
0
            public async Task ShouldReturnStructureFromDeserializer()
            {
                var expectedStructure = new Structure("structureId");

                _webServiceDeserializer.Setup(d => d.ParseStructureFromGetStructureStatusResult(It.IsAny <string>(), It.IsAny <string>())).Returns(expectedStructure);

                GetStatusResult result = await _webService.GetStructureAndDeviceStatusAsync(new Structure(""));

                Assert.AreEqual(expectedStructure, result.Structures.ElementAt(0));
            }
Exemple #18
0
        public void ShouldStopTimerIfGetStructureAndDeviceStatusFails()
        {
            var expectedResult = new GetStatusResult(WebServiceError.Unknown, new Exception());

            _mockWebService.Setup(w => w.GetStructureAndDeviceStatusAsync(It.IsAny <Structure>())).Returns(Task.FromResult(expectedResult));

            _timerCallback(null);

            _mockTimer.Verify(t => t.Change(Timeout.Infinite, Timeout.Infinite));
        }
Exemple #19
0
            public void ShouldUpdateIsLeafOn()
            {
                var structure  = new Structure("");
                var thermostat = new Thermostat("")
                {
                    IsLeafOn = true
                };

                structure.Thermostats.Add(thermostat);
                var status = new GetStatusResult(new[] { structure });

                _statusProvider.Raise(provider => provider.StatusUpdated += null, new StatusEventArgs(status));

                Assert.AreEqual(thermostat.IsLeafOn, _viewModel.IsLeafOn, "Expected IsLeafOn to update from status change.");
            }
Exemple #20
0
            public void ShouldUpdateHvacMode()
            {
                var structure  = new Structure("");
                var thermostat = new Thermostat("")
                {
                    HvacMode = HvacMode.HeatAndCool
                };

                structure.Thermostats.Add(thermostat);
                var status = new GetStatusResult(new[] { structure });

                _statusProvider.Raise(provider => provider.StatusUpdated += null, new StatusEventArgs(status));

                Assert.AreEqual(thermostat.HvacMode, _viewModel.HvacMode, "Expected HvacMode to update from status change.");
            }
Exemple #21
0
            public void ShouldUpdateTargetTemperatureLow()
            {
                var structure  = new Structure("");
                var thermostat = new Thermostat("")
                {
                    TargetTemperatureLow = 48d
                };

                structure.Thermostats.Add(thermostat);
                var status = new GetStatusResult(new[] { structure });

                _statusProvider.Raise(provider => provider.StatusUpdated += null, new StatusEventArgs(status));

                Assert.AreEqual(thermostat.TargetTemperatureLow, _viewModel.TargetTemperatureLow, "Expected TargetTemperatureLow to update from status change.");
            }
Exemple #22
0
            public async Task ShouldUseFanModeFromDeserializer()
            {
                var expectedFanMode = FanMode.On;

                _webServiceDeserializer.Setup(d => d.ParseFanModeFromDeviceSubscribeResult(It.IsAny <string>()))
                .Returns(expectedFanMode);
                _webResponse.SetupSequence(w => w.GetResponseStringAsync())
                .Returns(Task.FromResult(FakeJsonMessages.GetStructureStatusResult))
                .Returns(Task.FromResult(FakeJsonMessages.GetDeviceStatusResult));

                var structure = new Structure("");

                structure.Thermostats.Add(new Thermostat(""));
                GetStatusResult result = await _webService.GetStructureAndDeviceStatusAsync(structure);

                Assert.AreEqual(expectedFanMode, result.Structures.ElementAt(0).Thermostats[0].FanMode);
            }
Exemple #23
0
        private void UpdateViewModelFromGetStatusResult(GetStatusResult statusResult)
        {
            Structure  firstStructure  = statusResult.Structures.ElementAt(0);
            Thermostat firstThermostat = firstStructure.Thermostats.ElementAt(0);

            _getStatusResult = statusResult;

            TargetTemperature     = firstThermostat.TargetTemperature;
            TargetTemperatureLow  = firstThermostat.TargetTemperatureLow;
            TargetTemperatureHigh = firstThermostat.TargetTemperatureHigh;
            CurrentTemperature    = firstThermostat.CurrentTemperature;
            IsHeating             = firstThermostat.IsHeating;
            IsCooling             = firstThermostat.IsCooling;
            FanMode  = firstThermostat.FanMode;
            IsLeafOn = firstThermostat.IsLeafOn;
            HvacMode = firstThermostat.HvacMode;
            IsAway   = firstStructure.IsAway;
        }
Exemple #24
0
        public GetStatusResult GetStatus()
        {
            GetStatusResult status = null;

            //connect
            if (this.Transport.Connect() == CommunicationResult.OK)
            {
                status = new GetStatusResult();
                var solarMaxRequest = new SolarMaxRequest(new SolarMaxCommand[] { new SolarMaxCommand(SolarMaxCommandEnum.DEVICE_STATUS) }.ToList());
                var resSend         = this.Transport.Send(solarMaxRequest.ToString());
                if (resSend == CommunicationResult.OK)
                {
                    //receive
                    var resRec = this.Transport.Receive(out string rec);
                    if (resRec == CommunicationResult.OK)
                    {
                        SolarMaxResponse solarMaxResponse = new SolarMaxResponse(rec);
                        var listSolarMaxCommand           = solarMaxResponse.Parse();
                        if (listSolarMaxCommand.Count > 0)
                        {
                            status.Status = listSolarMaxCommand[0].Value;
                            status.Result = true;
                        }
                    }
                    else
                    {
                        status.Result           = false;
                        status.ErrorDescription = "Unable to receive the response";
                    }
                }
                else
                {
                    status.Result           = false;
                    status.ErrorDescription = "Unable to send the request";
                }
                //disconnect
                this.Transport.Disconnect();
                return(status);
            }
            return(new GetStatusResult()
            {
                Result = false, ErrorDescription = "Unable to connect"
            });
        }
Exemple #25
0
        /// <summary>
        /// Get the current status of a GrabzIt screenshot
        /// </summary>
        /// <param name="id">The id of the screenshot</param>
        /// <returns>A Status object representing the screenshot</returns>
        public Status GetStatus(string id)
        {
            lock (thisLock)
            {
                if (string.IsNullOrEmpty(id))
                {
                    return(null);
                }

                string url = string.Format("{0}getstatus.ashx?id={1}",
                                           BaseURLGet, id);
                GetStatusResult webResult = Get <GetStatusResult>(url);

                if (webResult == null)
                {
                    return(null);
                }

                return(webResult.GetStatus());
            }
        }
Exemple #26
0
        public void SetUp()
        {
            _mockTimer          = new Mock <ITimer>();
            _mockStatusProvider = new Mock <IStatusProvider>();
            _mockWebService     = new Mock <INestWebService>();

            ServiceContainer.RegisterService <ITimer>(_mockTimer.Object);
            ServiceContainer.RegisterService <INestWebService>(_mockWebService.Object);
            ServiceContainer.RegisterService <IStatusProvider>(_mockStatusProvider.Object);

            _mockWebService.Setup(w => w.GetThermostatStatusAsync(It.IsAny <Thermostat>())).Returns(Task.FromResult(new GetThermostatStatusResult(new Thermostat(""))));
            _mockWebService.Setup(w => w.GetStructureAndDeviceStatusAsync(It.IsAny <Structure>())).Returns(Task.FromResult(new GetStatusResult(new[] { new Structure("") })));
            _mockTimer.Setup(t => t.SetCallback(It.IsAny <TimerCallback>())).Callback <TimerCallback>(c => _timerCallback = c);
            _mockStatusProvider.Setup(s => s.CacheStatus(It.IsAny <GetStatusResult>())).Callback <GetStatusResult>(g => _cachedStatusResult = g);

            _updaterService = new StatusUpdaterService();
        }