Git Product home page Git Product logo

pvoutput.net's Introduction

PVOutput.Net

A .NET Core (Standard 2.0 compatible) wrapper library for API of the popular PVOutput service. PVOutput is a free service for sharing and comparing PV output data.

GitHub last commit (main) NuGet Version NuGet Downloads NET Build Code coverage

Installation

Installation can be done through installation of the NuGet package:

PM> Install-Package PVOutput.Net

Changelog

See Changelog for information on changes per version, including coming but yet unreleased changes.

Support

This library is targeting .NET Standard 2.0 and above. For full compatibility details, check the Microsoft Docs.

Please note: that the default branch of the repository is develop. This means that it can contain bugfixes/features that are not yet available in the NuGet package. See main for the source code, that was used for building the NuGet package.

Basic usage

This section describes examples of functionality that the library provides.

Getting data out of PVOutput.org

var client = new PVOutputClient(apiKey: "myPvOutputKey", ownedSystemId: 1);

// Request output for today
var outputResponse = await client.Output.GetOutputForDateAsync(DateTime.Today);
var output = outputResponse.Value;
Console.WriteLine($"Output for date {output.OutputDate.ToShortDateString()}, {output.EnergyGenerated} Wh generated");

Adding data to a system in PVOutput.org

var client = new PVOutputClient(apiKey: "myPvOutputKey", ownedSystemId: 1);
var builder = new StatusPostBuilder<IStatusPost>();

// Build the status
var status = builder.SetTimeStamp(DateTime.Now)
                .SetGeneration(200)
                .Build();

// Push the status back to PVOutput
var response = await client.Status.AddStatusAsync(status);

Using the client in an ASP.Net Core application

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddPVOutputClient(options =>
        {
            options.ApiKey = "myPvOutputKey";
            options.OwnedSystemId = 1;
        });
    }

For more information on usage, please see the documentation.

API Coverage

As of 0.8.0 this library contains the complete public API that official PVOutput exposes. See documentation for details.

Contribute

See Contributing for information on how to contribute to this project.

Contributors

Building the project

As the whole solution has all that dotnet magic, you can just run:

dotnet build

to build the solution as a whole or a single project.

Running the Nunit tests can also be done from the cli, just run:

dotnet test

License

This project's structure and Request handling have been seriously inspired (in part, copied even) by Henrik Fröhling's work on Trakt.NET, when it was still called TraktApiSharp. While this project is licensed under the same license as Trakt.NET, I'd still like to make this absolutely clear.

MIT © Marcel Boersma

pvoutput.net's People

Contributors

codecasternl avatar dependabot[bot] avatar khoality-dev avatar pyrocumulus avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

khoality-dev

pvoutput.net's Issues

Create a search query builder for the Search service

Try and create a search query builder for the Search service. At this time, there is only a string based query parameter. It would be nice to research the possibility to create a filter using a fluent api, instead of just a string.

Allow deleting all status on a specific day

StatusService.DeleteStatus now deletes specific moments. According to the api, if the time parameter is omitted, all statuses on a given day are deleted.

To implement this, we need a new api call: StatusService.DeleteAllStatusesOnDate. This would also take a single DateTime but just omit the time from the request.

Allow sending batch status posts with Net data

Currently the AddBatchStatus sends all status objects with the net flag set to false. Also, the cumulative type is always set to none.

We need to be able to control those parameters when sending data. The Net flag does completely modify the formatting of the data part of the request.

Implement Debug or Trace output

It would be nice to optionally log the requested Uri and Response content to a separate logging system. Ideally with another dependency.

Perhaps Debug or Trace? Has to work with Release mode binaries though.

Implement .NET Core DI support

Create an extension method for adding the PVOutputClient as a singleton to the service collection. This would make it a lot easier to integrate PVOutput in for example ASP.NET Core applications.

See:
https://aws.amazon.com/blogs/developer/working-with-dependency-injection-in-net-standard-inject-your-aws-clients-part-1/

Something like:

