diff --git a/composer.json b/composer.json index 0441a80..7b34d52 100644 --- a/composer.json +++ b/composer.json @@ -5,8 +5,9 @@ "minimum-stability": "stable", "require": { "php": "^7.4", + "ext-json": "*", "holicz/simple-exception": "^1.1", - "thecodingmachine/safe": "^1.1" + "thecodingmachine/safe": "1.1" }, "require-dev": { "phpstan/phpstan": "^0.12.18", diff --git a/composer.lock b/composer.lock index 5d0e540..4cf1df4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "cf5da207b342941494d4612b6dfe25be", + "content-hash": "9a6f5f3cf45d4d416b9144ff31478945", "packages": [ { "name": "holicz/simple-exception", diff --git a/src/Adapter/PvgisAdapter.php b/src/Adapter/PvgisAdapter.php index 08c505a..09399a8 100644 --- a/src/Adapter/PvgisAdapter.php +++ b/src/Adapter/PvgisAdapter.php @@ -15,6 +15,16 @@ final class PvgisAdapter { private const API_URL = 'https://re.jrc.ec.europa.eu/api/pvcalc?peakpower=1&pvtechchoice=crystSi&mountingplace=building&loss=1&outputformat=json&angle=35&lat=%s&lon=%s'; + /** + * Multiplier to change the PVGIS result in order to get desired production + */ + private float $multiplier; + + public function __construct(float $multiplier = 1.0) + { + $this->multiplier = $multiplier; + } + /** * @param string $latitude * @param string $longitude @@ -43,15 +53,16 @@ public function getPvgisData(string $latitude, string $longitude): ElectricityPr * @return ElectricityProduction * * @throws InvalidResponseFormatException + * @throws StringsException */ private function parsePvgisResponse(string $response): ElectricityProduction { try { $response = json_decode($response, true, 512, JSON_THROW_ON_ERROR); - $electricityProduction = new ElectricityProduction($response['outputs']['totals']['fixed']['E_m']); + $electricityProduction = new ElectricityProduction($this->multiplier * $response['outputs']['totals']['fixed']['E_m']); foreach ($response['outputs']['monthly']['fixed'] as $month) { - $electricityProduction->addMonthlyProduction($month['month'], $month['E_m']); + $electricityProduction->addMonthlyProduction($month['month'], $this->multiplier * $month['E_m']); } } catch (Exception $e) { throw new InvalidResponseFormatException(['response' => $response]);