Skip to content

Commit

Permalink
Add Continuous Integration (#4)
Browse files Browse the repository at this point in the history
* Switch to Black formatting

* Explicitly specify clang formatting

* Add CI
  • Loading branch information
TillFleisch authored Jan 26, 2024
1 parent 14ba639 commit 22a86fe
Show file tree
Hide file tree
Showing 16 changed files with 349 additions and 84 deletions.
9 changes: 9 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
UseTab: Never
IndentWidth: 4
NamespaceIndentation: All
AccessModifierOffset: -4
BreakBeforeBraces: Allman
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
SortIncludes: false
ColumnLimit: 0
122 changes: 122 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: CI

# yamllint disable-line rule:truthy
on:
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
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
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore: |
venv/
26 changes: 18 additions & 8 deletions components/desk_height_sensor/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,28 @@
import esphome.config_validation as cv
from esphome.components import sensor
from esphome.const import CONF_ID, ICON_ARROW_EXPAND_VERTICAL
from ..generic_desk import GenericDesk, CONF_DESK_ID

DEPENDENCIES = ['generic_desk']
from ..generic_desk import CONF_DESK_ID, GenericDesk

generic_desk_sensor_ns = cg.esphome_ns.namespace('generic_desk')
DEPENDENCIES = ["generic_desk"]

generic_desk_sensor_ns = cg.esphome_ns.namespace("generic_desk")
GenericDeskSensor = generic_desk_sensor_ns.class_(
'GenericDesk', sensor.Sensor, cg.PollingComponent)
"GenericDesk", sensor.Sensor, cg.PollingComponent
)

CONFIG_SCHEMA = sensor.sensor_schema(unit_of_measurement="cm", icon=ICON_ARROW_EXPAND_VERTICAL, accuracy_decimals=1).extend({
cv.GenerateID(): cv.declare_id(GenericDeskSensor),
cv.GenerateID(CONF_DESK_ID): cv.use_id(GenericDesk)
}).extend(cv.COMPONENT_SCHEMA)
CONFIG_SCHEMA = (
sensor.sensor_schema(
unit_of_measurement="cm", icon=ICON_ARROW_EXPAND_VERTICAL, accuracy_decimals=1
)
.extend(
{
cv.GenerateID(): cv.declare_id(GenericDeskSensor),
cv.GenerateID(CONF_DESK_ID): cv.use_id(GenericDesk),
}
)
.extend(cv.COMPONENT_SCHEMA)
)


def to_code(config):
Expand Down
11 changes: 6 additions & 5 deletions components/desk_is_moving_sensor/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import binary_sensor
from ..generic_desk import GenericDesk, CONF_DESK_ID

DEPENDENCIES = ['generic_desk']
from ..generic_desk import CONF_DESK_ID, GenericDesk

DEPENDENCIES = ["generic_desk"]

CONFIG_SCHEMA = binary_sensor.binary_sensor_schema().extend({
cv.GenerateID(CONF_DESK_ID): cv.use_id(GenericDesk)
})

CONFIG_SCHEMA = binary_sensor.binary_sensor_schema().extend(
{cv.GenerateID(CONF_DESK_ID): cv.use_id(GenericDesk)}
)


async def to_code(config):
Expand Down
14 changes: 7 additions & 7 deletions components/desk_memory_button/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
import esphome.config_validation as cv
from esphome.components import button
from esphome.const import CONF_ID
from ..generic_desk import GenericDesk, CONF_DESK_ID

DEPENDENCIES = ['generic_desk']
from ..generic_desk import CONF_DESK_ID, GenericDesk

CONF_MEMORY_BUTTON_ID = 'memory_id'
DEPENDENCIES = ["generic_desk"]

memory_button_ns = cg.esphome_ns.namespace('memory_button')
MemoryButton = memory_button_ns.class_(
"MemoryButton", button.Button, cg.Component)
CONF_MEMORY_BUTTON_ID = "memory_id"

memory_button_ns = cg.esphome_ns.namespace("memory_button")
MemoryButton = memory_button_ns.class_("MemoryButton", button.Button, cg.Component)