public void AddPVOutputClient(this IServiceCollection, Action<PVOutputOptions> optionsSetter)
{
   optionsSetter.Invoke();
   Services.AddSingleton<PVOutputClient>(new PVOutputClient(options.GetApiKey()))
}

CA1716 - Eliminate usage of reserved words

Types:

  • IInsolationService
  • IOutputService
  • IStatusService

All use parameters with the the name date which triggers the following code analysis warning:

warning CA1716: In virtual/interface member XXX, rename parameter date so that it no longer conflicts with the reserved language keyword 'Date'. Using a reserved keyword as the name of a parameter on a virtual/interface member makes it harder for consumers in other languages to override/implement the member.

The parameters have to be renamed to something that won't cause conflict.

pvoutput deprecated addbatchoutput

I found recently that pvoutput has deprecated the addbatchoutput API, batching is now part of addoutput, but batching is only available for donations mode, see jwillemsen/saj_collector#34. It looks this project needs to be updated because it uses addbatchoutput.jsp as far as I can tell.

Decrease visibility of public types

As most of the library is now covered by interfaces to help users with unit testing, it makes sense to decrease the visibility of the underlying actual implementations. It doesn't make sense to have the interfaces public as well as the implementations. The latter can go back to internal. This is especially true for all the modules.

It's also worth looking at the rest of the public facing types regarding this point.

Feedback requested!

I am very interested in people using this library and how it is working for them. I can see the NuGet downloads slightly increasing, but I don't know who's using it. No public repository is currently dependant on it.

Do you use this library?
If so, be it negative or positive please share your thoughts! 🙂 I'd like to hear them, one way or the other.

Add `Shade` enumeration for returning shade information

The PVOutput UI for maintaining system information, only provides the following options when entering shade information:

  • None
  • Low
  • Medium
  • High

It would be better to return this information in an enum format, instead of the current string type. Note that it's also possible to enter a time frame for the shade to occur. This information is currently not being returned by the PVOutput api.

Combining the data of multiple inverters from the same system

Larger systems usually have multiple inverters so it would be nice if there was an option to combine these outputs and thus preventing having to use multiple systems in PVOutput. As not all values can be added up the highest of those should be reported to PVOutput.

Add interfaces to enable unit testing

Hi @pyrocumulus, nice library, I'm using it in an upcoming Windows Service that syncs GoodWe API to PVOutput. Somewhere in that code, I have a class that wraps your PVOutputClient for configuration and DI purposes, and it has a property:

public PVOutputClient ApiClient { get; }

Now I want to test that my code calls your code, without actually calling your code, it being test data and all which I don't want to be sent to PVOutput.

Could you consider interfacing the PVOutputClient and its services, so it can be mocked for unit tests?

Document the public API layer of the library

Add Xml doc for all public facing types, methods and parameters. Also package the resulting documentation in the output assembly, so it can be packed into the Nuget package.

Add Output seems to work unreliably

Pushing only a date and generation seems to work well. However when paired with, peaktime/conditions/consumption the api seems to return 200 however no output is record at PVOutput's end.

Sample with which I experienced this

            var builder = new OutputPostBuilder();
            var output = builder.SetDate(DateTime.Today.AddDays(-2))
                .SetGenerated(10000)
                .SetPeakTime(new DateTime(2019, 12, 8, 10, 15, 23))
                .SetCondition("Fine")
                .SetTemperatures(5.2m, 9.4m)
                .SetConsumption(2000)
                .Build();

            var response = await client.Output.AddOutputAsync(output);

Express PeakTime as TimeSpan instead of DateTime

On various places a time-only data aspect is expressed as a DateTime, resulting in weird tricks to combine dates and times in new DateTime.

This can be avoided if the time-only aspects are expressed as TimeSpan.

API help url's are out-of-date

The API docs still use the following format:

https://pvoutput.org/help.html#api-addoutput

While the new format is:

https://pvoutput.org/help/api_specification.html#add-output-service

