Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
MapoDan committed Jan 9, 2024
2 parents d900bfd + d81133e commit 3e97956
Show file tree
Hide file tree
Showing 6 changed files with 397 additions and 2 deletions.
134 changes: 134 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: CI

# yamllint disable-line rule:truthy
on:
#push:
#pull_request: ~
workflow_dispatch:

env:
CACHE_VERSION: 1
PYTHON_VERSION_DEFAULT: '3.10.8'
PRE_COMMIT_HOME: ~/.cache/pre-commit

jobs:
# Separate job to pre-populate the base dependency cache
# This prevent upcoming jobs to do the same individually
prepare-base:
name: Prepare base dependencies
runs-on: ubuntu-latest
strategy:
matrix:
#python-version: ['3.8.14', '3.9.15', '3.10.8', '3.11.0']
python-version: ['3.10.8', '3.11.0']
steps:
- name: Check out code from GitHub
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
id: python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Restore base Python virtual environment
id: cache-venv
uses: actions/cache@v3
with:
path: venv
key: >-
${{ env.CACHE_VERSION}}-${{ runner.os }}-base-venv-${{
steps.python.outputs.python-version }}-${{
hashFiles('setup.py', 'requirements_test.txt') }}
restore-keys: |
${{ env.CACHE_VERSION}}-${{ runner.os }}-base-venv-${{ steps.python.outputs.python-version }}-
- name: Create Python virtual environment
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
python -m venv venv
. venv/bin/activate
pip install -U pip setuptools pre-commit
pip install -r requirements_test.txt
pip install -e .
pre-commit:
name: Prepare pre-commit environment
runs-on: ubuntu-latest
needs: prepare-base
steps:
- name: Check out code from GitHub
uses: actions/checkout@v3
- name: Set up Python ${{ env.PYTHON_VERSION_DEFAULT }}
uses: actions/setup-python@v4
id: python
with:
python-version: ${{ env.PYTHON_VERSION_DEFAULT }}
- name: Restore base Python virtual environment
id: cache-venv
uses: actions/cache@v3
with:
path: venv
key: >-
${{ env.CACHE_VERSION}}-${{ runner.os }}-base-venv-${{
steps.python.outputs.python-version }}-${{
hashFiles('setup.py', 'requirements_test.txt') }}
- name: Fail job if Python cache restore failed
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
echo "Failed to restore Python virtual environment from cache"
exit 1
- name: Restore pre-commit environment from cache
id: cache-precommit
uses: actions/cache@v3
with:
path: ${{ env.PRE_COMMIT_HOME }}
key: |
${{ env.CACHE_VERSION}}-${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
restore-keys: |
${{ env.CACHE_VERSION}}-${{ runner.os }}-pre-commit-
- name: Install pre-commit dependencies
if: steps.cache-precommit.outputs.cache-hit != 'true'
run: |
. venv/bin/activate
pre-commit install-hooks
pre-commit-run:
name: Run all of pre-commit
runs-on: ubuntu-latest
needs: pre-commit
steps:
- name: Check out code from GitHub
uses: actions/checkout@v3
- name: Set up Python ${{ env.PYTHON_VERSION_DEFAULT }}
uses: actions/setup-python@v4
id: python
with:
python-version: ${{ env.PYTHON_VERSION_DEFAULT }}
- name: Restore base Python virtual environment
id: cache-venv
uses: actions/cache@v3
with:
path: venv
key: >-
${{ env.CACHE_VERSION}}-${{ runner.os }}-base-venv-${{
steps.python.outputs.python-version }}-${{
hashFiles('setup.py', 'requirements_test.txt') }}
- name: Fail job if Python cache restore failed
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
echo "Failed to restore Python virtual environment from cache"
exit 1
- name: Restore pre-commit environment from cache
id: cache-precommit
uses: actions/cache@v3
with:
path: ${{ env.PRE_COMMIT_HOME }}
key: |
${{ env.CACHE_VERSION}}-${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
- name: Fail job if cache restore failed
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
echo "Failed to restore Python virtual environment from cache"
exit 1
- name: Run pre-commit
run: |
. venv/bin/activate
pre-commit run -a
24 changes: 24 additions & 0 deletions .github/workflows/validate-hacs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Validate with hassfest

on:
push:
pull_request:
schedule:
- cron: 0 0 * * *

jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: home-assistant/actions/hassfest@master
hacs:
name: HACS Action
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: HACS Action
uses: hacs/action@main
with:
category: integration
135 changes: 135 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
---
files: ^(.*\.(py|json|md|sh|yaml|cfg|txt))$
exclude: ^(\.[^/]*cache/.*|.*/_user.py)$
repos:
- repo: https://github.com/verhovsky/pyupgrade-docs
rev: v0.3.0
hooks:
- id: pyupgrade-docs
- repo: https://github.com/executablebooks/mdformat
# Do this before other tools "fixing" the line endings
rev: 0.7.16
hooks:
- id: mdformat
name: Format Markdown
entry: mdformat # Executable to run, with fixed options
language: python
types: [markdown]
args: [--wrap, '75', --number]
additional_dependencies:
- mdformat-toc
- mdformat-beautysh
# -mdformat-shfmt
# -mdformat-tables
- mdformat-config
- mdformat-black
- mdformat-web
- mdformat-gfm
- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
hooks:
- id: blacken-docs
additional_dependencies: [black==22.6.0]
stages: [manual] # Manual because already done by mdformat-black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: no-commit-to-branch
args: [--branch, main]
- id: check-yaml
args: [--unsafe]
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-json
- id: mixed-line-ending
- id: check-builtin-literals
- id: check-ast
- id: check-merge-conflict
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- id: check-docstring-first
- id: fix-byte-order-marker
- id: check-case-conflict
# - id: check-toml
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.29.0
hooks:
- id: yamllint
args:
- --no-warnings
- -d
- '{extends: relaxed, rules: {line-length: {max: 90}}}'
- repo: https://github.com/lovesegfault/beautysh.git
rev: v6.2.1
hooks:
- id: beautysh
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args:
- --py310-plus
- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
args:
- --safe
- --quiet
- -l 79
- repo: https://github.com/Lucas-C/pre-commit-hooks-bandit
rev: v1.0.6
hooks:
- id: python-bandit-vulnerability-check
- repo: https://github.com/fsouza/autoflake8
rev: v0.4.0
hooks:
- id: autoflake8
args:
- -i
- -r
- --expand-star-imports
- custom_components
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
# - pyproject-flake8>=0.0.1a5
- flake8-bugbear>=22.7.1
- flake8-comprehensions>=3.10.1
- flake8-2020>=1.7.0
- mccabe>=0.7.0
- pycodestyle>=2.9.1
- pyflakes>=2.5.0
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
hooks:
- id: codespell
args: [--toml, pyproject.toml]
additional_dependencies:
- tomli
- repo: https://github.com/pre-commit/mirrors-pylint
rev: v3.0.0a5
hooks:
- id: pylint
additional_dependencies:
#- voluptuous==0.13.1
- homeassistant-stubs==2023.3.1
#- sqlalchemy
#- pyyaml
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
hooks:
- id: mypy
additional_dependencies:
#- voluptuous==0.13.1
- pydantic>=1.10.5
- homeassistant-stubs==2023.3.1
#- sqlalchemy
#- pyyaml
4 changes: 2 additions & 2 deletions custom_components/programmable_thermostat/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Add ProgrammableThermostat entities from configuration.yaml."""
_LOGGER.info("Setup entity coming from configuration.yaml named: %s", config.get(CONF_NAME))
await async_setup_reload_service(hass, DOMAIN, PLATFORM)
await async_setup_reload_service(hass, DOMAIN, [PLATFORM])
async_add_entities([ProgrammableThermostat(hass, config)])

async def async_setup_entry(hass, config_entry, async_add_devices):
Expand All @@ -80,7 +80,7 @@ async def async_setup_entry(hass, config_entry, async_add_devices):
else:
result = config_entry.data
_LOGGER.info("setup entity-config_entry_data=%s",result)
await async_setup_reload_service(hass, DOMAIN, PLATFORM)
await async_setup_reload_service(hass, DOMAIN, [PLATFORM])
async_add_devices([ProgrammableThermostat(hass, result)])


Expand Down
Loading

0 comments on commit 3e97956

Please sign in to comment.