Skip to content

Commit 0577024

Browse files
committed
Better docs
1 parent 16a27d2 commit 0577024

2 files changed

Lines changed: 33 additions & 6 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ pip install -e .
3131
### Usage
3232

3333
```python
34+
import logging
3435
from py_incharge import InChargesend_remote_start
3536

37+
# Optional: logging.basicConfig(level=logging.INFO)
3638
client = InCharge(email="your@email.com", password="your_password", subscription_key="your_subscription_key")
3739
client.login()
3840

src/py_incharge/client.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,17 @@ def __init__(self, email: str, password: str, subscription_key: str):
3030
self.bearer_token: Optional[str] = None
3131

3232
def login(self):
33-
"""Login and retrieve bearer token"""
34-
logging.info("Starting login process...")
33+
"""
34+
Login and retrieve bearer token. The bearer token is a token stored by the application in
35+
the session storage after a successful login. It is used to authenticate API requests
36+
and websocket connections.
37+
38+
This method uses Selenium to automate the login process by filling in the email and password fields
39+
on the login page, submitting the form, and then retrieving the token from the session storage.
40+
41+
Note: This method requires the Chrome WebDriver to be installed and available in the system PATH.
42+
"""
43+
3544
logging.info("Starting the login process to retrieve the bearer token...")
3645

3746
options = webdriver.ChromeOptions()
@@ -43,7 +52,7 @@ def login(self):
4352
driver.get("https://myincharge.vattenfall.com/")
4453

4554
try:
46-
logging.info("Filling in the login form...")
55+
logging.info("Filling in email and password...")
4756
email_input = find_element_through_shadow(
4857
driver,
4958
hosts_css_chain=["ic-input[formcontrolname='username']"],
@@ -84,7 +93,12 @@ def login(self):
8493
logging.info("Login successful, bearer token obtained")
8594

8695
def get_ticket(self) -> str:
87-
"""Get ticket for websocket authentication"""
96+
"""
97+
Before starting a remote transaction, a ticket ID must be obtained.
98+
This ticket is used to authenticate the websocket connection and is required
99+
to start a remote transaction. This function sends a POST request to the
100+
InCharge API to obtain a ticket id.
101+
"""
88102
if not self.bearer_token:
89103
raise ValueError("Must login first before getting ticket")
90104

@@ -104,7 +118,12 @@ def get_ticket(self) -> str:
104118
return response.text.strip().strip('"')
105119

106120
def get_remote_start_command_id(self, station_name: str) -> str:
107-
"""Get command ID for remote start transaction"""
121+
"""
122+
Nobody knows why, but the command ID is not static and must be fetched
123+
from the InCharge API every time before starting a remote transaction.
124+
This function sends a GET request to the InCharge API to retrieve the command id
125+
for the remote start transaction command for the specified station.
126+
"""
108127
if not self.bearer_token:
109128
raise ValueError("Must login first before getting command ID")
110129

@@ -129,7 +148,13 @@ def get_remote_start_command_id(self, station_name: str) -> str:
129148
def start_remote_transaction(
130149
self, station_name: str, rfid: str, connector_id: int = 1
131150
):
132-
"""Start a remote transaction on the specified station"""
151+
"""
152+
In short: this method will turn on your EV charger.
153+
154+
This method starts a remote transaction on the specified station using the provided RFID and connector ID.
155+
It first retrieves the command ID for the remote start transaction, then obtains a ticket ID,
156+
and finally establishes a websocket connection to send the remote start command.
157+
"""
133158
if not self.bearer_token:
134159
raise ValueError("Must login first before starting transaction")
135160

0 commit comments

Comments
 (0)