edf_api package

Submodules

edf_api.models module

class edf_api.models.Address(city, postal_code, street, number)

Bases: object

Represents an address

city: str
static from_xml(p)
number: str
postal_code: str
street: str
class edf_api.models.ElecInfo(status, outage_start_date, outage_end_date, number_affected_homes, grid_status, title, description, outage)

Bases: object

Represents the electrical grid status

description: str
static from_json(coupure, crise)
grid_status: int
static no_outage()
number_affected_homes: int
outage: bool
outage_end_date: str
outage_start_date: str
status: str
title: str

edf_api.auth module

class edf_api.auth.EDFAuth(session)

Bases: object

Class to handle authentication with the EDF APIs and retrieve essential data to use them

async get_insee(addr)

Function to retrieve the INSEE code from an address :type addr: Address :param addr: an address object

Return type

str

Returns

the insee code

get_login_url(redirect='edfetmoiauth:/oauthcallback')

Function to generate a login url for the first connection :type redirect: str :param redirect: the redirection url for the login request

Return type

Tuple[str, str, str, str]

Returns

the link to edf login portal the code_verifier associated with this request (to use when retreiving the token) the state associated with this request (to compare when the results of this request are received) the nonce associated with this request (to use when retreiving the token)

async get_pdl(access_token, accord_co, numero_bp)

Function to retrieve the PDL number and to check if the counter status

Parameters
  • access_token (str) – a valid access_token

  • accord_co (str) – the contract agreement number (from get_person_data)

  • numero_bp (str) – the business partner number (from get_person_data)

Returns

True if it is capable of reporting mesaurements, else False the PDL number of the counter

Return type

the status of the counter

async get_person_data(access_token)

Function to retrieve information related to the user

Parameters

access_token (str) – a valid access_token

Return type

Tuple[str, str, Address]

Returns

the contract agreement number the business partner number the address of the user

async get_token(code=None, code_verifier=None, nonce=None, refresh_token=None)

Function to retrieve the access and refresh token The token can be requested using a code (for the first login) or a refresh token For the first mode, you need to provide the code, code_verifier and nonce arguments For the second mode, you only need to provide the refresh_token

Parameters
  • code (Optional[str]) – the code returned by the login url

  • code_verifier (Optional[str]) – the code returned by the get_login_url function

  • nonce (Optional[str]) – the nonce returned by the get_login_url function

  • refresh_token (Optional[str]) – the refresh_token to use to request a new access_token

Return type

Tuple[str, str, int]

Returns

the new access_token the refresh_token (same as the one in argument if specified) the expiration date of the access_token

edf_api.exc module

exception edf_api.exc.InvalidNonceException

Bases: Exception

Module contents

class edf_api.EDFApi(session, access_token, refresh_token, expiration, bp_num, pdl, insee)

Bases: object

Class to handle data retreival

async get_elec_daily_data(start, end, retry=False)

Function to get the daily consumption data for electricity

Parameters
  • start (str) – the start date for the retrieved data in YYYY-MM-DD format

  • end (str) – the end date for the retrieved data in YYYY-MM-DD format

  • retry (bool) – (internal) used to know if this is the first call to this function or if this is a retry

Return type

dict

async get_elec_monthly_data(start, end, retry=False)

Function to get the monthly consumption data for electricity

Parameters
  • start (str) – the start date for the retrieved data in YYYY-MM format

  • end (str) – the end date for the retrieved data in YYYY-MM format

  • retry (bool) – (internal) used to know if this is the first call to this function or if this is a retry

Return type

dict

async get_elec_monthly_data_similar_homes(start, end, retry=False)

Function to get the monthly consumption data for electricity for similar homes

Parameters
  • start (str) – the start date for the retrieved data in YYYY-MM format

  • end (str) – the end date for the retrieved data in YYYY-MM format

  • retry (bool) – (internal) used to know if this is the first call to this function or if this is a retry

Return type

dict

async get_grid_info()

Function to get the grid status for a specific insee code

Return type

ElecInfo

Returns

an ElecInfo object

save_tokens()

Function to save the access_token (which may have changed), refresh_token and expiration date for future use

Return type

Tuple[str, str, str]

Returns

the access token the refresh token the expiration timestamp of the access token