Formatted the files and changed to non async executor

This commit is contained in:
Roger Gonzalez 2023-09-23 20:25:28 -03:00
parent ab55efc3eb
commit d111d187b3
Signed by: rogs
GPG Key ID: C7ECE9C6C36EC2E6
6 changed files with 77 additions and 81 deletions

2
.flake8 Normal file
View File

@ -0,0 +1,2 @@
[flake8]
max-line-length = 121

View File

@ -1,58 +1,25 @@
exclude: ^(.bzr|\.direnv|\.eggs|\.git|\.hg|\.mypy_cache|\.nox|\.pants\.d|\.svn|\.tox|\.venv|_build|buck-out|build|dist|node_modules|venv|\.idea|dockerdata|static|.*\b(migrations)\b.*)
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.3.0
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/psf/black
rev: 19.10b0
- id: isort
- repo: https://github.com/ambv/black
rev: 22.3.0
hooks:
- id: black
args:
- --safe
- --quiet
files: ^((homeassistant|script|tests)/.+)?[^/]+\.py$
- repo: https://github.com/codespell-project/codespell
rev: v1.16.0
hooks:
- id: codespell
args:
- --ignore-words-list=hass,alot,datas,dof,dur,farenheit,hist,iff,ines,ist,lightsensor,mut,nd,pres,referer,ser,serie,te,technik,ue,uint,visability,wan,wanna,withing
- --skip="./.*,*.csv,*.json"
- --quiet-level=2
exclude_types: [csv, json]
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.1
language_version: python3
- repo: https://github.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
additional_dependencies:
- flake8-docstrings==1.5.0
- pydocstyle==5.0.2
files: ^(homeassistant|script|tests)/.+\.py$
- repo: https://github.com/PyCQA/bandit
rev: 1.6.2
hooks:
- id: bandit
args:
- --quiet
- --format=custom
- --configfile=tests/bandit.yaml
files: ^(homeassistant|script|tests)/.+\.py$
- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.21
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: check-executables-have-shebangs
stages: [manual]
- id: check-json
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.770
hooks:
- id: mypy
args:
- --pretty
- --show-error-codes
- --show-error-context
- flake8-bugbear==20.1.4
- flake8-builtins==1.5.3
- flake8-comprehensions==3.2.3
- flake8-tidy-imports==4.1.0
- flake8-eradicate==1.1.0
- flake8-print==4.0.0
- flake8-return==1.1.2
- flake8-use-fstring==1.1
- git+https://github.com/derrix060/flake8-expression-complexity.git

View File

@ -7,17 +7,13 @@ from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(
hass: core.HomeAssistant, entry: config_entries.ConfigEntry
) -> bool:
async def async_setup_entry(hass: core.HomeAssistant, entry: config_entries.ConfigEntry) -> bool:
"""Set up platform from a ConfigEntry."""
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = entry.data
# Forward the setup to the sensor platform.
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, "sensor")
)
hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, "sensor"))
return True

View File

@ -1,11 +1,11 @@
import re
import logging
import re
from typing import Any, Dict, Optional
from homeassistant import config_entries
from homeassistant.const import CONF_EMAIL
import homeassistant.helpers.config_validation as cv
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.const import CONF_EMAIL
from .const import DOMAIN
@ -48,7 +48,7 @@ def validate_uyu_phone_number(phone_number: str) -> None:
if not phone_number.startswith("598"):
raise ValueError
if not re.match(r"^[0-9]{11}$", phone_number):
if not re.match(r"^[0-9]{11}$", phone_number): # noqa: FS003
raise ValueError
@ -81,6 +81,4 @@ class UTEConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
return self.async_create_entry(title="UTE", data=self.data)
return self.async_show_form(
step_id="user", data_schema=AUTH_SCHEMA, errors=errors
)
return self.async_show_form(step_id="user", data_schema=AUTH_SCHEMA, errors=errors)

View File

@ -1,20 +1,16 @@
from datetime import timedelta
import logging
from datetime import timedelta
from typing import Callable, Optional
from ute_wrapper.ute import UTEClient
from homeassistant import config_entries, core
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import CONF_EMAIL
from homeassistant.helpers.entity import Entity
from homeassistant.helpers.typing import (
ConfigType,
DiscoveryInfoType,
HomeAssistantType,
)
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, HomeAssistantType
from ute_wrapper.ute import UTEClient
from .config_flow import CONF_PHONE_NUMBER, schema
from .const import DOMAIN
from .config_flow import schema, CONF_PHONE_NUMBER
_LOGGER = logging.getLogger(__name__)
# Time between updating data from UTE
@ -38,7 +34,7 @@ async def async_setup_entry(
async_add_entities(sensor, update_before_add=True)
async def async_setup_platform(
def setup_platform(
hass: HomeAssistantType,
config: ConfigType,
async_add_entities: Callable,
@ -64,8 +60,5 @@ class UTESensor(Entity):
self._name = "Current energy usage"
async def async_update(self):
try:
ute_data = await self.ute.get_current_usage_info()
self._state = ute_data["data"]["power_in_watts"]
except ():
pass

40
pyproject.toml Normal file
View File

@ -0,0 +1,40 @@
[tool.black]
line-length = 121
target-version = ['py36', 'py37', 'py38']
include = '\.pyi?$'
# regex below includes default list from isort, for parity
exclude = '''
/(
\.bzr
| \.direnv
| \.eggs
| \.git
| \.hg
| \.mypy_cache
| \.nox
| \.pants\.d
| \.svn
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
| node_modules
| venv
| \.idea
| dockerdata
| static
)/
'''
[tool.isort]
# these are black-compatible settings
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true
line_length = 121
skip = "dockerdata,.idea,static"
filter_files = true