Skip to content

Commit

Permalink
fix: update ha deprecations and fix infinite loop (#42)
Browse files Browse the repository at this point in the history
* chore: add vscode configs

* chore: add mypy, pylint, ruff and other meta tools

* chore: add scripts for development

* fix: update code to latest ha library and fix deprecations

resolves bug causing infinite loop
  • Loading branch information
c0un7-z3r0 authored Jun 18, 2024
1 parent ab2e016 commit 38fc1e4
Show file tree
Hide file tree
Showing 56 changed files with 2,285 additions and 982 deletions.
52 changes: 52 additions & 0 deletions .devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "Phoniebox",
"image": "mcr.microsoft.com/devcontainers/python:3.12",
"postCreateCommand": "scripts/setup",
"forwardPorts": [
8123
],
"portsAttributes": {
"8123": {
"label": "Home Assistant"
}
},
"customizations": {
"extensions": [
"charliermarsh.ruff",
"ms-python.python",
"github.vscode-pull-request-github",
"ryanluker.vscode-coverage-gutters",
"ms-python.vscode-pylance"
],
"vscode": {
"settings": {
"python.pythonPath": "/usr/local/bin/python3.12",
"python.defaultInterpreterPath": "/usr/local/bin/python3.12",
"python.formatting.provider": "ruff",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.rulers": [
100
],
"editor.codeActionsOnSave": {
"source.fixAll": "always",
"source.organizeImports": "always"
},
"files.trimTrailingWhitespace": true
},
"extensions": [
"github.vscode-pull-request-github",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-vscode.makefile-tools",
"ryanluker.vscode-coverage-gutters",
"charliermarsh.ruff",
"ms-python.debugpy"
]
}
},
"remoteUser": "vscode",
"features": {}
}
75 changes: 36 additions & 39 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,84 +1,81 @@
name-template: 'v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'
change-template: '- #$NUMBER $TITLE @$AUTHOR'
name-template: "v$RESOLVED_VERSION"
tag-template: "v$RESOLVED_VERSION"
change-template: "- #$NUMBER $TITLE @$AUTHOR"
sort-direction: ascending
categories:
- title: ':boom: Breaking changes'
label: 'pr: breaking'
- title: ":boom: Breaking changes"
label: "pr: breaking"

- title: ':sparkles: Features'
label: 'pr: feat'
- title: ":sparkles: Features"
label: "pr: feat"

- title: ':recycle: Refactor'
label: 'pr: refactor'
- title: ":recycle: Refactor"
label: "pr: refactor"

- title: ':bug: Bug Fixes'
label: 'pr: fix'

- title: ':zap: Performance Improvements'
labels: 'pr: perf'
- title: ":bug: Bug Fixes"
label: "pr: fix"

- title: ":zap: Performance Improvements"
labels: "pr: perf"

autolabeler:
- label: 'pr: breaking'
- label: "pr: breaking"
body:
- '/BREAKING CHANGE/'
- label: 'pr: test'
- "/BREAKING CHANGE/"
- label: "pr: test"
branch:
- 'test\/.+/'
- label: 'pr: style'
- label: "pr: style"
branch:
- 'style\/.+/'
- label: 'pr: refactor'
- label: "pr: refactor"
branch:
- '/refactor\/.+/'
- label: 'pr: perf'
- label: "pr: perf"
branch:
- '/perf\/.+/'
- label: 'pr: fix'
- label: "pr: fix"
branch:
- '/fix\/.+/'
- label: 'pr: ci'
- label: "pr: ci"
branch:
- '/ci\/.+/'
- label: 'pr: build'
- label: "pr: build"
branch:
- '/build\/.+/'
- label: 'pr: docs'
- label: "pr: docs"
files:
- '*.md'
- "*.md"
branch:
- '/docs{0,1}\/.+/'
- label: 'pr: feat'
- label: "pr: feat"
branch:
- '/feature\/.+/'



include-labels:
- 'pr: breaking'
- 'pr: fix'
- 'pr: feat'
- 'pr: perf'
- 'pr: refactor'
- "pr: breaking"
- "pr: fix"
- "pr: feat"
- "pr: perf"
- "pr: refactor"

version-resolver:
major:
labels:
- 'pr: breaking'
- "pr: breaking"
minor:
labels:
- 'pr: feat'
- 'pr: perf'
- 'pr: refactor'
- "pr: feat"
- "pr: perf"
- "pr: refactor"
patch:
labels:
- 'pr: fix'
- "pr: fix"
default: minor

