StromGedacht.NET 1.1.0

dotnet add package StromGedacht.NET --version 1.1.0
NuGet\Install-Package StromGedacht.NET -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="StromGedacht.NET" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add StromGedacht.NET --version 1.1.0
#r "nuget: StromGedacht.NET, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install StromGedacht.NET as a Cake Addin
#addin nuget:?package=StromGedacht.NET&version=1.1.0

// Install StromGedacht.NET as a Cake Tool
#tool nuget:?package=StromGedacht.NET&version=1.1.0

StromGedacht.NET

dotnet nuget version nuget downloads build codecov GitHub license

C# client for the StromGedacht API

Installation

Available on NuGet.

dotnet add package StromGedacht.NET

or

PM> Install-Package StromGedacht.NET

Usage

The client can provide the region state at the current time or all states for a given time period.

The period may extend a maximum of 2 days into the future and 4 days into the past.

Each time you make a request, you will need to provide the zip code of the region for which you want to request the state.

Initialization

First create an instance of StromGedachtClient by passing an instance of HttpClient to its constructor.

var httpClient = new HttpClient();

var client = new StromGedachtClient(httpClient);

Get current state

You can fetch the current state of a region by calling the Now / NowAsync methods and passing the zip code of the region.

var state = client.Now("70173");
var state = await client.NowAsync("70173");

If the api returns an error, this method returns null. This could happen if the zip code is invalid / not supported.

Get states for time period

You can fetch all states of a region for a specific time period by calling the States / StatesAsync methods and passing the zip code of the region, the start time and end time.

Start and end time can be two dates:

var from = new DateTimeOffset(2023, 1, 1, 0, 0, 0, TimeSpan.FromHours(2));
var to = new DateTimeOffset(2023, 1, 3, 23, 59, 59, TimeSpan.FromHours(2));

var states = client.States("70173", from, to);
var from = new DateTimeOffset(2023, 1, 1, 0, 0, 0, TimeSpan.FromHours(2));
var to = new DateTimeOffset(2023, 1, 3, 23, 59, 59, TimeSpan.FromHours(2));

var states = await client.StatesAsync("70173", from, to);

or the hours relative to this moment:

var hoursInPast = 24;
var hoursInFuture  = 48;

var states = client.States("70173", hoursInPast, hoursInFuture);
var hoursInPast = 24;
var hoursInFuture  = 48;

var states = await client.StatesAsync("70173", hoursInPast, hoursInFuture);

If the api returns an error, this method returns an empty list. This could happen if the zip code is invalid / not supported or the supported period is exceeded.

Get forecast

You can fetch the forecast of a region for a specific time period by calling the Forecast / ForecastAsync methods and passing the zip code of the region, the start time and end time.

var from = new DateTimeOffset(2023, 1, 1, 0, 0, 0, TimeSpan.FromHours(2));
var to = new DateTimeOffset(2023, 1, 3, 23, 59, 59, TimeSpan.FromHours(2));

var forecast = client.Forecast("70173", from, to);
var from = new DateTimeOffset(2023, 1, 1, 0, 0, 0, TimeSpan.FromHours(2));
var to = new DateTimeOffset(2023, 1, 3, 23, 59, 59, TimeSpan.FromHours(2));

var forecast = await client.ForecastAsync("70173", from, to);

Dependency Injection

You can register the StromGedachtClient in your Startup with a typed HttpClient.

builder.Services.AddHttpClient<StromGedachtClient>();

Then inject the client wherever you like. E.g. in a controller:

[Route("Home")]
[ApiController]
public class HomeController : ControllerBase
{
    private readonly StromGedachtClient _client;

    public HomeController(StromGedachtClient client)
    {
        _client = client;
    }
}

API rate limits

The api is limited to about 6 requests per minute.

Here are some related projects:

Shoutout

The used API is provided by StromGedacht, TransnetBW GmbH.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.0 97 1/17/2024
1.0.0 134 5/19/2023
1.0.0-beta 97 5/18/2023