Changes needed:
Go through the whole code base and update all links in the old format */help.html#* to new url's. Has to be done manually because the anchors are also renamed, not only moved.

Resolve CA1716 naming violations

We need to resolve these issues for better compatibility with different languages/runtimes:

Warning CA1716 In virtual/interface member XXXXXXXXXXX, rename parameter date so that it no longer conflicts with the reserved language keyword 'Date'. Using a reserved keyword as the name of a parameter on a virtual/interface member makes it harder for consumers in other languages to override/implement the member.

Violations in:
PVOutput.Net D:\Git\pvoutput.net\src\PVOutput.Net\Modules\Interfaces\IStatusService.cs
PVOutput.Net D:\Git\pvoutput.net\src\PVOutput.Net\Modules\Interfaces\IOutputService.cs
PVOutput.Net D:\Git\pvoutput.net\src\PVOutput.Net\Modules\Interfaces\IOutputService.cs
PVOutput.Net D:\Git\pvoutput.net\src\PVOutput.Net\Modules\Interfaces\IInsolationService.cs
PVOutput.Net D:\Git\pvoutput.net\src\PVOutput.Net\Modules\Interfaces\IInsolationService.cs
PVOutput.Net D:\Git\pvoutput.net\src\PVOutput.Net\Modules\Interfaces\IInsolationService.cs

Some string values are getting double UrlEncoded

Describe the bug

Some parameters are getting processed by UrlEncode write. This results in %2520 instead of %20 for a space character.

To reproduce

Steps to reproduce the behavior:

  1. Setup client
  2. AddStatusRequest
  3. Use the TextMessage property and use a space character in the text

Expected behavior

It should not double encode.

Additional context

More than one parameter ought to be affected by this. Manual UrlEncode should only be applied in the curious case of the + character.

`System.GetOwnSystemAsync()`: Invalid description 'EW' for enum Orientation

Describe the bug

The orientation "EW" isn't known (https://github.com/pyrocumulus/pvoutput.net/blob/develop/src/PVOutput.Net/Enums/Orientation.cs).

To reproduce

  1. Set up client
  2. Configure PVOutput panel orientation "EW"
  3. Call method System.GetOwnSystemAsync()
  4. See error

Stack Trace

System.ArgumentException: Invalid description 'EW' for enum Orientation (Parameter 'enumerationDescription')
   at PVOutput.Net.Objects.Core.FormatHelper.DescriptionToEnumValue[TEnumType](String enumerationDescription)
   at PVOutput.Net.Objects.Modules.Readers.SystemObjectStringReader.<>c.<ParseBaseProperties>b__2_9(ISystem t, String s)
   at PVOutput.Net.Objects.Core.BaseObjectStringReader`1.ParsePropertyArray(TReturnType target, TextReader reader, Action`2[] properties)
   at PVOutput.Net.Objects.Modules.Readers.SystemObjectStringReader.ParseBaseProperties(ISystem target, TextReader reader)
   at PVOutput.Net.Objects.Core.BaseObjectStringReader`1.ParseProperties(TReturnType target, TextReader reader, CancellationToken cancellationToken)
   at PVOutput.Net.Objects.Core.BaseObjectStringReader`1.ReadObjectAsync(TextReader reader, CancellationToken cancellationToken)
   at PVOutput.Net.Objects.Core.BaseObjectStringReader`1.ReadObjectAsync(Stream stream, CancellationToken cancellationToken)
   at PVOutput.Net.Requests.Handler.RequestHandler.ExecuteSingleItemRequestAsync[TResponseContentType](IRequest request, Dictionary`2 loggingScope, CancellationToken cancellationToken)

Undocumented though: https://pvoutput.org/help/api_specification.html#id66

Cleanup public facing api

Restructure namespace and folder hierarchy to lessen namespace requirements. No more structure per type/class, only by functionality

Migrate codeanalysis

Microsoft.CodeAnalysis.FxCopAnalyzers is deprecated, we need to migrate analysers to Microsoft.CodeAnalysis.NetAnalyzers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.