Skip to content

Commit

Permalink
updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Floris272 committed Feb 29, 2024
1 parent a094f7d commit 5bb347a
Show file tree
Hide file tree
Showing 41 changed files with 176 additions and 532 deletions.
Binary file modified .coverage
Binary file not shown.
3 changes: 3 additions & 0 deletions .github/workflows/lint_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ jobs:
run: |
make lint
make test
make black
make ruff
make mypy
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
install:
pip install -r requirements.txt
pip install -r requirements.txt && pip install -r docs/requirements.txt

lint:
pylint src

mypy:
mypy src

black:
black src tests

ruff:
ruff --fix src tests && ruff format src tests

test:
python -m pytest

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The library is an asyncio-driven library that interfaces with the Websocket API

### Requirements

- Python 3.9 or newer
- Python 3.11 or newer
- websockets
- asyncio

Expand Down
4 changes: 4 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# autodoc
homeassistant
bluecurrent-api

# readthedocs dependencies
alabaster==0.7.12
attrs==21.2.0
Expand Down
Binary file removed docs/source/_static/img/diagram.png
Binary file not shown.
Binary file removed docs/source/_static/img/step_card.png
Binary file not shown.
Binary file removed docs/source/_static/img/step_user.png
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import sys
sys.path.insert(0, os.path.abspath('../../src'))
sys.path.insert(0, os.path.abspath('../../'))


# -- Project information -----------------------------------------------------
Expand Down
4 changes: 0 additions & 4 deletions docs/source/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
maxdepth: 1
glob:
---
documentation/class-diagram
documentation/api-package-example
documentation/api-package-documentation
documentation/integration-documentation
documentation/platforms-documentation
documentation/config-flow-documentation
documentation/automations-documentation
```
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Client

```{eval-rst}
.. automodule:: bluecurrent_api.client
.. automodule:: src.bluecurrent_api.client
:members:
:private-members:
:special-members:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Exceptions

```{eval-rst}
.. automodule:: bluecurrent_api.exceptions
.. automodule:: src.bluecurrent_api.exceptions
:members:
:private-members:
:special-members:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Utils

```{eval-rst}
.. automodule:: bluecurrent_api.utils
.. automodule:: src.bluecurrent_api.utils
:members:
:private-members:
:special-members:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Websocket

```{eval-rst}
.. automodule:: bluecurrent_api.websocket
.. automodule:: src.bluecurrent_api.websocket
:members:
:private-members:
:special-members:
Expand Down
7 changes: 1 addition & 6 deletions docs/source/documentation/api-package-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

To give a better view on how to package works here is an example on how to use the API package.

First an instance of the client is created.

Then connection with the API is made with `connect` with an API token generated in the driver portal.

And last with `asyncio.gather` the loop is started, and a receiver is given. All incoming messages will be routed to the given method.

```python
from bluecurrent_api import Client
import asyncio
Expand All @@ -27,6 +21,7 @@ async def main():
# example requests
async def requests():
await client.get_charge_points()
await client.wait_for_response()
await client.disconnect()

# start the loop and send requests
Expand Down
29 changes: 0 additions & 29 deletions docs/source/documentation/automations-documentation.md

This file was deleted.

9 changes: 0 additions & 9 deletions docs/source/documentation/class-diagram.md

This file was deleted.

44 changes: 0 additions & 44 deletions docs/source/documentation/config-flow-documentation.md

This file was deleted.

106 changes: 6 additions & 100 deletions docs/source/documentation/integration-documentation.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,9 @@
# Integration

### async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool

- Retrieves the api token from the config_entry.
- Tries to connect to the API.
- Starts the loop.
- Waits until `CHARGE_POINTS` is received.
- Stores the connector, so it can be retrieved in other classes.
- Tells Ha to start the platform setup.
- Sets disconnect to be called when the integration is unloaded.
- Defines all service methods.
- Registers services.

### async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool

- Unloads the config entry.

### set_entities_unavailable(hass: HomeAssistant, config_id: str)

- Sets all BlueCurrent entities to unavailable.

## Connector

charge_points: dict[str, dict]
grid: dict[str, Any]

### \_\_init\_\_(hass: HomeAssistant, config: ConfigEntry, client: Client)

