From 5ec5f6c1fb3ea7edb9d533efab369011ba0b9350 Mon Sep 17 00:00:00 2001 From: Till Date: Tue, 30 Jan 2024 21:18:18 +0100 Subject: [PATCH] Add continuous integration (#28) * Standardize code style * Add continuous integration workflow --- .clang-format | 10 ++ .github/workflows/ci.yaml | 129 ++++++++++++++++++ .pre-commit-config.yaml | 17 +++ .yamllint | 2 + README.md | 2 +- .../philips_action_button/action_button.h | 10 +- components/philips_action_button/button.py | 1 + .../philips_bean_settings/bean_settings.h | 10 +- components/philips_bean_settings/number.py | 1 + components/philips_power_switch/power.cpp | 2 +- components/philips_power_switch/power.h | 2 +- components/philips_power_switch/switch.py | 1 + components/philips_series_2200/__init__.py | 1 - .../philips_series_2200/philips_series_2200.h | 15 +- components/philips_size_settings/number.py | 1 + .../philips_size_settings/size_settings.h | 10 +- .../philips_status_sensor/text_sensor.py | 1 + pyproject.toml | 4 + requirements.txt | 1 + tests/base.yaml | 29 ++++ tests/full.yaml | 78 +++++++++++ 21 files changed, 314 insertions(+), 13 deletions(-) create mode 100644 .clang-format create mode 100644 .github/workflows/ci.yaml create mode 100644 .pre-commit-config.yaml create mode 100644 .yamllint create mode 100644 pyproject.toml create mode 100644 requirements.txt create mode 100644 tests/base.yaml create mode 100644 tests/full.yaml diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..d3c185d --- /dev/null +++ b/.clang-format @@ -0,0 +1,10 @@ +UseTab: Never +IndentWidth: 4 +NamespaceIndentation: All +AccessModifierOffset: -4 +BreakBeforeBraces: Allman +AllowShortIfStatementsOnASingleLine: false +AllowShortFunctionsOnASingleLine: false +IndentCaseLabels: false +SortIncludes: false +ColumnLimit: 0 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..cd48f18 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,129 @@ +name: CI + +# yamllint disable-line rule:truthy +on: + workflow_dispatch: + inputs: + esphome_version: + description: "ESPHome PyPi Package version to use" + required: false + type: string + push: + branches: [main, dev] + + pull_request: + merge_group: + +permissions: + contents: read + +concurrency: + # yamllint disable-line rule:line-length + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + ci: + name: ${{ matrix.name }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + max-parallel: 5 + matrix: + include: + - id: test + file: tests/full.yaml + name: Test tests/full.yaml + pio_cache_key: full + - id: test + file: tests/base.yaml + name: Test tests/base.yaml + pio_cache_key: base + - id: clang-format + name: Run clang-format + - id: yamllint + name: Run yamllint + - id: black-format + name: Run black-format + - id: isort + name: Run isort + + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + id: python + with: + python-version: "3.9" + + - name: Cache virtualenv + uses: actions/cache@v3 + with: + path: .venv + # yamllint disable-line rule:line-length + key: venv-${{ steps.python.outputs.python-version }} + restore-keys: | + venv-${{ steps.python.outputs.python-version }} + - name: Set up virtualenv + # yamllint disable rule:line-length + run: | + python -m venv .venv + source .venv/bin/activate + pip install -U pip + pip install -r requirements.txt + if [ ${{ github.event.inputs.esphome_version != '' }} == true ]; then pip install ESPHome==${{ github.event.inputs.esphome_version }}; else pip install -U ESPHome; fi + echo "$GITHUB_WORKSPACE/.venv/bin" >> $GITHUB_PATH + echo "VIRTUAL_ENV=$GITHUB_WORKSPACE/.venv" >> $GITHUB_ENV + # yamllint enable rule:line-length + + # Use per check platformio cache because checks use different parts + - name: Cache platformio + uses: actions/cache@v3 + with: + path: ~/.platformio + # yamllint disable-line rule:line-length + key: platformio-${{ matrix.pio_cache_key }}-${{ hashFiles('platformio.ini') }} + if: matrix.id == 'test' + + - run: esphome compile ${{ matrix.file }} + if: matrix.id == 'test' + env: + # Also cache libdeps, store them in a ~/.platformio subfolder + PLATFORMIO_LIBDEPS_DIR: ~/.platformio/libdeps + + - name: Run clang-format + uses: jidicula/clang-format-action@v4.11.0 + with: + clang-format-version: "13" + check-path: "components" + if: matrix.id == 'clang-format' + + - name: Run yamllint + if: matrix.id == 'yamllint' + uses: frenck/action-yamllint@v1.4.0 + + - name: Run black-format + if: matrix.id == 'black-format' + uses: psf/black@stable + with: + options: "--check --verbose" + version: "~= 24.1" + + - name: Run isort + if: matrix.id == 'isort' + uses: isort/isort-action@master + with: + requirementsFiles: "requirements.txt" + + ci-status: + name: CI Status + runs-on: ubuntu-latest + needs: [ci] + if: always() + steps: + - name: Successful deploy + if: ${{ !(contains(needs.*.result, 'failure')) }} + run: exit 0 + - name: Failing deploy + if: ${{ contains(needs.*.result, 'failure') }} + run: exit 1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..aa93c90 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,17 @@ +repos: + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 24.1.0 + hooks: + - id: black + language_version: python3.11 + + - repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + name: isort (python) + + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v17.0.6 + hooks: + - id: clang-format diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..3a07442 --- /dev/null +++ b/.yamllint @@ -0,0 +1,2 @@ +ignore: | + venv/ diff --git a/README.md b/README.md index bdb624c..6dc8054 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ESPHome Smart Coffee (Philips Series 2200) +# ESPHome Smart Coffee (Philips Series 2200) [![CI](https://github.com/TillFleisch/ESPHome-Philips-Smart-Coffee/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/TillFleisch/ESPHome-Philips-Smart-Coffee/actions/workflows/ci.yaml) This project integrates a Philips Series 2200 Coffee Machine into into [Home Assistant](https://home-assistant.io) through [ESPHome](https://esphome.io). This component has been developed on a Philips EP2220 and an ESP8266. diff --git a/components/philips_action_button/action_button.h b/components/philips_action_button/action_button.h index 24ba191..fae10b6 100644 --- a/components/philips_action_button/action_button.h +++ b/components/philips_action_button/action_button.h @@ -52,14 +52,20 @@ namespace esphome * * @param action Action to use */ - void set_action(Action action) { action_ = action; }; + void set_action(Action action) + { + action_ = action; + }; /** * @brief Reference to uart which is connected to the mainboard * * @param uart uart connected to mainboard */ - void set_uart_device(uart::UARTDevice *uart) { mainboard_uart_ = uart; }; + void set_uart_device(uart::UARTDevice *uart) + { + mainboard_uart_ = uart; + }; /** * @brief Sets the long press parameter on this button component. diff --git a/components/philips_action_button/button.py b/components/philips_action_button/button.py index 6018fe3..9fe7932 100644 --- a/components/philips_action_button/button.py +++ b/components/philips_action_button/button.py @@ -2,6 +2,7 @@ import esphome.config_validation as cv from esphome.components import button from esphome.const import CONF_ID + from ..philips_series_2200 import CONTROLLER_ID, PhilipsSeries2200 DEPENDENCIES = ["philips_series_2200"] diff --git a/components/philips_bean_settings/bean_settings.h b/components/philips_bean_settings/bean_settings.h index 5d75fb7..19e1e4a 100644 --- a/components/philips_bean_settings/bean_settings.h +++ b/components/philips_bean_settings/bean_settings.h @@ -44,7 +44,10 @@ namespace esphome * * @param source Source of the value */ - void set_source(Source source) { source_ = source; }; + void set_source(Source source) + { + source_ = source; + }; /** * @brief Sets the status sensor reference @@ -60,7 +63,10 @@ namespace esphome * * @param uart uart connected to mainboard */ - void set_uart_device(uart::UARTDevice *uart) { mainboard_uart_ = uart; }; + void set_uart_device(uart::UARTDevice *uart) + { + mainboard_uart_ = uart; + }; /** * @brief Published the state if it's different form the currently published state. diff --git a/components/philips_bean_settings/number.py b/components/philips_bean_settings/number.py index 14beee4..4c1566c 100644 --- a/components/philips_bean_settings/number.py +++ b/components/philips_bean_settings/number.py @@ -2,6 +2,7 @@ import esphome.config_validation as cv from esphome.components import number from esphome.const import CONF_MODE + from ..philips_series_2200 import CONTROLLER_ID, PhilipsSeries2200 from ..philips_status_sensor.text_sensor import STATUS_SENSOR_ID, StatusSensor diff --git a/components/philips_power_switch/power.cpp b/components/philips_power_switch/power.cpp index 346f6f3..6166c63 100644 --- a/components/philips_power_switch/power.cpp +++ b/components/philips_power_switch/power.cpp @@ -95,6 +95,6 @@ namespace esphome } } - } // namespace power_switch + } // namespace philips_power_switch } // namespace philips_series_2200 } // namespace esphome \ No newline at end of file diff --git a/components/philips_power_switch/power.h b/components/philips_power_switch/power.h index 0559121..cd1f26b 100644 --- a/components/philips_power_switch/power.h +++ b/components/philips_power_switch/power.h @@ -105,6 +105,6 @@ namespace esphome bool *initial_state_; }; - } // namespace power_switch + } // namespace philips_power_switch } // namespace philips_series_2200 } // namespace esphome \ No newline at end of file diff --git a/components/philips_power_switch/switch.py b/components/philips_power_switch/switch.py index d28f355..093e518 100644 --- a/components/philips_power_switch/switch.py +++ b/components/philips_power_switch/switch.py @@ -2,6 +2,7 @@ import esphome.config_validation as cv from esphome.components import switch from esphome.const import CONF_ID + from ..philips_series_2200 import CONTROLLER_ID, PhilipsSeries2200 DEPENDENCIES = ["philips_series_2200"] diff --git a/components/philips_series_2200/__init__.py b/components/philips_series_2200/__init__.py index 4ab4a69..ef5ce02 100644 --- a/components/philips_series_2200/__init__.py +++ b/components/philips_series_2200/__init__.py @@ -2,7 +2,6 @@ import esphome.config_validation as cv from esphome import pins from esphome.components.uart import UARTComponent - from esphome.const import CONF_ID AUTO_LOAD = [ diff --git a/components/philips_series_2200/philips_series_2200.h b/components/philips_series_2200/philips_series_2200.h index 540a71b..d222b4d 100644 --- a/components/philips_series_2200/philips_series_2200.h +++ b/components/philips_series_2200/philips_series_2200.h @@ -27,21 +27,30 @@ namespace esphome * * @param uart display uart reference */ - void register_display_uart(uart::UARTComponent *uart) { display_uart_ = uart::UARTDevice(uart); }; + void register_display_uart(uart::UARTComponent *uart) + { + display_uart_ = uart::UARTDevice(uart); + }; /** * @brief Set the reference to the uart port connected to the Mainboard * * @param uart Mainboard uart reference */ - void register_mainboard_uart(uart::UARTComponent *uart) { mainboard_uart_ = uart::UARTDevice(uart); }; + void register_mainboard_uart(uart::UARTComponent *uart) + { + mainboard_uart_ = uart::UARTDevice(uart); + }; /** * @brief Sets the pin used for power tripping the display unit * * @param pin GPIO pin */ - void set_power_pin(GPIOPin *pin) { power_pin_ = pin; }; + void set_power_pin(GPIOPin *pin) + { + power_pin_ = pin; + }; /** * @brief Sets the invert status of the power pin diff --git a/components/philips_size_settings/number.py b/components/philips_size_settings/number.py index bcf0c1e..e7a0af5 100644 --- a/components/philips_size_settings/number.py +++ b/components/philips_size_settings/number.py @@ -2,6 +2,7 @@ import esphome.config_validation as cv from esphome.components import number from esphome.const import CONF_MODE + from ..philips_series_2200 import CONTROLLER_ID, PhilipsSeries2200 from ..philips_status_sensor.text_sensor import STATUS_SENSOR_ID, StatusSensor diff --git a/components/philips_size_settings/size_settings.h b/components/philips_size_settings/size_settings.h index 9a2aee4..1e8aebe 100644 --- a/components/philips_size_settings/size_settings.h +++ b/components/philips_size_settings/size_settings.h @@ -45,7 +45,10 @@ namespace esphome * * @param source Source of the value */ - void set_source(Source source) { source_ = source; }; + void set_source(Source source) + { + source_ = source; + }; /** * @brief Sets the status sensor reference @@ -61,7 +64,10 @@ namespace esphome * * @param uart uart connected to mainboard */ - void set_uart_device(uart::UARTDevice *uart) { mainboard_uart_ = uart; }; + void set_uart_device(uart::UARTDevice *uart) + { + mainboard_uart_ = uart; + }; /** * @brief Published the state if it's different form the currently published state. diff --git a/components/philips_status_sensor/text_sensor.py b/components/philips_status_sensor/text_sensor.py index a5d65e6..85f081c 100644 --- a/components/philips_status_sensor/text_sensor.py +++ b/components/philips_status_sensor/text_sensor.py @@ -2,6 +2,7 @@ import esphome.config_validation as cv from esphome.components import text_sensor from esphome.const import CONF_ID + from ..philips_series_2200 import CONTROLLER_ID, PhilipsSeries2200 USE_CAPPUCCINO = "use_cappuccino" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b7d2ace --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,4 @@ +[tool.black] +target-version = ["py311"] +[tool.isort] +profile = "black" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c3c0b83 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +esphome \ No newline at end of file diff --git a/tests/base.yaml b/tests/base.yaml new file mode 100644 index 0000000..b2ca30f --- /dev/null +++ b/tests/base.yaml @@ -0,0 +1,29 @@ +esphome: + name: philip + +esp8266: + board: d1_mini + +external_components: + - source: + type: local + path: ../components + +logger: + baud_rate: 0 + +uart: + - tx_pin: GPIO1 + rx_pin: GPIO3 + baud_rate: 115200 + id: uart_mainboard + - tx_pin: GPIO15 + rx_pin: GPIO13 + baud_rate: 115200 + id: uart_display + +philips_series_2200: + display_uart: uart_display + mainboard_uart: uart_mainboard + power_pin: GPIO12 + id: philip diff --git a/tests/full.yaml b/tests/full.yaml new file mode 100644 index 0000000..fb67945 --- /dev/null +++ b/tests/full.yaml @@ -0,0 +1,78 @@ +esphome: + name: philip + +esp8266: + board: d1_mini + +external_components: + - source: + type: local + path: ../components + +logger: + baud_rate: 0 + +uart: + - tx_pin: GPIO1 + rx_pin: GPIO3 + baud_rate: 115200 + id: uart_mainboard + - tx_pin: GPIO15 + rx_pin: GPIO13 + baud_rate: 115200 + id: uart_display + +philips_series_2200: + display_uart: uart_display + mainboard_uart: uart_mainboard + power_pin: GPIO12 + invert_power_pin: true + power_trip_delay: 750ms + id: philip + +text_sensor: + - platform: philips_status_sensor + controller_id: philip + id: status + name: "Status" + - platform: philips_status_sensor + controller_id: philip + use_cappuccino: true + name: "Status cappuccino" + +switch: + - platform: philips_power_switch + controller_id: philip + name: "Cleaning Power" + icon: mdi:coffee-maker + - platform: philips_power_switch + controller_id: philip + name: "Power" + clean: false + icon: mdi:coffee-maker + +button: + - platform: philips_action_button + controller_id: philip + action: MAKE_COFFEE + name: "Make Coffee" + icon: mdi:coffee + + - platform: philips_action_button + controller_id: philip + action: SELECT_HOT_WATER + name: "Select Hot Water" + long_press: true + icon: mdi:tea + +number: + - platform: philips_bean_settings + name: "Coffee beans" + controller_id: philip + status_sensor_id: status + source: COFFEE + - platform: philips_size_settings + name: "Coffee size" + controller_id: philip + status_sensor_id: status + source: COFFEE