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: repos:
- repo: https://github.com/asottile/pyupgrade - repo: https://github.com/pycqa/isort
rev: v2.3.0 rev: 5.12.0
hooks: hooks:
- id: pyupgrade - id: isort
args: [--py37-plus] - repo: https://github.com/ambv/black
- repo: https://github.com/psf/black rev: 22.3.0
rev: 19.10b0
hooks: hooks:
- id: black - id: black
args: language_version: python3
- --safe - repo: https://github.com/pycqa/flake8
- --quiet rev: 3.9.2
files: ^((homeassistant|script|tests)/.+)?[^/]+\.py$
- repo: https://github.com/codespell-project/codespell
rev: v1.16.0
hooks: hooks:
- id: codespell - id: flake8
args: additional_dependencies:
- --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 - flake8-bugbear==20.1.4
- --skip="./.*,*.csv,*.json" - flake8-builtins==1.5.3
- --quiet-level=2 - flake8-comprehensions==3.2.3
exclude_types: [csv, json] - flake8-tidy-imports==4.1.0
- repo: https://gitlab.com/pycqa/flake8 - flake8-eradicate==1.1.0
rev: 3.8.1 - flake8-print==4.0.0
hooks: - flake8-return==1.1.2
- id: flake8 - flake8-use-fstring==1.1
additional_dependencies: - git+https://github.com/derrix060/flake8-expression-complexity.git
- 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

View File

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

View File

@ -1,11 +1,11 @@
import re
import logging import logging
import re
from typing import Any, Dict, Optional 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 homeassistant.helpers.config_validation as cv
import voluptuous as vol import voluptuous as vol
from homeassistant import config_entries
from homeassistant.const import CONF_EMAIL
from .const import DOMAIN from .const import DOMAIN
@ -48,7 +48,7 @@ def validate_uyu_phone_number(phone_number: str) -> None:
if not phone_number.startswith("598"): if not phone_number.startswith("598"):
raise ValueError 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 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_create_entry(title="UTE", data=self.data)
return self.async_show_form( return self.async_show_form(step_id="user", data_schema=AUTH_SCHEMA, errors=errors)
step_id="user", data_schema=AUTH_SCHEMA, errors=errors
)

View File

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