aeneria/grdf-adict

A small library to use a part of GRDF ADICT API with PHP : https://site.grdf.fr/web/grdf-adict/

0.2 2021-06-04 17:47 UTC

This package is auto-updated.

Last update: 2022-08-09 14:57:35 UTC


README

⚠⚠ Work in progress ⚠⚠

Firstly developped to be used in aeneria, this small library let you use easily GRDFS ADICT API.

Requirements

PHP 7.3 or higher

Getting started

First of all, you will need a ClientID and a ClientSecret to use GRDFS ADICT API. Visit https://grdf-adict.grdf.fr, to know how to get ones. During your registration you will also give a redirect URL, you will need it to use this library.

Now that you have those, install the library with composer:

composer require aeneria/grdf-adict

If you are using a framework such as Symfony, you can declare the library as a service and use it with dependency injection:

# config/services.yaml

services:
    Aeneria\GrdfAdictApi\Service\DataConnectService:
        class: Aeneria\GrdfAdictApi\Service\GrdfAdictService
        arguments:
            $httpClient: "@http_client"
            $authEndpoint: "https://mon-compte-particulier.enedis.fr"
            $tokenEndpoint: "https://gw.prd.api.enedis.fr "
            $dataEndpoint: "https://gw.prd.api.enedis.fr"
            $clientId: "YOUR_CLIENT_ID"
            $clientSecret: "YOUR_CLIENT_SECRET"
            $redirectUri: "YOUR_REDIRECT_URI"

Or you can declare it in your code this way:

<?php

use Aeneria\GrdfAdictApi\Services\GrdfAdictService;

//...

$grdfAdict = new GrdfAdictService(
    HttpClient::create(),
    "https://mon-compte-particulier.enedis.fr",
    "https://gw.prd.api.enedis.fr "
    "https://gw.prd.api.enedis.fr",
    "YOUR_CLIENT_ID",
    "YOUR_CLIENT_SECRET",
    "YOUR_REDIRECT_URI
);

//...

Then you can use the API:

<?php

// Getting consent page URL
$grdfAdict->getAuthentificationService()->getConsentPageUrl('P6M', $state);

// Getting Tokens from Code
$token = $dataConnect->getAuthentificationService()->requestAuthorizationToken($param['code']);

// Getting Tokens from Refresh Token
$token = $dataConnect->getAuthentificationService()->requestAccessToken($token->getAccesToken());

// Getting consumption data
$meteringData = $dataConnect->getMeteringDataV4Service()->requestDailyConsumption(
    $token->getAccessToken(),
    $token->getUsagePointsId(),
    new \DateTimeImmutable('8 days ago'),
    new \DateTimeImmutable('yesterday')
);
$meteringData = $dataConnect->getMeteringDataV4Service()->requestConsumptionLoadCurve(
    $token->getAccessToken(),
    $token->getUsagePointsId(),
    new \DateTimeImmutable('2 days ago'),
    new \DateTimeImmutable('yesterday')
);

// Getting production data
$meteringData = $dataConnect->getMeteringDataV4Service()->requestDailyProduction(
    $token->getAccessToken(),
    $token->getUsagePointsId(),
    new \DateTimeImmutable('8 days ago'),
    new \DateTimeImmutable('yesterday')
);
$meteringData = $dataConnect->getMeteringDataV4Service()->requestProductionLoadCurve(
    $token->getAccessToken(),
    $token->getUsagePointsId(),
    new \DateTimeImmutable('2 days ago'),
    new \DateTimeImmutable('yesterday')
);

// Getting customer data
$address = $dataConnect->getCustomersService()->requestUsagePointAdresse(
    $token->getAccessToken(),
    $token->getUsagePointsId()
);

Support

Feel free to open an issue!