Skip to content

Commit

Permalink
Reformatting linter fixes (#131)
Browse files Browse the repository at this point in the history
* Adjusted eols

Also updated .gitattributes and extensions.json

* Linter fix

Sorted imports using ruff.
Auto spacing using ruff.
Relative imports in tests.
Added None return type in tests.
  • Loading branch information
iprak authored May 10, 2024
1 parent a8b9b90 commit 8acc7cb
Show file tree
Hide file tree
Showing 21 changed files with 1,105 additions and 1,073 deletions.
Empty file modified .devcontainer/configuration.yaml
100644 → 100755
Empty file.
Empty file modified .devcontainer/devcontainer.json
100644 → 100755
Empty file.
10 changes: 5 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.git
config
.devcontainer
.vscode
**/__pycache__
.git
config
.devcontainer
.vscode
**/__pycache__
34 changes: 17 additions & 17 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: Validate

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

jobs:
validate:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
- name: HACS validation
uses: "hacs/action@main"
with:
category: "integration"
name: Validate

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

jobs:
validate:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
- name: HACS validation
uses: "hacs/action@main"
with:
category: "integration"
114 changes: 57 additions & 57 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.38.0
hooks:
- id: pyupgrade
args: [--py39-plus]
- repo: https://github.com/psf/black
rev: 22.8.0
hooks:
- id: black
args:
- --safe
- --quiet
files: ^((homeassistant|pylint|script|tests)/.+)?[^/]+\.py$
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
args:
- --ignore-words-list=hass,alot,datas,dof,dur,ether,farenheit,hist,iff,iif,ines,ist,lightsensor,mut,nd,pres,referer,rime,ser,serie,te,technik,ue,uint,visability,wan,wanna,withing,iam,incomfort,ba,haa,pullrequests
- --skip="./.*,*.csv,*.json"
- --quiet-level=2
exclude_types: [csv, json]
exclude: ^tests/fixtures/|homeassistant/generated/
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies:
- pycodestyle==2.8.0
- pyflakes==2.4.0
- flake8-docstrings==1.6.0
- pydocstyle==6.1.1
- flake8-comprehensions==3.10.0
- flake8-noqa==1.2.8
- mccabe==0.6.1
files: ^(homeassistant|script|tests)/.+\.py$
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
hooks:
- id: bandit
args:
- --quiet
- --format=custom
- --configfile=tests/bandit.yaml
files: ^(homeassistant|script|tests)/.+\.py$
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: check-executables-have-shebangs
stages: [manual]
- id: check-json
exclude: (.vscode|.devcontainer)
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.38.0
hooks:
- id: pyupgrade
args: [--py39-plus]
- repo: https://github.com/psf/black
rev: 22.8.0
hooks:
- id: black
args:
- --safe
- --quiet
files: ^((homeassistant|pylint|script|tests)/.+)?[^/]+\.py$
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
args:
- --ignore-words-list=hass,alot,datas,dof,dur,ether,farenheit,hist,iff,iif,ines,ist,lightsensor,mut,nd,pres,referer,rime,ser,serie,te,technik,ue,uint,visability,wan,wanna,withing,iam,incomfort,ba,haa,pullrequests
- --skip="./.*,*.csv,*.json"
- --quiet-level=2
exclude_types: [csv, json]
exclude: ^tests/fixtures/|homeassistant/generated/
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
additional_dependencies:
- pycodestyle==2.8.0
- pyflakes==2.4.0
- flake8-docstrings==1.6.0
- pydocstyle==6.1.1
- flake8-comprehensions==3.10.0
- flake8-noqa==1.2.8
- mccabe==0.6.1
files: ^(homeassistant|script|tests)/.+\.py$
- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
hooks:
- id: bandit
args:
- --quiet
- --format=custom
- --configfile=tests/bandit.yaml
files: ^(homeassistant|script|tests)/.+\.py$
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: check-executables-have-shebangs
stages: [manual]
- id: check-json
exclude: (.vscode|.devcontainer)
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"recommendations": [
"charliermarsh.ruff",
"esbenp.prettier-vscode",
"ms-python.python"
"ms-python.python",
"mhutchie.git-graph"
]
}
40 changes: 20 additions & 20 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License
Copyright (c) 2020 Indu Prakash @iprak
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
MIT License

Copyright (c) 2020 Indu Prakash @iprak

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion custom_components/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"""Dummy __init__.py to make imports with pytest-homeassistant-custom-component work."""
"""Dummy __init__.py to make imports with pytest-homeassistant-custom-component work."""
Empty file modified custom_components/yahoofinance/coordinator.py
100644 → 100755
Empty file.
16 changes: 8 additions & 8 deletions custom_components/yahoofinance/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from __future__ import annotations