CONFIG_SCHEMA = button.BUTTON_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(MemoryButton),
cv.GenerateID(CONF_DESK_ID): cv.use_id(GenericDesk),
cv.Required(CONF_MEMORY_BUTTON_ID): cv.int_
cv.Required(CONF_MEMORY_BUTTON_ID): cv.int_,
}
).extend(cv.COMPONENT_SCHEMA)

Expand Down
62 changes: 31 additions & 31 deletions components/desk_memory_button/desk_memory_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,42 @@

namespace esphome
{
namespace memory_button
{
namespace memory_button
{

static const char *const TAG = "Desk.memoryButton";
static const char *const TAG = "Desk.memoryButton";

void MemoryButton::dump_config()
{
LOG_BUTTON("", "Memory Button", this);
}
void MemoryButton::dump_config()
{
LOG_BUTTON("", "Memory Button", this);
}

void MemoryButton::press_action()
{
for (unsigned int i = 0; i <= MESSAGE_REPETITIONS; i++)
{
switch (this->memory_id)
void MemoryButton::press_action()
{
case 0:
uart_device->write_array({0xea, 0xf5, 0x41, 0x00, 0x00, 0x41, 0xd4, 0x28});
break;
case 1:
uart_device->write_array({0xea, 0xf5, 0x42, 0x00, 0x00, 0x42, 0x94, 0x6d});
break;
case 2:
uart_device->write_array({0xea, 0xf5, 0x43, 0x00, 0x00, 0x43, 0x54, 0x51});
break;
case 3:
uart_device->write_array({0xea, 0xf5, 0x44, 0x00, 0x00, 0x44, 0x14, 0xe7});
break;
for (unsigned int i = 0; i <= MESSAGE_REPETITIONS; i++)
{
switch (this->memory_id)
{
case 0:
uart_device->write_array({0xea, 0xf5, 0x41, 0x00, 0x00, 0x41, 0xd4, 0x28});
break;
case 1:
uart_device->write_array({0xea, 0xf5, 0x42, 0x00, 0x00, 0x42, 0x94, 0x6d});
break;
case 2:
uart_device->write_array({0xea, 0xf5, 0x43, 0x00, 0x00, 0x43, 0x54, 0x51});
break;
case 3:
uart_device->write_array({0xea, 0xf5, 0x44, 0x00, 0x00, 0x44, 0x14, 0xe7});
break;

default:
break;
default:
break;
}
uart_device->flush();
delay(5);
}
}
uart_device->flush();
delay(5);
}
}

} // namespace output
} // namespace memory_button
} // namespace esphome
2 changes: 1 addition & 1 deletion components/desk_memory_button/desk_memory_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ namespace esphome
uart::UARTDevice *uart_device;
};

} // namespace output
} // namespace memory_button
} // namespace esphome
19 changes: 11 additions & 8 deletions components/desk_switch/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@
import esphome.config_validation as cv
from esphome.components import switch
from esphome.const import CONF_ID
from ..generic_desk import GenericDesk, CONF_DESK_ID

from ..generic_desk import CONF_DESK_ID, GenericDesk

CONF_DIRECTION = "direction"

desk_switch_ns = cg.esphome_ns.namespace('desk_switch')
DeskSwitch = desk_switch_ns.class_('DeskSwitch', switch.Switch, cg.Component)
desk_switch_ns = cg.esphome_ns.namespace("desk_switch")
DeskSwitch = desk_switch_ns.class_("DeskSwitch", switch.Switch, cg.Component)

CONFIG_SCHEMA = switch.SWITCH_SCHEMA.extend({
cv.GenerateID(): cv.declare_id(DeskSwitch),
cv.GenerateID(CONF_DESK_ID): cv.use_id(GenericDesk),
cv.Required(CONF_DIRECTION): cv.boolean
}).extend(cv.COMPONENT_SCHEMA)
CONFIG_SCHEMA = switch.SWITCH_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(DeskSwitch),
cv.GenerateID(CONF_DESK_ID): cv.use_id(GenericDesk),
cv.Required(CONF_DIRECTION): cv.boolean,
}
).extend(cv.COMPONENT_SCHEMA)


async def to_code(config):
Expand Down
Loading

0 comments on commit 22a86fe

Please sign in to comment.