public async Task GetRoomMeasure_Should_Return_TemperatureSteps() { var parameters = new GetRoomMeasureParameters { HomeId = "5a327cbdb05a2133678b5d3e", RoomId = "2255031728", Scale = Scale.Max, Type = ThermostatMeasurementType.Temperature }; httpTest.RespondWith( "{\"body\":[{\"beg_time\":1513259100,\"step_time\":1800,\"value\":[[27.9],[27.1],[26.2],[25.4],[25.8],[26.2],[26.7],[26.9],[27],[27.1],[27.2],[27],[26.8],[26.6],[26.5],[26.3],[26.3],[26.3],[26.2],[26.2],[26.2],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26],[26],[26.1],[26],[26],[26],[26],[26],[25.9],[24.8],[24],[23.6],[23.5],[23.2],[23],[22.9],[22.7],[22.5],[22.4],[22.4],[22.6],[22.8],[23.1],[23.2],[23.4],[23.4],[23.3],[23.1],[22.9],[22.5],[22.2],[21.9],[21.6],[21.6],[21.4],[21.2],[21.1],[21],[20.9],[20.8],[20.7],[20.7],[20.6],[20.6],[20.6],[20.5],[20.5],[20.5],[20.4],[20.4],[20.4],[20.4],[20.4],[20.3],[20.3],[20.2],[20.2],[20.2],[20.2],[20.2],[20.2],[20.2],[20.2],[20.2],[20.2],[20.2],[20.3],[20.3],[20.3],[20.3],[20.2],[20.2],[20.1],[20],[20],[19.9],[19.8],[19.8],[19.8],[19.7],[19.7],[19.7],[19.6],[19.9],[20.2],[20.6],[20.6],[20.7],[20.6],[20.7],[20.7],[20.7],[20.8],[20.7],[20.8],[20.7],[20.8],[20.5],[20.2],[20],[19.9],[19.7],[19.6],[19.5],[19.5],[19.4],[19.4],[19.4],[19.5],[19.5],[19.6],[19.6],[19.6],[19.7],[19.7],[19.7],[19.7],[19.7],[19.7],[19.6],[19.6],[19.5],[19.4],[19.4],[19.3],[19.3],[19.3],[19.3],[19.2],[19.2],[19.3],[20],[20.6],[20.8],[20.9],[20.8],[20.9],[21],[20.8],[20.9],[20.9],[20.7],[20.8],[20.8],[20.7],[20.4],[20.2],[20],[19.9],[19.7],[19.6],[19.6],[19.5],[19.7],[20.3],[20.6],[21],[21.3],[21.7],[21.9],[21.7],[21.6],[21.6],[21.5],[21.6],[21.9],[22.1],[22],[22],[22.1],[22.2],[22.3],[22.2],[21.9],[21.5],[21.1],[20.7],[20.5],[20.3],[20.4],[20.6],[20.7],[20.7],[20.8],[20.7],[20.8],[20.7],[20.8],[20.7],[20.8],[20.7],[20.8],[20.8],[20.5],[20.2],[20],[19.9],[19.7],[19.7],[19.6],[19.5],[19.7],[20.2],[20.6],[21],[21.4],[21.7],[21.7],[21.5],[21.2],[21],[21],[21.2],[21.5],[21.8],[22.2],[22.2],[22.3],[22.6],[23.4],[23.8],[24.2],[24.4],[24.4],[24.4],[24.5],[24.5],[24.5],[24.6],[24.6],[24.6],[24.6],[24.6],[24.7],[24.7],[24.7],[24.7],[24.8],[24.8],[24.8],[24.9],[24.9],[24.9],[25],[25],[25.1],[25.1],[25.1],[25.2],[25.2],[25.3],[25.6],[25.9],[26.1],[26.4],[26.5],[26.4],[26.3],[26.2],[26.3],[26.4],[26.5],[26.7],[26.8],[26.7],[26.9],[27],[27],[26.7],[26.6],[26.5],[26.3],[26.2],[26.1],[26],[26],[26],[26],[25.9],[25.9],[25.9],[25.9],[25.9],[25.9],[25.9],[25.9],[25.9],[25.9],[25.9],[25.9],[26],[26],[26],[26],[26],[26.1],[26.1],[25.2],[23.9],[23.2],[24.1],[25.1],[25.9],[26.3],[26.6],[26.6],[26.2],[25.7],[25],[24.4],[25.1],[25.7],[26.2],[26.3],[26.1],[25.9],[25.2],[24],[22.9],[21.9],[21],[20.2],[19.6],[19.3],[19.1],[19],[18.9],[18.8],[18.7],[18.6],[18.5],[18.4],[18.3],[18.2],[18.1],[18],[17.9],[17.8],[17.6],[17.4],[17.3],[17.1],[17],[17],[17.3],[18.2],[20.2],[21.9],[23.2],[24.1],[24.8],[25.2],[24.8],[23.9],[24.3],[25],[25.6],[26],[26.2],[26.3],[26.4],[26.4],[26.5],[26.5],[26.4],[26.3],[26.2],[26.1],[26],[25.9],[25.9],[25.9],[25.8],[25.8],[25.8],[25.8],[25.8],[25.8],[25.8],[25.8],[25.9],[25.9],[25.9],[25.9],[25.9],[25.9],[25.9],[25.9],[26],[26],[26],[26],[26],[26],[26],[26.1],[26.1],[26.1],[26.2],[26.2],[26.2],[26.2],[26.2],[26.3],[26.3],[26.3],[26.3],[26.2],[26.2],[26.2],[26.2],[26.2],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.3],[26.3],[26.3],[26.3],[26.3],[26.3],[26.3],[26.3],[26.3],[26.3],[26.3],[26.3],[26.3],[26.3],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.2],[26.3],[26.3],[26.4],[26.4],[26.5],[26.4],[26.4],[26.3],[26.3],[26.3],[26.3],[26.2],[26.2],[26.2],[26.2],[26.2],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26.1],[26],[26],[25.9],[25.9],[25.8],[25.8],[25.8],[25.7],[25.7],[25.7],[25.7],[25.7],[25.7],[25.7],[25.8],[25.9],[26],[26],[24.8],[23.8],[24.4],[24.9],[25.3],[25.8],[26.1],[26.4],[26.6],[26.7],[26.7],[26.8],[26.9],[26.9],[27.1],[27.2],[27.3],[27.3],[27.3],[27.3],[27.2],[27.1],[27],[26.9],[26.8],[26.7],[26.6],[26.5],[26.5],[26.4],[26.4],[26.3],[26.2],[26.1],[26.1],[26],[26],[25.9],[25.9],[25.9],[25.8],[25.8],[25.8],[25.9],[26],[26.1],[26.2],[26.2],[26.3],[25.1],[24.9],[25.2],[25.6],[26],[26.4],[26.6],[26.7],[26.7],[26.7],[26.6],[26.6],[26.7],[26.7],[26.9],[26.6],[26.5],[26.6],[26.7],[26.7],[26.5],[26.5],[26.4],[26.4],[26.4],[26.4],[26.4],[26.3],[26.3],[26.2],[26.2],[26.1],[26.1],[26],[26],[25.9],[25.9],[25.9],[25.8],[25.8],[25.8],[25.8],[25.8],[25.8],[25.9],[25.9],[25.9],[25.9],[26],[26.1],[25.9],[24.8],[25.2],[25.7],[26.3],[26.6],[26.7],[26.8],[26.8],[26.7],[26.9],[27],[27.1],[27.1],[26.8],[26.3],[25.4],[24.6],[23.8],[23.2],[22.6],[22.2],[21.9],[21.6],[21.5],[21.4],[21.3],[21.2],[21.1],[21],[21],[20.9],[20.8],[20.8],[20.7],[20.7],[20.6],[20.6],[20.6],[20.5],[20.5],[20.4],[20.4],[20.3],[20.2],[20.2],[20.2],[20.3],[20.5],[20.7],[20.9],[21.1],[21.2],[21.3],[21.3],[21.3],[21.3],[21.3],[21.4],[21.5],[21.5],[21.6],[21.6],[21.6],[21.6],[21.6],[21.4],[21],[20.8],[20.6],[20.4],[20.3],[20.2],[20.4],[20.5],[20.5],[20.5],[20.5],[20.5],[20.5],[20.6],[20.5],[20.6],[20.5],[20.6],[20.5],[20.6],[20.4],[20.3],[20.3],[20.2],[20.2],[20.2],[20.2],[20.2],[20.2],[20.2],[20.3],[20.3],[20.3],[20.4],[20.4],[20.5],[20.5],[20.4],[20.4],[20.4],[20.4],[20.4],[20.4],[20.3],[20.3],[20.3],[20.3],[20.3],[20.2],[20.2],[20.2],[20.2],[20.2],[20.2],[20.5],[20.7],[20.7],[20.8],[20.7],[20.7],[20.7],[20.8],[20.8],[20.7],[20.8],[20.7],[20.8],[20.7],[20.5],[20.4],[20.3],[20.2],[20.2],[20.1],[20.1],[20.1],[20.1],[20.1],[20.1],[20.1],[20.1],[20.1],[20.2],[20.2],[20.3],[20.4],[20.3],[20.3],[20.3],[20.2],[20.2],[20.1],[20],[20],[19.9],[19.9],[19.9],[19.9],[19.8],[19.8],[19.8],[19.8],[20],[20.3],[20.7],[20.7],[20.8],[20.7],[20.8],[20.7],[20.8],[20.7],[20.8],[20.7],[20.8],[20.7],[20.4],[20.1],[20],[19.9],[19.7],[19.7],[19.5],[19.5],[19.5],[19.4],[19.4],[19.4],[19.4],[19.4],[19.4],[19.4],[19.4],[19.5],[19.7],[19.7],[19.6],[19.6],[19.5],[19.5],[19.5],[19.4],[19.4],[19.4],[19.3],[19.3],[19.3],[19.3],[19.3],[19.4],[20.2],[20.7],[20.9],[20.7],[20.8],[20.8],[20.7],[20.8],[20.7],[20.7],[20.8],[20.7],[20.8],[20.7],[20.4],[20.1],[19.8],[19.7],[19.6],[19.5],[19.4],[19.4],[19.5],[19.9],[20.5],[20.8],[21],[21.3],[21.3],[21.1],[20.9],[20.9],[21.2],[21.5],[21.8],[22.1],[22.2],[22.3],[22.3],[22.4],[22.4],[22.1],[21.7],[21.3],[21],[20.7],[20.5],[20.4],[20.6],[20.7],[20.7],[20.9],[20.8],[20.8],[20.8],[20.8],[20.9],[20.8],[20.8],[20.8],[20.8],[20.9],[20.6],[20.4],[20.3],[20.2],[20.1],[20.1],[20],[19.9],[20.2],[20.7],[21.2],[21.7],[21.9],[22],[21.9],[21.6],[21.5],[21.6],[21.8],[22]]},{\"beg_time\":1514992500,\"step_time\":1800,\"value\":[[22.8],[22.9],[22.8],[22.7],[22.8],[22.8],[22.7],[22.3],[21.8],[21.4],[21.1],[20.8],[20.6],[20.6],[20.8],[20.8],[20.9],[20.8],[20.9],[20.9],[20.9],[20.9],[20.9],[20.9],[20.9],[20.9],[20.9],[20.7],[20.6],[20.4],[20.4],[20.3],[20.3],[20.3],[20.3],[20.6],[21.2],[21.4],[21.6],[21.8],[22.1],[22.2],[22],[21.9],[21.9],[22],[22.3],[22.5],[22.6],[22.7],[22.8],[22.8],[22.9],[22.6],[22.3],[21.7],[21.4],[21.1],[20.9],[20.7],[20.5],[20.7]]}],\"status\":\"ok\",\"time_exec\":0.79246497154236,\"time_server\":1518023284}"); var sut = new Netatmo.EnergyClient("https://api.netatmo.com/", credentialManagerMock.Object); var result = await sut.GetRoomMeasure <TemperatureStep>(parameters); httpTest .ShouldHaveCalled("https://api.netatmo.com/api/getroommeasure") .WithVerb(HttpMethod.Post) .WithOAuthBearerToken(accessToken) .WithContentType("application/json").WithRequestJson(new GetRoomMeasureRequest { HomeId = parameters.HomeId, RoomId = parameters.RoomId, Scale = parameters.Scale.Value, Type = parameters.Type.Value }) .Times(1); result.Body[0].BeginAt.Should().Be(Instant.FromDateTimeUtc(DateTime.SpecifyKind(new DateTime(2017, 12, 14, 13, 45, 0), DateTimeKind.Utc))); result.Body.Length.Should().Be(2); result.Body[0].Values[0][0].Should().Be(27.9); result.Body[0].Values[1][0].Should().Be(27.1); }
public void GetRoomMeasure_Should_Throw_ArgumentException(GetRoomMeasureParameters parameters, string exceptionMessage) { var sut = new Netatmo.EnergyClient("https://api.netatmo.com/", credentialManagerMock.Object); sut .Awaiting(async s => await s.GetRoomMeasure <TemperatureStep>(parameters)) .Should().Throw <ArgumentException>() .WithMessage(exceptionMessage); }
private void ValidateGetRoomMeasureParameters <T>(GetRoomMeasureParameters parameters) { if (string.IsNullOrWhiteSpace(parameters.HomeId)) { throw new ArgumentException("Home Id shouldn't be null"); } if (string.IsNullOrWhiteSpace(parameters.RoomId)) { throw new ArgumentException("Room Id shouldn't be null"); } if (parameters.Scale == null) { throw new ArgumentException("Scale shouldn't be null"); } if (parameters.Type == null) { throw new ArgumentException("Type shouldn't be null"); } if (ThermostatMeasurementType.AvailableTypes(parameters.Scale).All(type => type.Value != parameters.Type.Value)) { throw new ArgumentException("Type shouldn't be allow for this scale"); } if (parameters.Limit.HasValue && (parameters.Limit.Value < 0 || parameters.Limit.Value > 1024)) { throw new ArgumentException("Limit should be between 0 and 1024"); } if (parameters.BeginAt.HasValue && parameters.EndAt.HasValue && parameters.BeginAt.Value > parameters.EndAt.Value) { throw new ArgumentException("BeginAt should be lower than EndAt"); } if (parameters.Type == ThermostatMeasurementType.Temperature || parameters.Type == ThermostatMeasurementType.SetPointTemperature || parameters.Type == ThermostatMeasurementType.MinTemp || parameters.Type == ThermostatMeasurementType.MaxTemp) { if (typeof(T) != typeof(TemperatureStep)) { throw new ArgumentException("TemperatureStep should be used with a temperature measurement"); } } else if (parameters.Type == ThermostatMeasurementType.DateMinTemp) { if (typeof(T) != typeof(DateTemperatureStep)) { throw new ArgumentException("DateTemperatureStep should be used with a date of temperature measurement"); } } }
public async Task <DataResponse <T[]> > GetRoomMeasure <T>(GetRoomMeasureParameters parameters) where T : IStep { ValidateGetRoomMeasureParameters <T>(parameters); return(await baseUrl .ConfigureRequest(Configuration.ConfigureRequest) .AppendPathSegment("/api/getroommeasure") .WithOAuthBearerToken(credentialManager.AccessToken) .PostJsonAsync(new GetRoomMeasureRequest { HomeId = parameters.HomeId, RoomId = parameters.RoomId, Scale = parameters.Scale.Value, Type = parameters.Type.Value, BeginAt = parameters.BeginAt, EndAt = parameters.EndAt, Limit = parameters.Limit, Optimize = parameters.Optimize, RealTime = parameters.RealTime }).ReceiveJson <DataResponse <T[]> >()); }
public static async Task Main(string[] args) { JsonConvert.DefaultSettings = Configuration.JsonSerializer; IClient client = new Client( SystemClock.Instance, " https://api.netatmo.com/", Environment.GetEnvironmentVariable("NETATMO_CLIENT_ID"), Environment.GetEnvironmentVariable("NETATMO_CLIENT_SECRET")); await client.GenerateToken( Environment.GetEnvironmentVariable("NETATMO_USERNAME"), Environment.GetEnvironmentVariable("NETATMO_PASSWORD"), new[] { Scope.CameraAccess, Scope.CameraRead, Scope.CameraWrite, Scope.HomecoachRead, Scope.PresenceAccess, Scope.PresenceRead, Scope.StationRead, Scope.StationWrite, Scope.ThermostatRead }); var token = client.CredentialManager.CredentialToken; Console.WriteLine($"Token : {token.AccessToken}"); Console.WriteLine("Stations data :"); var stationsData = await client.Weather.GetStationsData(); Console.WriteLine(JsonConvert.SerializeObject(stationsData, Formatting.Indented)); Console.WriteLine("Energy Homes data :"); var homesData = await client.Energy.GetHomesData(); Console.WriteLine(JsonConvert.SerializeObject(homesData, Formatting.Indented)); Console.WriteLine("Energy Homes data :"); foreach (var home in homesData.Body.Homes) { Console.WriteLine(home.Name); var homeStatus = await client.Energy.GetHomeStatus(home.Id); Console.WriteLine(JsonConvert.SerializeObject(homeStatus, Formatting.Indented)); Console.WriteLine("Energy room measure :"); foreach (var room in home.Rooms) { Console.WriteLine(room.Name); var parameters = new GetRoomMeasureParameters { HomeId = home.Id, RoomId = room.Id, Scale = Scale.Max, Type = ThermostatMeasurementType.Temperature, BeginAt = SystemClock.Instance.GetCurrentInstant().Plus(Duration.FromDays(-1)), EndAt = SystemClock.Instance.GetCurrentInstant() }; var roomMeasure = await client.Energy.GetRoomMeasure <TemperatureStep>(parameters); Console.WriteLine(JsonConvert.SerializeObject(roomMeasure, Formatting.Indented)); } } Console.WriteLine("RefreshToken :"); Thread.Sleep(9000); await client.RefreshToken(); var newToken = client.CredentialManager.CredentialToken; Console.WriteLine($"Old token expires at : {token.ExpiresAt.ToInvariantString()}"); Console.WriteLine($"New token expires at : {newToken.ExpiresAt.ToInvariantString()}"); }