from datetime import date, datetime, timedelta, time
from datetime import date, datetime, timedelta
import logging

from homeassistant.components.sensor import (
Expand All @@ -26,8 +26,8 @@
ATTR_CURRENCY_SYMBOL,
ATTR_DIVIDEND_DATE,
ATTR_MARKET_STATE,
ATTR_PRE_MARKET_TIME,
ATTR_POST_MARKET_TIME,
ATTR_PRE_MARKET_TIME,
ATTR_QUOTE_SOURCE_NAME,
ATTR_QUOTE_TYPE,
ATTR_REGULAR_MARKET_TIME,
Expand All @@ -42,8 +42,8 @@
DATA_DIVIDEND_DATE,
DATA_FINANCIAL_CURRENCY,
DATA_MARKET_STATE,
DATA_PRE_MARKET_TIME,
DATA_POST_MARKET_TIME,
DATA_PRE_MARKET_TIME,
DATA_QUOTE_SOURCE_NAME,
DATA_QUOTE_TYPE,
DATA_REGULAR_MARKET_PREVIOUS_CLOSE,
Expand Down Expand Up @@ -172,7 +172,7 @@ def safe_convert(value: float | None, conversion: float | None) -> float | None:
if conversion is None:
return value
return value * conversion

@staticmethod
def convert_timestamp_to_datetime(date_timestamp, return_format) -> str | None:
"""Convert Epoch JSON element to datetime."""
Expand All @@ -184,7 +184,7 @@ def convert_timestamp_to_datetime(date_timestamp, return_format) -> str | None:
converted_date = datetime.fromtimestamp(date_timestamp,tz=dt_util.DEFAULT_TIME_ZONE)
if return_format == "date":
converted_date = converted_date.date()

return converted_date.isoformat()

@property
Expand Down Expand Up @@ -380,15 +380,15 @@ def update_properties(self) -> None:
self._attr_extra_state_attributes[
ATTR_DIVIDEND_DATE
] = self.convert_timestamp_to_datetime(symbol_data.get(DATA_DIVIDEND_DATE),'date')

self._attr_extra_state_attributes[
ATTR_REGULAR_MARKET_TIME
] = self.convert_timestamp_to_datetime(symbol_data.get(DATA_REGULAR_MARKET_TIME),'dateTime')

self._attr_extra_state_attributes[
ATTR_POST_MARKET_TIME
] = self.convert_timestamp_to_datetime(symbol_data.get(DATA_POST_MARKET_TIME),'dateTime')

self._attr_extra_state_attributes[
ATTR_PRE_MARKET_TIME
] = self.convert_timestamp_to_datetime(symbol_data.get(DATA_PRE_MARKET_TIME),'dateTime')
Expand Down
6 changes: 3 additions & 3 deletions custom_components/yahoofinance/services.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Describes the format of available services for yahoofinance

refresh_symbols:
# Describes the format of available services for yahoofinance

refresh_symbols:
description: Refresh data for all the symbols.
20 changes: 13 additions & 7 deletions gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text eol=lf

# Declare files that will always have CRLF line endings on checkout.
*.py text eol=lf

*.sh text eol=lf
# Ensure Docker script files uses LF to support Docker for Windows.
# Ensure "git config --global core.autocrlf input" before you clone
* text eol=lf
*.py whitespace=error

*.ico binary
*.jpg binary
*.png binary
*.zip binary
*.mp3 binary
*.pcm binary

Dockerfile.dev linguist-language=Dockerfile
6 changes: 3 additions & 3 deletions hacs.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "Yahoo Finance",
"render_readme": true
{
"name": "Yahoo Finance",
"render_readme": true
}
8 changes: 4 additions & 4 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Tests for Yahoo Finance component."""

TEST_SYMBOL = "BABA"
TEST_CRUMB = "!123"
"""Tests for Yahoo Finance component."""

TEST_SYMBOL = "BABA"
TEST_CRUMB = "!123"
16 changes: 8 additions & 8 deletions tests/bad_request.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"finance": {
"result": null,
"error": {
"code": "Bad Request",
"description": "Missing required query parameter=symbols"
}
}
{
"finance": {
"result": null,
"error": {
"code": "Bad Request",
"description": "Missing required query parameter=symbols"
}
}
}
34 changes: 17 additions & 17 deletions tests/bandit.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# https://bandit.readthedocs.io/en/latest/config.html

tests:
- B108
- B306
- B307
- B313
- B314
- B315
- B316
- B317
- B318
- B319
- B320
- B325
- B602
- B604
# https://bandit.readthedocs.io/en/latest/config.html

tests:
- B108
- B306
- B307
- B313
- B314
- B315
- B316
- B317
- B318
- B319
- B320
- B325
- B602
- B604
Loading

0 comments on commit 8acc7cb

Please sign in to comment.