mysolenso.auth - Authentication

MySolenso authentication module.

Provides the MySolensoAuth class, which manages the HTTP session, authentication via password or token, and generation of authorisation headers for the two underlying APIs (Solenso and Hoymiles).

Source: https://github.com/thanatos-vf-2000/mysolenso

Example

Connect with a password (the token is retrieved automatically):

from mysolenso.auth import MySolensoAuth

auth = MySolensoAuth(username="jdoe", password="encrypted_pass")
print(auth.isConnect())                   # True
print(auth.token)                         # "eyJ..."
print(auth.get_auth_headers_solenso())

Connect directly with an existing token:

auth = MySolensoAuth(username="jdoe", token="eyJ...")
headers = auth.get_auth_headers_hoymiles()
class mysolenso.auth.MySolensoAuth(username, password=None, token=None)[source]

Bases: object

Secure and robust HTTP client for the Solenso API.

Handles authentication (via encrypted password or a pre-existing token), maintains the HTTP session with the correct headers, and exposes the helper methods required by other library modules.

The class is thread-safe: token reads and writes are protected by an internal threading.Lock.

Parameters:
  • username (str) – Email address or account identifier on Solenso. Must not be empty or blank.

  • password (Optional[str]) – Encrypted password as sent by the Solenso web interface. Triggers a call to _authenticate() when provided.

  • token (Optional[str]) – Existing session token. Used as-is without any additional network call.

Raises:
username

Account identifier (whitespace-stripped).

Type:

str

Example

auth = MySolensoAuth(username="jdoe", token="tok_abc123")
if auth.isConnect():
    headers = auth.get_auth_headers_solenso()
property token: str

Current session token.

Returns:

JWT/opaque token returned by the API, or an empty string if not authenticated.

Return type:

str

property token_language: str

Language code sent in the session cookie.

Returns:

Language code in ll_LL format (e.g. "fr_fr").

Return type:

str

isConnect()[source]

Check whether a valid session token is present in memory.

Returns:

True if the token is non-empty, False otherwise.

Return type:

bool

Example

auth = MySolensoAuth(username="jdoe", token="tok_abc123")
assert auth.isConnect() is True
auth.disconnect()
assert auth.isConnect() is False
get_auth_headers_solenso()[source]

Build the Cookie headers for the Solenso API.

Calls to the Solenso API (profile, stations…) authenticate via two cookies: solenso_token_language and solenso_token.

Returns:

Dictionary containing the "Cookie" key with the formatted value.

Return type:

dict

Raises:

MySolensoAuthenticationException – If no valid token is available (disconnected session).

Example

headers = auth.get_auth_headers_solenso()
# {"Cookie": "solenso_token_language=fr_fr; solenso_token=eyJ..."}
get_auth_headers_hoymiles()[source]

Build the Authorization headers for the Hoymiles API.

Hoymiles micro-inverters used by Solenso require an Authorization: Bearer <token> header.

Returns:

Dictionary containing the "Authorization" key with the Bearer scheme.

Return type:

dict

Raises:

MySolensoAuthenticationException – If no valid token is available.

Example

headers = auth.get_auth_headers_hoymiles()
# {"Authorization": "Bearer eyJ..."}
disconnect()[source]

Remove the session token from memory.

After this call, isConnect() returns False and any call to get_auth_headers_* methods will raise an exception.

Note

This method does not revoke the token server-side on Solenso; it only clears the local token.

Return type:

None