Skip to content

Commit

Permalink
Minor updates in devel configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
ldotlopez committed Jan 5, 2024
1 parent 057ecc6 commit 2951c68
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
rev: v4.5.0
hooks:
- id: end-of-file-fixer
# exclude: '\.json$'
Expand All @@ -14,18 +14,18 @@ repos:
- id: debug-statements

- repo: https://github.com/asottile/pyupgrade
rev: v3.9.0
rev: v3.15.0
hooks:
- id: pyupgrade
args: ['--py310-plus']
args: ['--py311-plus']

- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.0
hooks:
- id: isort
args: ['--profile', 'black']

- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.12.1
hooks:
- id: black
9 changes: 6 additions & 3 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ name = "pypi"
[packages]

[dev-packages]
black = "*"
build = "*"
homeassistant = ">=2024.1.0"
homeassistant-historical-sensor = {editable = true, path = "."}
sqlalchemy = "*"
ipdb = "*"
ipython = "*"
isort = "*"
mypy = "*"
pre-commit = "*"
homeassistant = ">=2024.1.0b0"
build = "*"
sqlalchemy = "*"
twine = "*"

[requires]
Expand Down
2 changes: 0 additions & 2 deletions config/configuration.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

# Loads default set of integrations. Do not remove.
default_config:

logger:
Expand Down
7 changes: 1 addition & 6 deletions custom_components/delorian/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
#

import itertools
import logging
import statistics
from datetime import datetime, timedelta

from homeassistant.components.recorder.models import StatisticData, StatisticMetaData
from homeassistant.components.recorder.statistics import StatisticsRow
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import UnitOfEnergy
Expand Down Expand Up @@ -124,10 +122,7 @@ def get_statistic_metadata(self) -> StatisticMetaData:
return meta

async def async_calculate_statistic_data(
self,
hist_states: list[HistoricalState],
*,
latest: StatisticsRow | None = None,
self, hist_states: list[HistoricalState], *, latest: dict | None = None
) -> list[StatisticData]:
#
# Group historical states by hour
Expand Down
12 changes: 6 additions & 6 deletions homeassistant_historical_sensor/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.


import logging
from abc import abstractmethod
from datetime import datetime, timedelta
from functools import cached_property

import sqlalchemy.exc
import sqlalchemy.orm
Expand Down Expand Up @@ -86,11 +86,11 @@ async def async_added_to_hass(self):
if self.statistic_id and getattr(self, "state_class", None):
_LOGGER.warning(
f"{self.entity_id}: state_class attribute is set. "
"This is NOT supported, your statistics will be messed sooner or later"
+ "This is NOT supported, your statistics will be messed sooner or later"
)

@property
def should_poll(self):
@cached_property
def should_poll(self) -> bool:
# HistoricalSensors MUST NOT poll.
# Polling creates incorrect states at intermediate time points.

Expand Down Expand Up @@ -143,7 +143,7 @@ async def async_write_ha_historical_states(self):
hist_states = list(sorted(hist_states, key=lambda x: x.dt))
_LOGGER.debug(
f"{self.entity_id}: "
f"{len(hist_states)} historical states present in sensor"
+ f"{len(hist_states)} historical states present in sensor"
)

if not hist_states:
Expand Down Expand Up @@ -213,7 +213,7 @@ def _write_recorder_states(
cutoff = dtutil.utc_from_timestamp(latest.last_updated_ts or 0)
_LOGGER.debug(
f"{self.entity_id}: "
f"lastest state found at {cutoff} ({latest.state})"
+ f"lastest state found at {cutoff} ({latest.state})"
)
hist_states = [x for x in hist_states if x.dt > cutoff]

Expand Down
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# https://packaging.python.org/tutorials/packaging-projects/

[project]
name = "homeassistant-historical-sensor"
version = "2.0.0rc4"
Expand All @@ -15,7 +17,7 @@ classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
requires-python = ">3.11"
requires-python = ">=3.11"

[project.urls]
Homepage = "https://github.com/ldotlopez/ha-historical-sensor"
Expand All @@ -41,5 +43,8 @@ profile = "black"
[tool.mypy]
files = ['homeassistant_historical_sensor']

[tool.pyupgrade]
addopts = "--py311-plus"

[tool.setuptools]
packages = ["homeassistant_historical_sensor"]

0 comments on commit 2951c68

Please sign in to comment.