Skip to content

Commit

Permalink
3.12 (#78)
Browse files Browse the repository at this point in the history
* 3.12

* Update code_checker.yml

* Update pyproject.toml

* fixup! Format Python code with black

* Update pyproject.toml

* ruff

Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>

* ruff

Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>

---------

Signed-off-by: Daniel Hjelseth Høyer <github@dahoiv.net>
  • Loading branch information
Danielhiversen authored Jan 23, 2024
1 parent 872f2d6 commit 7be4255
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 40 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/code_checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ jobs:
strategy:
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"
env:
SRC_FOLDER: custom_components/tibber_data
steps:
Expand All @@ -83,9 +83,9 @@ jobs:
cache: 'pip'
- name: Install depencency
run: |
pip install dlint flakeheaven flake8-deprecated flake8-executable pylint mypy homeassistant pyTibber
- name: Flake8 Code Linter
run: flakeheaven lint $SRC_FOLDER
pip install dlint ruff flake8-deprecated flake8-executable pylint mypy homeassistant pyTibber
- name: Ruff Code Linter
run: ruff $SRC_FOLDER
# - name: Mypy Code Linter
# run: mypy $SRC_FOLDER
- name: Pylint Code Linter
Expand Down
2 changes: 1 addition & 1 deletion custom_components/tibber_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def async_setup(hass, config):
try:
await home.update_info()
except Exception: # pylint: disable=broad-exception-caught
_LOGGER.error("Error", exc_info=True)
_LOGGER.exception("Error")
if k == 19:
raise
await asyncio.sleep(min(60, 2**k))
Expand Down
4 changes: 3 additions & 1 deletion custom_components/tibber_data/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def __init__(self, coordinator, entity_description):
f"{coordinator.tibber_home.home_id}_{entity_description.key}"
)

self._attr_name = f"{self.entity_description.name} {self.coordinator.tibber_home.address1}"
self._attr_name = (
f"{self.entity_description.name} {self.coordinator.tibber_home.address1}"
)

@callback
def _handle_coordinator_update(self) -> None:
Expand Down
27 changes: 12 additions & 15 deletions custom_components/tibber_data/data_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import datetime
import logging
from random import randrange
from typing import List, Set

import aiohttp
import tibber
Expand Down Expand Up @@ -43,13 +42,13 @@ def __init__(self, hass, tibber_home: tibber.TibberHome, email: str, password: s
update_interval=datetime.timedelta(seconds=15),
)
self.tibber_home: tibber.TibberHome = tibber_home
tibber_home._timeout = 30
tibber_home._timeout = 30 # noqa: SLF001
self.email = email
self._password = password
self._token = None
self._chargers: List[str] = []
self._offline_evs: List[dict] = []
self._month_consumption: Set[Consumption] = set()
self._chargers: list[str] = []
self._offline_evs: list[dict] = []
self._month_consumption: set[Consumption] = set()

self._session = aiohttp.ClientSession()
self.charger_name = {}
Expand Down Expand Up @@ -482,17 +481,15 @@ async def _get_data(self, data, now):
@property
def offline_ev_entity_descriptions(self):
"""Return the entity descriptions for the offline ev."""
entity_descriptions = []
for ev_dev in self._offline_evs:
entity_descriptions.append(
SensorEntityDescription(
key=f"offline_ev_{ev_dev['brandAndModel']}_soc",
name=f"{ev_dev['brandAndModel']} soc",
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
)
return [
SensorEntityDescription(
key=f"offline_ev_{ev_dev['brandAndModel']}_soc",
name=f"{ev_dev['brandAndModel']} soc",
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
)
return entity_descriptions
for ev_dev in self._offline_evs
]

@property
def subsidy(self):
Expand Down
13 changes: 8 additions & 5 deletions custom_components/tibber_data/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,19 @@ async def async_setup_platform(hass: HomeAssistant, _, async_add_entities, confi

if config.get("password"):
for entity_description in TIBBER_APP_SENSORS:
dev.append(TibberDataSensor(coordinator, entity_description))
dev.append( # noqa: PERF401
TibberDataSensor(coordinator, entity_description)
)
for (
chargers_entity_descriptions
) in coordinator.chargers_entity_descriptions:
dev.append(TibberDataSensor(coordinator, chargers_entity_descriptions))
dev.append( # noqa: PERF401
TibberDataSensor(coordinator, chargers_entity_descriptions)
)
for (
offline_ev_entity_descriptions
) in coordinator.offline_ev_entity_descriptions:
dev.append(
dev.append( # noqa: PERF401
TibberDataSensor(coordinator, offline_ev_entity_descriptions)
)

Expand Down Expand Up @@ -214,10 +218,9 @@ def update_grid_price_sensor(self):
self._attr_extra_state_attributes["raw_tomorrow"] = local_raw_tomorrow
else:
_LOGGER.debug("No grid price available")
native_value = self.coordinator.data.get(self.entity_description.key, {}).get(
return self.coordinator.data.get(self.entity_description.key, {}).get(
dt_util.now().replace(minute=0, second=0, microsecond=0)
)
return native_value

@property
def subsidy(self):
Expand Down
10 changes: 5 additions & 5 deletions custom_components/tibber_data/tibber_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ async def get_historic_data(
query = """
{{
viewer {{
home(id: "{0}") {{
consumption(resolution: HOURLY, last: 9600, before:"{1}") {{
home(id: "{}") {{
consumption(resolution: HOURLY, last: 9600, before:"{}") {{
nodes {{
consumption
cost
Expand Down Expand Up @@ -53,8 +53,8 @@ async def get_historic_production_data(
query = """
{{
viewer {{
home(id: "{0}") {{
production(resolution: HOURLY, last: 744, before:"{1}") {{
home(id: "{}") {{
production(resolution: HOURLY, last: 744, before:"{}") {{
nodes {{
from
profit
Expand Down Expand Up @@ -172,7 +172,7 @@ async def get_tibber_chargers_data(
+ '" resolution: "DAILY" from: "'
+ str(now.year)
+ "-"
+ "{:02d}".format(now.month)
+ f"{now.month:02d}"
+ '-01T00:00:00+0200" ) { from consumption energyCost } } } }',
}
),
Expand Down
14 changes: 5 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ profile = "black"
follow_imports = "silent"
ignore_missing_imports = true

[tool.flakeheaven]
max_line_length = 120
# make output nice
format = "grouped"
# show line of source code in output
show_source = true
[tool.ruff]
select = ["E", "F", "PL", "W", "ASYNC", "A", "DTZ", "G", "T20", "RET", "RUF", "TCH", "S", "B", "C90", "T10", "N", "PERF", "UP", "SLF", "TID", "TCH"]
ignore = ["PLR0913", "C901", "S101", "PLR2004", "S311", "PLR0912", "PLR0915", "DTZ005", ]
line-length = 120
target-version = "py311"

[tool.flakeheaven.plugins]
pyflakes = ["+*"]
"flake8-*" = ["+*"]

[tool.pytest.ini_options]
testpaths = [
Expand Down

0 comments on commit 7be4255

Please sign in to comment.