- Stores the given parameters.

### connect(token: str)

- Sets `on_data` as the receiver.
- Connects to the API.

### on_data(message: dict)

[](../flow/on-data.md)

Routes the received message to the correct function based on the object.

#### handle_charge_points(data: list)

- Adds all evse_ids to `charge_points` and sends status requests for each. Also sends grid status request.

### get_charge_point_data(self, evse_id: str)

- Requests the status and settings of the charge point with the given evse_id.

### add_charge_point(self, evse_id: str, model: str, name: str)

- Adds the charge point to `charge_points`

### update_charge_point(self, evse_id: str, data: dict)

- Updates the key, value pairs of charge point with the given evse_id and dispatches a signal.

#### handle_activity(data: dict)

- The state of the block / operative switch is not returned with `CH_STATUS`, But the state is related to the state of the `activity` sensor. So this function sets the state of `block` switch based on the state of `activity`.

### dispatch_value_update_signal(self, evse_id: str)
- Dispatches a `value_update`

### dispatch_grid_update_signal(self) -> None:
- Dispatches a `grid_update`

### start_loop()

- Tries to start the loop for listening to the API.
- If an error happens, a warning is logged and the reconnect method is called after 1 second.

```{note}
The reason for the one second delay is that the connection closes quite frequently so with this it 'immediately' reconnects.
```{toctree}
---
maxdepth: 1
glob:
---
integration-documentation/*
```

### reconnect(self, event_time: datetime | None = None)

- Tries to reconnect the API, starts the loop again and requests the charge points.
- If the reconnection fails the entities will be set unavailable and the reconnect method will be called again in 20 seconds.
- If the error was `request limit reached`, the reconnect method is called after the next limit reset.

### disconnect()

- Disconnects with the API, if the connection was already closed and a `WebsocketError` is thrown, ignore it.

## BlueCurrentEntity(Entity)

### \_\_init\_\_(connector: Connector, evse_id: str | None = None)

- Stores connector
- If evse_id is given, device info is added to entity.

### async_added_to_hass()

- Connects the dispatcher to a signal to call `update` when triggered.

Update method calls `update_from_latest_data()` and writes the state to HA.

### update_from_latest_data()

- Method that is implemented in the platform classes.
23 changes: 23 additions & 0 deletions docs/source/documentation/integration-documentation/config_flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ConfigFlow

```{eval-rst}
.. automodule:: homeassistant.components.blue_current.config_flow
:members:
:private-members:
:special-members:
:exclude-members: __weakref__
```

### async_step_user
- This method is called when a user adds the integration to Home Assistant. If the user_input is None it returns the form with `async_show_form`.
- If there is user input it will validate the given token and get the customer id and email. The customer id is used as the unique id of the config entry and the email as title.
- If an exception happens it will add an error to the `errors` dict and this will be given to `async_show_form` and shown to the user.
- If there are no errors it sets the unique id and stores the current entry if there is one.
- If there is a current entry 'update_entry' is called and the flow will be aborted because the reauth is successful.
- Otherwise, the entry is created normally.


### async_step_reauth

- Is called when a config is reconfigured. This button is shown when the `ConfigEntryAuthFailed` exception is raised in `async_setup_entry` in `__init__.py`.
- Calls `async_step_user` in which the entry is updated instead of creating a new one.
9 changes: 9 additions & 0 deletions docs/source/documentation/integration-documentation/entity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Entity

```{eval-rst}
.. automodule:: homeassistant.components.blue_current.entity
:members:
:private-members:
:special-members:
:exclude-members: __weakref__
```
9 changes: 9 additions & 0 deletions docs/source/documentation/integration-documentation/init.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Init

```{eval-rst}
.. automodule:: homeassistant.components.blue_current.__init__
:members:
:private-members:
:special-members:
:exclude-members: __weakref__
```
9 changes: 9 additions & 0 deletions docs/source/documentation/integration-documentation/sensor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Sensor

```{eval-rst}
.. automodule:: homeassistant.components.blue_current.sensor
:members:
:private-members:
:special-members:
:exclude-members: __weakref__
```
Loading

0 comments on commit 5bb347a

Please sign in to comment.