Skip to content

Commit

Permalink
Make better use of pre-commit (#2288)
Browse files Browse the repository at this point in the history
  • Loading branch information
LDprg committed Jun 23, 2024
1 parent 28e4c63 commit 634f11b
Show file tree
Hide file tree
Showing 608 changed files with 11,570 additions and 11,788 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ body:
label: "Additional context"
description: "Add any other context or screenshots about the feature request here."
validations:
required: true
required: true
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE/power_profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
## Additional info
<!--
Add any additional info we must know about the measurements here.
-->
-->
4 changes: 2 additions & 2 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
When create a PR for new measurements to the library, please go the the `Preview` tab and select the `power-profile` template:
If you are issuing a new PR for other purpose you can remove all this text.
If you are issuing a new PR for other purpose you can remove all this text.

* [Power profile](?expand=1&template=power_profile.md)
* [Power profile](?expand=1&template=power_profile.md)
2 changes: 1 addition & 1 deletion .github/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ autolabeler:
- label: 'enhancement'
branch:
- '/feature\/.+/'
- '/feat\/.+/'
- '/feat\/.+/'
27 changes: 15 additions & 12 deletions .github/scripts/lut_validator/rules/brightness.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"properties": {
"bri": {
"type": "integer",
"minimum": 0,
"maximum": 255
},
"watt": {
"type": "number",
"minimum": 0.01
}
"properties": {
"bri": {
"type": "integer",
"minimum": 0,
"maximum": 255
},
"required": ["bri", "watt"]
}
"watt": {
"type": "number",
"minimum": 0.01
}
},
"required": [
"bri",
"watt"
]
}
38 changes: 21 additions & 17 deletions .github/scripts/lut_validator/rules/color_temp.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
{
"properties": {
"bri": {
"type": "integer",
"minimum": 0,
"maximum": 255
},
"mired": {
"type": "integer",
"minimum": 0,
"maximum": 670
},
"watt": {
"type": "number",
"minimum": 0.01
}
"properties": {
"bri": {
"type": "integer",
"minimum": 0,
"maximum": 255
},
"required": ["bri", "mired", "watt"]
}
"mired": {
"type": "integer",
"minimum": 0,
"maximum": 670
},
"watt": {
"type": "number",
"minimum": 0.01
}
},
"required": [
"bri",
"mired",
"watt"
]
}
49 changes: 27 additions & 22 deletions .github/scripts/lut_validator/rules/hs.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
{
"properties": {
"bri": {
"type": "integer",
"minimum": 0,
"maximum": 255
},
"hue": {
"type": "integer",
"minimum": 0,
"maximum": 65535
},
"sat": {
"type": "integer",
"minimum": 0,
"maximum": 255
},
"watt": {
"type": "number",
"minimum": 0.01
}
"properties": {
"bri": {
"type": "integer",
"minimum": 0,
"maximum": 255
},
"required": ["bri", "hue", "sat", "watt"]
}
"hue": {
"type": "integer",
"minimum": 0,
"maximum": 65535
},
"sat": {
"type": "integer",
"minimum": 0,
"maximum": 255
},
"watt": {
"type": "number",
"minimum": 0.01
}
},
"required": [
"bri",
"hue",
"sat",
"watt"
]
}
2 changes: 1 addition & 1 deletion .github/scripts/supported_models/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
gitpython==3.1.43
pytablewriter==1.2.0
gitpython==3.1.43
2 changes: 1 addition & 1 deletion .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}
with:
post-pr-comment: false
post-pr-comment: false
2 changes: 1 addition & 1 deletion .github/workflows/crowdin-download.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/crowdin-upload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/generate-model-list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
CLOUDFLARE_ZONE: ${{ secrets.CLOUDFLARE_ZONE }}
CLOUDFLARE_EMAIL: ${{ secrets.CLOUDFLARE_EMAIL }}
CLOUDFLARE_KEY: ${{ secrets.CLOUDFLARE_KEY }}
PURGE_URLS: '["https://powercalc.lauwbier.nl/api/library"]'
PURGE_URLS: '["https://powercalc.lauwbier.nl/api/library"]'
2 changes: 1 addition & 1 deletion .github/workflows/hacs-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v4
- name: validation
- name: validation
uses: "hacs/action@main"
with:
category: "integration"
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
- uses: ./.github/workflows/poetry-composite-action
- name: Run Ruff
run: |
poetry run ruff .
poetry run ruff .
2 changes: 1 addition & 1 deletion .github/workflows/poetry-composite-action/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ runs:
run: cd $INPUT_DIRECTORY; poetry install --no-interaction --no-root
if: steps.cache-deps.outputs.cache-hit != 'true'
env:
INPUT_DIRECTORY: ${{ inputs.directory }}
INPUT_DIRECTORY: ${{ inputs.directory }}
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
with:
disable-releaser: github.ref != 'refs/heads/main'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
file: ./custom_components/powercalc/powercalc.zip
asset_name: powercalc.zip
tag: ${{ github.ref }}
overwrite: true
overwrite: true
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
days-before-issue-stale: 30
days-before-pr-stale: 45
days-before-issue-close: 5
days-before-pr-close: 10
days-before-pr-close: 10
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ jobs:
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: coverage.lcov
path-to-lcov: coverage.lcov
33 changes: 31 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-builtin-literals
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
exclude: ^.*/?tsconfig\.json$
- id: check-shebang-scripts-are-executable
- id: check-symlinks
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: destroyed-symlinks
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: forbid-submodules
- id: mixed-line-ending
- id: pretty-format-json
args: [ --autofix, --no-sort-keys, --no-ensure-ascii ]
exclude: ^.*/?tsconfig\.json$
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.2.2'
rev: v0.4.8
hooks:
- id: ruff
- id: ruff
args: [ --fix ]
- id: ruff-format
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ sphinx:
# Explicitly set the version of Python and its requirements
python:
install:
- requirements: docs/requirements.txt
- requirements: docs/requirements.txt
2 changes: 1 addition & 1 deletion INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ powercalc:

## Setup power sensors

After restarting power and energy sensors should appear for the lights found in your HA installation which are supported by powercalc.
After restarting power and energy sensors should appear for the lights found in your HA installation which are supported by powercalc.
Please see the list of [supported models](https://powercalc.lauwbier.nl).
When no power sensor is appearing please check the logs for any errors.
Powercalc also provides extensive configuation to setup your own power sensors using different strategies. Please see the main [Documentation](https://github.com/bramstroker/homeassistant-powercalc/blob/master/README.md) on github for all the options and examples.
Expand Down
2 changes: 1 addition & 1 deletion crowdin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ files: [
}
}
}
]
]
54 changes: 29 additions & 25 deletions custom_components/powercalc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,29 +343,37 @@ async def setup_yaml_sensors(

async def _load_secondary_sensors(_: None) -> None:
"""Load secondary sensors after primary sensors."""
await asyncio.gather(*(
hass.async_create_task(async_load_platform(
hass,
Platform.SENSOR,
DOMAIN,
sensor_config,
config,
))
for sensor_config in secondary_sensors
))
await asyncio.gather(
*(
hass.async_create_task(
async_load_platform(
hass,
Platform.SENSOR,
DOMAIN,
sensor_config,
config,
),
)
for sensor_config in secondary_sensors
),
)

hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, _load_secondary_sensors)

await asyncio.gather(*(
hass.async_create_task(async_load_platform(
hass,
Platform.SENSOR,
DOMAIN,
sensor_config,
config,
))
for sensor_config in primary_sensors
))
await asyncio.gather(
*(
hass.async_create_task(
async_load_platform(
hass,
Platform.SENSOR,
DOMAIN,
sensor_config,
config,
),
)
for sensor_config in primary_sensors
),
)


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
Expand Down Expand Up @@ -426,11 +434,7 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
version = config_entry.version
if version == 1:
data = {**config_entry.data}
if (
CONF_FIXED in data
and CONF_POWER in data[CONF_FIXED]
and CONF_POWER_TEMPLATE in data[CONF_FIXED]
):
if CONF_FIXED in data and CONF_POWER in data[CONF_FIXED] and CONF_POWER_TEMPLATE in data[CONF_FIXED]:
data[CONF_FIXED].pop(CONF_POWER, None)
hass.config_entries.async_update_entry(config_entry, data=data, version=2)

Expand Down
Loading

0 comments on commit 634f11b

Please sign in to comment.