Skip to content

Commit

Permalink
Merge pull request #49 from pyrocumulus/orientation-enumeration
Browse files Browse the repository at this point in the history
Use Orientation enumeration in return information
  • Loading branch information
pyrocumulus authored Jan 21, 2021
2 parents 23468e0 + 8a7838b commit b8cd3fb
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 21 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [Unreleased]

### Breaking change

- Some methods will now return an `Orientation` enumeration value instead of a string representation [#49](https://github.com/pyrocumulus/pvoutput.net/pull/49)

## [0.8.1] - 2020-11-07

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ For more information on usage, please see the [documentation](https://pyrocumulu

## API Coverage

As of 0.8.0 this library the complete public API that official PVOutput exposes. See [documentation](https://pyrocumulus.github.io/pvoutput.net/) for details.
As of 0.8.0 this library contains the complete public API that official PVOutput exposes. See [documentation](https://pyrocumulus.github.io/pvoutput.net/) for details.

## Building the project

Expand Down
2 changes: 0 additions & 2 deletions src/PVOutput.Net/Objects/Core/FormatHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ internal static TResultType GetValueOrDefault<TResultType>(string value) where T
return result ?? (default);
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "Exception messages are non translatable for now")]
internal static string GetEnumerationDescription<TEnumType>(this TEnumType enumerationValue) where TEnumType : struct
{
Type type = enumerationValue.GetType();
Expand All @@ -97,7 +96,6 @@ internal static string GetEnumerationDescription<TEnumType>(this TEnumType enume
return null;
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "Exception messages are non translatable for now")]
public static TEnumType DescriptionToEnumValue<TEnumType>(this string enumerationDescription) where TEnumType : struct
{
var type = typeof(TEnumType);
Expand Down
3 changes: 2 additions & 1 deletion src/PVOutput.Net/Objects/IFavourite.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using PVOutput.Net.Enums;

namespace PVOutput.Net.Objects
{
Expand Down Expand Up @@ -62,7 +63,7 @@ public interface IFavourite
/// <summary>
/// Primary orientation of most panels.
/// </summary>
string Orientation { get; set; }
Orientation Orientation { get; set; }

/// <summary>
/// Tilt the solar array has.
Expand Down
4 changes: 2 additions & 2 deletions src/PVOutput.Net/Objects/ISystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public interface ISystem
/// <summary>
/// Orientation of the solar panels if the system.
/// </summary>
string Orientation { get; set; }
Orientation Orientation { get; set; }

/// <summary>
/// Tilt the solar array has.
Expand Down Expand Up @@ -98,7 +98,7 @@ public interface ISystem
/// <summary>
/// Orientation of secondary array, if present.
/// </summary>
string SecondaryOrientation { get; set; }
Orientation? SecondaryOrientation { get; set; }

/// <summary>
/// Tilt of the secondary array, if present.
Expand Down
3 changes: 2 additions & 1 deletion src/PVOutput.Net/Objects/ISystemSearchResult.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using PVOutput.Net.Enums;

namespace PVOutput.Net.Objects
{
Expand Down Expand Up @@ -32,7 +33,7 @@ public interface ISystemSearchResult
/// <summary>
/// Orientation of the solar panels of the found system.
/// </summary>
string Orientation { get; set; }
Orientation Orientation { get; set; }

/// <summary>
/// Total number of outputs the found system has recorded.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using PVOutput.Net.Enums;

namespace PVOutput.Net.Objects.Modules.Implementations
{
Expand All @@ -16,7 +17,7 @@ internal class Favourite : IFavourite
public int NumberOfInverters { get; set; }
public int InverterPower { get; set; }
public string InverterBrand { get; set; }
public string Orientation { get; set; }
public Orientation Orientation { get; set; }
public decimal? ArrayTilt { get; set; }
public string Shade { get; set; }
public DateTime? InstallDate { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions src/PVOutput.Net/Objects/Modules/Implementations/System.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class System : ISystem
public int NumberOfInverters { get; set; }
public int InverterPower { get; set; }
public string InverterBrand { get; set; }
public string Orientation { get; set; }
public Orientation Orientation { get; set; }
public decimal ArrayTilt { get; set; }
public string Shade { get; set; }
public DateTime InstallDate { get; set; }
Expand All @@ -26,7 +26,7 @@ internal class System : ISystem
// Secondary
public int? SecondaryNumberOfPanels { get; set; }
public int? SecondaryPanelPower { get; set; }
public string SecondaryOrientation { get; set; }
public Orientation? SecondaryOrientation { get; set; }
public decimal? SecondaryArrayTilt { get; set; }

// Tariffs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using PVOutput.Net.Enums;

namespace PVOutput.Net.Objects.Modules.Implementations
{
Expand All @@ -10,7 +11,7 @@ internal class SystemSearchResult : ISystemSearchResult
public int SystemSize { get; set; }
public int Postcode { get; set; }
public string Country { get; set; }
public string Orientation { get; set; }
public Orientation Orientation { get; set; }
public int NumberOfOutputs { get; set; }
public string LastOutput { get; set; }
public int SystemId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using PVOutput.Net.Enums;
using PVOutput.Net.Objects.Core;
using PVOutput.Net.Objects.Modules.Implementations;

Expand All @@ -24,7 +25,7 @@ public FavouriteObjectStringReader()
(t, s) => t.NumberOfInverters = FormatHelper.GetValueOrDefault<int>(s),
(t, s) => t.InverterPower = FormatHelper.GetValueOrDefault<int>(s),
(t, s) => t.InverterBrand = s,
(t, s) => t.Orientation = s,
(t, s) => t.Orientation = FormatHelper.DescriptionToEnumValue<Orientation>(s),
(t, s) => t.ArrayTilt = FormatHelper.GetValue<decimal>(s),
(t, s) => t.Shade = s,
(t, s) => t.InstallDate = FormatHelper.ParseOptionalDate(s),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private void ParseBaseProperties(ISystem target, TextReader reader)
(t, s) => t.NumberOfInverters = FormatHelper.GetValueOrDefault<int>(s),
(t, s) => t.InverterPower = FormatHelper.GetValueOrDefault<int>(s),
(t, s) => t.InverterBrand = s,
(t, s) => t.Orientation = s,
(t, s) => t.Orientation = FormatHelper.DescriptionToEnumValue<Orientation>(s),
(t, s) => t.ArrayTilt = FormatHelper.GetValueOrDefault<decimal>(s),
(t, s) => t.Shade = s,
(t, s) => t.InstallDate = FormatHelper.ParseDate(s),
Expand All @@ -43,7 +43,7 @@ private void ParseBaseProperties(ISystem target, TextReader reader)
(t, s) => t.StatusInterval = FormatHelper.GetValueOrDefault<int>(s),
(t, s) => t.SecondaryNumberOfPanels = FormatHelper.GetValue<int>(s),
(t, s) => t.SecondaryPanelPower = FormatHelper.GetValue<int>(s),
(t, s) => t.SecondaryOrientation = s,
(t, s) => t.SecondaryOrientation = !string.IsNullOrWhiteSpace(s) ? FormatHelper.DescriptionToEnumValue<Orientation>(s) : (Orientation?)null,
(t, s) => t.SecondaryArrayTilt = FormatHelper.GetValue<decimal>(s)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using PVOutput.Net.Enums;
using PVOutput.Net.Objects.Core;

namespace PVOutput.Net.Objects.Modules.Readers
Expand All @@ -25,7 +26,7 @@ public SystemSearchResultObjectStringReader()
t.Postcode = postcode;
t.Country = country;
},
(t, s) => t.Orientation = s,
(t, s) => t.Orientation = FormatHelper.DescriptionToEnumValue<Orientation>(s),
(t, s) => t.NumberOfOutputs = FormatHelper.GetValueOrDefault<int>(s),
(t, s) => t.LastOutput = s,
(t, s) => t.SystemId = FormatHelper.GetValueOrDefault<int>(s),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task FavouriteReader_ForResponse_CreatesCorrectObjects()
Assert.That(favourite.NumberOfInverters, Is.EqualTo(1));
Assert.That(favourite.InverterPower, Is.EqualTo(2000));
Assert.That(favourite.InverterBrand, Is.EqualTo("CMS"));
Assert.That(favourite.Orientation, Is.EqualTo("N"));
Assert.That(favourite.Orientation, Is.EqualTo(Orientation.North));
Assert.That(favourite.ArrayTilt, Is.EqualTo(30.5d));
Assert.That(favourite.Shade, Is.EqualTo("No"));
Assert.That(favourite.InstallDate, Is.EqualTo(new DateTime(2010, 1, 1)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using NUnit.Framework;
using PVOutput.Net.Enums;
using PVOutput.Net.Modules;
using PVOutput.Net.Objects;
using PVOutput.Net.Objects.Modules.Readers;
Expand Down Expand Up @@ -201,7 +202,7 @@ public async Task SearchReader_ForResponse_CreatesCorrectObject()
Assert.That(result.SystemSize, Is.EqualTo(9360));
Assert.That(result.Postcode, Is.EqualTo(4280));
Assert.That(result.Country, Is.EqualTo("Australia"));
Assert.That(result.Orientation, Is.EqualTo("NW"));
Assert.That(result.Orientation, Is.EqualTo(Orientation.NorthWest));
Assert.That(result.NumberOfOutputs, Is.EqualTo(81));
Assert.That(result.LastOutput, Is.EqualTo("2 days ago"));
Assert.That(result.SystemId, Is.EqualTo(249));
Expand Down
10 changes: 7 additions & 3 deletions tests/PVOutput.Net.Tests/Modules/System/SystemServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@ public async Task SystemReader_WithMinimalResponse_CreatesCorrectObject()
Assert.That(result.NumberOfInverters, Is.EqualTo(1));
Assert.That(result.InverterPower, Is.EqualTo(5500));
Assert.That(result.InverterBrand, Is.EqualTo("Fronius Primo 3.6-1"));
Assert.That(result.Orientation, Is.EqualTo("E"));
Assert.That(result.Orientation, Is.EqualTo(Orientation.East));
Assert.That(result.ArrayTilt, Is.EqualTo(53.1d));
Assert.That(result.Shade, Is.EqualTo("None"));
Assert.That(result.InstallDate, Is.EqualTo(new DateTime(2016, 10, 01)));
Assert.That(result.SecondaryOrientation, Is.Null);
Assert.That(result.SecondaryArrayTilt, Is.Null);
Assert.That(result.SecondaryNumberOfPanels, Is.Null);
Assert.That(result.SecondaryPanelPower, Is.Null);
Assert.That(result.Location.Latitude, Is.EqualTo(51.0d));
Assert.That(result.Location.Longitude, Is.EqualTo(6.1d));
Assert.That(result.StatusInterval, Is.EqualTo(5));
Expand All @@ -106,7 +110,7 @@ public async Task SystemReader_ForResponse_CreatesCorrectObject()
Assert.That(result.NumberOfInverters, Is.EqualTo(1));
Assert.That(result.InverterPower, Is.EqualTo(5500));
Assert.That(result.InverterBrand, Is.EqualTo("Fronius Primo 3.6-1"));
Assert.That(result.Orientation, Is.EqualTo("E"));
Assert.That(result.Orientation, Is.EqualTo(Orientation.East));
Assert.That(result.ArrayTilt, Is.EqualTo(53.1d));
Assert.That(result.Shade, Is.EqualTo("None"));
Assert.That(result.InstallDate, Is.EqualTo(new DateTime(2016, 8, 22)));
Expand All @@ -115,7 +119,7 @@ public async Task SystemReader_ForResponse_CreatesCorrectObject()
Assert.That(result.StatusInterval, Is.EqualTo(5));
Assert.That(result.SecondaryNumberOfPanels, Is.EqualTo(10));
Assert.That(result.SecondaryPanelPower, Is.EqualTo(190));
Assert.That(result.SecondaryOrientation, Is.EqualTo("W"));
Assert.That(result.SecondaryOrientation, Is.EqualTo(Orientation.West));
Assert.That(result.SecondaryArrayTilt, Is.EqualTo(33.5d));
Assert.That(result.ExportTariff, Is.EqualTo(17.37d));
Assert.That(result.ImportPeakTariff, Is.EqualTo(20.46d));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public partial class SystemServiceTests

public const string POSTSYSTEM_URL = "postsystem.jsp";

public const string SYSTEM_RESPONSE_SIMPLE = "Test System,4125,1234,15,275,JA Solar mono,1,5500,Fronius Primo 3.6-1,E,53.1,None,20161001,51.0,6.1,5;;0";
public const string SYSTEM_RESPONSE_SIMPLE = "Test System,4125,1234,15,275,JA Solar mono,1,5500,Fronius Primo 3.6-1,E,53.1,None,20161001,51.0,6.1,5;;";

public const string SYSTEM_RESPONSE_EXTENDED = "Test System,4125,1234,15,275,JA Solar mono,1,5500,Fronius Primo 3.6-1,E,53.1,None,20160822,51.0,6.1,5,10,190,W,33.5;17.37,20.46,20.2,25.4,22.65,40.0;12,232,480,512;1;DC-1 Voltage,V,DC-2 Voltage,V,DC-DC Booster Temp,°C,DC-1 Power (2x13x290Wp),W;61,106,252,380,430,425,417,354,253,159,70,48,400,350,300,250,200,150,100,175,275,375,475,525";

Expand Down

0 comments on commit b8cd3fb

Please sign in to comment.