template: |
[![Downloads for this release](https://img.shields.io/github/downloads/c0un7-z3r0/hass-phoniebox/v$RESOLVED_VERSION/total.svg)](https://github.com/c0un7-z3r0/hass-phoniebox/releases/v$RESOLVED_VERSION)
$CHANGES
## Links
- [How to submit bugs/feature requests](https://github.com/c0un7-z3r0/hass-phoniebox/issues)
2 changes: 1 addition & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
# will suggest using that commit message instead of the PR title for the
# merge commit, and it's easy to commit this by mistake. Enable this option
# to also validate the commit message for one commit PRs.
validateSingleCommit: true
validateSingleCommit: true
4 changes: 2 additions & 2 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
pull_request:
schedule:
- cron: '0 0 * * *'
- cron: "0 0 * * *"
jobs:
validate:
runs-on: "ubuntu-latest"
Expand Down Expand Up @@ -37,7 +37,7 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'python' ]
language: [ "python" ]

steps:
- name: Check out code from GitHub
Expand Down
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,32 @@ venv.bak/
.DS_Store

.idea
/config/.storage/assist_pipeline.pipelines
/config/.storage/auth
/config/.storage/auth_provider.homeassistant
/config/.storage/bluetooth.passive_update_processor
/config/.storage/core.analytics
/config/.storage/core.area_registry
/config/.storage/core.config
/config/.storage/core.config_entries
/config/.storage/core.device_registry
/config/.storage/core.entity_registry
/config/.storage/core.logger
/config/.storage/core.restore_state
/config/.storage/core.uuid
/config/.storage/homeassistant.exposed_entities
/config/.storage/http
/config/.storage/http.auth
/config/.storage/lovelace
/config/.storage/lovelace.map
/config/.storage/lovelace_dashboards
/config/.storage/onboarding
/config/.storage/person
/config/.storage/repairs.issue_registry
/config/.storage/trace.saved_traces
/config/blueprints/automation/homeassistant/motion_light.yaml
/config/blueprints/automation/homeassistant/notify_leaving_zone.yaml
/config/blueprints/script/homeassistant/confirmable_notification.yaml
/config/.HA_VERSION
/config/home-assistant.log.1
/config/home-assistant_v2.db
51 changes: 51 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.8
hooks:
- id: ruff
args:
- --fix
- id: ruff-format
files: ^((custom_components|pylint|script|tests)/.+)?[^/]+\.(py|pyi)$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-executables-have-shebangs
stages: [ manual ]
- id: check-json
exclude: (.vscode|.devcontainer)
- id: no-commit-to-branch
args:
- --branch=dev
- --branch=master
- --branch=rc
- repo: https://github.com/cdce8p/python-typing-update
rev: v0.6.0
hooks:
# Run `python-typing-update` hook manually from time to time
# to update python typing syntax.
# Will require manual work, before submitting changes!
# pre-commit run --hook-stage manual python-typing-update --all-files
- id: python-typing-update
stages: [ manual ]
args:
- --py311-plus
- --force
- --keep-updates
files: ^(custom_components|tests|script)/.+\.py$
- repo: local
hooks:
- id: mypy
name: mypy
entry: scripts/run-in-env.sh mypy
language: script
types_or: [ python, pyi ]
require_serial: true
files: ^(custom_components|pylint)/.+\.(py|pyi)$
- id: pylint
name: pylint
entry: scripts/run-in-env.sh pylint -j 0
language: script
types_or: [ python, pyi ]
files: ^custom_components/.+\.(py|pyi)$
37 changes: 37 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# The contents of this file is based on https://github.com/home-assistant/core/blob/dev/pyproject.toml

target-version = "py312"

[lint]
select = [
"ALL",
]

ignore = [
"ANN101", # Missing type annotation for `self` in method
"ANN401", # Dynamically typed expressions (typing.Any) are disallowed
"D203", # no-blank-line-before-class (incompatible with formatter)
"D212", # multi-line-summary-first-line (incompatible with formatter)
"COM812", # incompatible with formatter
"ISC001", # incompatible with formatter
]

[lint.flake8-pytest-style]
fixture-parentheses = false

[lint.pyupgrade]
keep-runtime-typing = true

[lint.mccabe]
max-complexity = 25

[per-file-ignores]
"tests/**/*.py" = [
# at least this three should be fine in tests:
"S101", # asserts allowed in tests...
"ARG", # Unused function args -> fixtures nevertheless are functionally relevant...
"FBT", # Don't care about booleans as positional arguments in tests, e.g. via @pytest.mark.parametrize()
# The below are debateable
"PLR2004", # Magic value used in comparison, ...
"PT004",
]
1 change: 1 addition & 0 deletions .strict-typing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
custom_components/*
67 changes: 67 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Home Assistant",
"type": "debugpy",
"request": "launch",
"module": "homeassistant",
"justMyCode": false,
"args": ["--debug", "-c", "config"]
},
{
"name": "Home Assistant (skip pip)",
"type": "debugpy",
"request": "launch",
"module": "homeassistant",
"justMyCode": false,
"args": ["--debug", "-c", "config", "--skip-pip"]
},
{
"name": "Home Assistant: Changed tests",
"type": "debugpy",
"request": "launch",
"module": "pytest",
"justMyCode": false,
"args": ["--timeout=10", "--picked"]
},
{
"name": "Home Assistant: all tests",
"type": "debugpy",
"request": "launch",
"module": "pytest",
"justMyCode": false,
"args": ["--timeout=10"]
},
{
"name": "Home Assistant: Attach Local",
"type": "debugpy",
"request": "attach",
"connect": {
"port": 5678,
"host": "localhost"
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "."
}
]
},
{
"name": "Home Assistant: Attach Remote",
"type": "debugpy",
"request": "attach",
"connect": {
"port": 5678,
"host": "homeassistant.local"
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/usr/src/homeassistant"
}
]
}
]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"python.testing.unittestArgs": ["-v", "-s", "./test", "-p", "test_*.py"],
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false
}
Loading

0 comments on commit 38fc1e4

Please sign in to comment.