Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use plain Black code style #7

Merged
merged 2 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-code-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
python -m isort ucapi/. --check --verbose
- name: Check code formatting with black
run: |
python -m black ucapi --check --verbose --line-length 120
python -m black ucapi --check --verbose
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/integration-python-library.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions .idea/runConfigurations/Check_Black_style.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions .idea/runConfigurations/Check_flake8.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions .idea/runConfigurations/Check_isort.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions .idea/runConfigurations/Check_pylint.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions .idea/runConfigurations/Run_isort.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Python API wrapper for the UC Integration API
[![PyPi](https://img.shields.io/pypi/v/ucapi.svg)](https://pypi.org/project/ucapi)
[![License](https://img.shields.io/github/license/unfoldedcircle/ucapi.svg)](LICENSE)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

This library simplifies writing Python based integrations for the [Unfolded Circle Remote Two](https://www.unfoldedcircle.com/)
by wrapping the [WebSocket Integration API](https://github.com/unfoldedcircle/core-api/tree/main/integration-api).
Expand All @@ -19,6 +22,12 @@ Not yet supported:
Requirements:
- Python 3.10 or newer

## Installation

Use pip:
```shell
pip3 install ucapi
```
## Usage

Install build tools:
Expand Down
15 changes: 7 additions & 8 deletions docs/code_guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Note: once <https://github.com/pypa/pip/issues/11440> is implemented, the requir
### Linting

```shell
python -m pylint ucapi
python3 -m pylint ucapi
```

- The tool is configured in `.pylintrc`.
Expand All @@ -34,7 +34,7 @@ Linting integration in PyCharm/IntelliJ IDEA:
Import statements must be sorted with [isort](https://pycqa.github.io/isort/):

```shell
python -m isort ucapi/.
python3 -m isort ucapi/.
```

- The tool is configured in `pyproject.toml` to use the `black` code-formatting profile.
Expand All @@ -44,23 +44,22 @@ python -m isort ucapi/.
Source code is formatted with the [Black code formatting tool](https://github.com/psf/black):

```shell
python -m black ucapi --line-length 120
python3 -m black ucapi --line-length 120
```

PyCharm/IntelliJ IDEA integration:
1. Go to `Preferences or Settings -> Tools -> Black`
2. Configure:
- Python interpreter
- Use Black formatter: `On code reformat` & optionally `On save`
- Arguments: `--line-length 120`

## Verify

The following tests are run as GitHub action for each push on the main branch and for pull requests.
They can also be run anytime on a local developer machine:
```shell
python -m pylint ucapi
python -m flake8 ucapi --count --show-source --statistics
python -m isort ucapi/. --check --verbose
python -m black ucapi --check --verbose --line-length 120
python3 -m pylint ucapi
python3 -m flake8 ucapi --count --show-source --statistics
python3 -m isort ucapi/. --check --verbose
python3 -m black ucapi --check --verbose
```
6 changes: 4 additions & 2 deletions examples/hello_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
api = ucapi.IntegrationAPI(loop)


async def cmd_handler(entity: ucapi.Button, cmd_id: str, _params: dict[str, Any] | None) -> ucapi.StatusCodes:
async def cmd_handler(
entity: ucapi.Button, cmd_id: str, _params: dict[str, Any] | None
) -> ucapi.StatusCodes:
"""
Push button command handler.

Expand All @@ -28,7 +30,7 @@ async def cmd_handler(entity: ucapi.Button, cmd_id: str, _params: dict[str, Any]

@api.listens_to(ucapi.Events.CONNECT)
async def on_connect() -> None:
"""When the remote connects, we just set the device state. We are ready all the time!"""
# When the remote connects, we just set the device state. We are ready all the time!
await api.set_device_state(ucapi.DeviceStates.CONNECTED)


Expand Down
18 changes: 12 additions & 6 deletions examples/setup_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ async def driver_setup_handler(msg: ucapi.SetupDriver) -> ucapi.SetupAction:

Either start the setup process or handle the provided user input data.

:param msg: the setup driver request object, either DriverSetupRequest or UserDataResponse
:param msg: the setup driver request object, either DriverSetupRequest,
UserDataResponse or UserConfirmationResponse
:return: the setup action on how to continue
"""
if isinstance(msg, ucapi.DriverSetupRequest):
Expand All @@ -31,16 +32,19 @@ async def driver_setup_handler(msg: ucapi.SetupDriver) -> ucapi.SetupAction:
return ucapi.SetupError()


async def handle_driver_setup(msg: ucapi.DriverSetupRequest) -> ucapi.RequestUserInput | ucapi.SetupError:
async def handle_driver_setup(
msg: ucapi.DriverSetupRequest,
) -> ucapi.SetupAction:
"""
Start driver setup.

Initiated by Remote Two to set up the driver.

:param msg: not used, value(s) of input fields in the first setup screen. See setup_data_schema in driver metadata.
:param msg: value(s) of input fields in the first setup screen.
:return: the setup action on how to continue
"""
# for our demo we clear everything, a real driver might have to handle this differently
# For our demo we simply clear everything!
# A real driver might have to handle this differently
api.available_entities.clear()
api.configured_entities.clear()

Expand Down Expand Up @@ -141,7 +145,9 @@ async def handle_user_data_response(msg: ucapi.UserDataResponse) -> ucapi.SetupA
return ucapi.SetupError()


async def cmd_handler(entity: ucapi.Button, cmd_id: str, _params: dict[str, Any] | None) -> ucapi.StatusCodes:
async def cmd_handler(
entity: ucapi.Button, cmd_id: str, _params: dict[str, Any] | None
) -> ucapi.StatusCodes:
"""
Push button command handler.

Expand All @@ -159,7 +165,7 @@ async def cmd_handler(entity: ucapi.Button, cmd_id: str, _params: dict[str, Any]

@api.listens_to(ucapi.Events.CONNECT)
async def on_connect() -> None:
"""When the remote connects, we just set the device state. We are ready all the time!"""
# When the remote connects, we just set the device state. We are ready all the time!
await api.set_device_state(ucapi.DeviceStates.CONNECTED)


Expand Down
Loading