Skip to content

Commit

Permalink
Various updates (#175)
Browse files Browse the repository at this point in the history
* update devcontainer

* update python and HA

* update pre-commit

* run pre-commit
  • Loading branch information
edenhaus authored Jul 9, 2023
1 parent b1bc794 commit 22aaea0
Show file tree
Hide file tree
Showing 31 changed files with 282 additions and 223 deletions.
74 changes: 74 additions & 0 deletions .devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"customizations": {
"vscode": {
"extensions": [
"esbenp.prettier-vscode",
"github.vscode-pull-request-github",
"ms-python.python",
"ms-python.vscode-pylance",
"ms-vscode.makefile-tools",
"ryanluker.vscode-coverage-gutters",
"visualstudioexptteam.vscodeintellicode"
],
"settings": {
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.tabSize": 4,
"files.eol": "\n",
"files.trimTrailingWhitespace": true,
"python.analysis.autoImportCompletions": true,
"python.analysis.autoSearchPaths": false,
"python.analysis.extraPaths": ["/home/vscode/.local/lib/python*/"],
"python.analysis.typeCheckingMode": "basic",
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.provider": "black",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.languageServer": "Pylance",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.enabled": true,
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.linting.mypyEnabled": true,
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.linting.pylintArgs": ["--disable", "import-error"],
"python.linting.pylintEnabled": true,
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
"python.pythonPath": "/usr/local/python/bin/python",
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
"terminal.integrated.defaultProfile.linux": "zsh",
"terminal.integrated.profiles.linux": {
"zsh": {
"path": "/usr/bin/zsh"
}
}
}
}
},
"features": {
"rust": "latest"
},
"forwardPorts": [8123],
"image": "mcr.microsoft.com/devcontainers/python:3-bullseye",
"name": "Bodymiscale",
"portsAttributes": {
"0-8122": {
"label": "Auto-Forwarded - Other",
"onAutoForward": "ignore"
},
"8123": {
"label": "Home Assistant"
},
"8124-999999": {
"label": "Auto-Forwarded - Other",
"onAutoForward": "ignore"
}
},
"postCreateCommand": "scripts/setup",
"remoteUser": "vscode",
"runArgs": ["-e", "GIT_EDITOR=code --wait"]
}
60 changes: 0 additions & 60 deletions .devcontainer/README.md

This file was deleted.

33 changes: 0 additions & 33 deletions .devcontainer/devcontainer.json

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
- cron: "0 0 * * *"

env:
DEFAULT_PYTHON: "3.9"
DEFAULT_PYTHON: "3.11"

jobs:
validate-hacs:
Expand Down
18 changes: 11 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ ci:
- mypy
- pylint

default_language_version:
python: python3.11

repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
rev: v3.9.0
hooks:
- id: pyupgrade
args: [--py39-plus]
args: [--py310-plus]
- repo: https://github.com/psf/black
rev: 22.12.0
rev: 23.3.0
hooks:
- id: black
args:
Expand All @@ -28,7 +31,7 @@ repos:
<<: &python-files
files: ^(custom_components/.+)?[^/]+\.py$
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
rev: 1.7.5
hooks:
- id: bandit
args:
Expand All @@ -53,16 +56,17 @@ repos:
- --fix=lf
stages: [manual]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.4
rev: v2.7.1
hooks:
- id: prettier
additional_dependencies:
- [email protected]
- [email protected].2
- [email protected].3
exclude_types:
- python
exclude: manifest\.json$
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.29.0
rev: v1.32.0
hooks:
- id: yamllint
- repo: local
Expand Down
27 changes: 14 additions & 13 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"host": "localhost",
"justMyCode": false,
// Example of attaching to local debug server
"name": "Python: Attach Local",
"type": "python",
"request": "attach",
"port": 5678,
"host": "localhost",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "."
}
]
],
"port": 5678,
"request": "attach",
"type": "python"
},
{
"host": "homeassistant.local",
// Example of attaching to my production server
"name": "Python: Attach Remote",
"type": "python",
"request": "attach",
"port": 5678,
"host": "homeassistant.local",
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/usr/src/homeassistant"
}
]
],
"port": 5678,
"request": "attach",
"type": "python"
}
]
],
"version": "0.2.0"
}
17 changes: 9 additions & 8 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
// See https://code.visualstudio.com/docs/editor/tasks
{
"tasks": [
{
"command": "container start",
"label": "Run Home Assistant on port 9123",
"command": "scripts/develop",
"label": "Run Home Assistant",
"problemMatcher": [],
"type": "shell"
},
{
"command": "container check",
"label": "Run Home Assistant configuration against /config",
"command": "scripts/setup",
"label": "Upgrade environment",
"problemMatcher": [],
"type": "shell"
},
{
"command": "container install",
"label": "Upgrade Home Assistant to latest dev",
"command": "scripts/test",
"label": "Run tests",
"problemMatcher": [],
"type": "shell"
},
{
"command": "container set-version",
"label": "Install a specific version of Home Assistant",
"command": "scripts/lint",
"label": "Run lint checks",
"problemMatcher": [],
"type": "shell"
}
Expand Down
1 change: 0 additions & 1 deletion bandit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ tests:
- B318
- B319
- B320
- B325
- B601
- B602
- B604
Expand Down
4 changes: 2 additions & 2 deletions custom_components/bodymiscale/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
from collections.abc import MutableMapping
from functools import partial
from typing import Any, Optional
from typing import Any

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
Expand Down Expand Up @@ -172,7 +172,7 @@ def __init__(self, handler: BodyScaleMetricsHandler):
key="bodymiscale", name=handler.config[CONF_NAME], icon="mdi:human"
),
)
self._timer_handle: Optional[asyncio.TimerHandle] = None
self._timer_handle: asyncio.TimerHandle | None = None
self._available_metrics: MutableMapping[str, StateType] = TTLCache(
maxsize=len(Metric), ttl=60
)
Expand Down
5 changes: 2 additions & 3 deletions custom_components/bodymiscale/entity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Bodymiscale entity module."""
from typing import Optional

from homeassistant.const import CONF_NAME
from homeassistant.helpers.device_registry import DeviceEntryType
Expand All @@ -17,7 +16,7 @@ class BodyScaleBaseEntity(Entity): # type: ignore[misc]
def __init__(
self,
handler: BodyScaleMetricsHandler,
entity_description: Optional[EntityDescription] = None,
entity_description: EntityDescription | None = None,
):
"""Initialize the entity."""
super().__init__()
Expand All @@ -44,7 +43,7 @@ def __init__(
self._attr_name = f"{name} {self.entity_description.key.replace('_', ' ')}"

@property
def device_info(self) -> Optional[DeviceInfo]:
def device_info(self) -> DeviceInfo | None:
"""Return device specific attributes."""
return DeviceInfo(
entry_type=DeviceEntryType.SERVICE,
Expand Down
6 changes: 3 additions & 3 deletions custom_components/bodymiscale/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@


import logging
from collections.abc import Mapping, MutableMapping
from collections.abc import Callable, Mapping, MutableMapping
from dataclasses import dataclass, field
from typing import Any, Callable, Optional
from typing import Any

from cachetools import TTLCache
from homeassistant.const import (
Expand Down Expand Up @@ -58,7 +58,7 @@ class MetricInfo:

depends_on: list[Metric]
calculate: Callable[[Mapping[str, Any], Mapping[Metric, StateType]], StateType]
decimals: Optional[int] = None # Round decimals before passing to the subscribers
decimals: int | None = None # Round decimals before passing to the subscribers
depended_by: list[Metric] = field(default_factory=list, init=False)


Expand Down
Loading

0 comments on commit 22aaea0

Please sign in to comment.