diff --git a/custom_components/average/recorder.py b/custom_components/average/recorder.py deleted file mode 100644 index 2460e9c..0000000 --- a/custom_components/average/recorder.py +++ /dev/null @@ -1,14 +0,0 @@ -"""Integration platform for recorder.""" -from __future__ import annotations - -from homeassistant.core import HomeAssistant, callback - -from .const import ATTR_SOURCES, ATTR_TO_PROPERTY - - -@callback -def exclude_attributes(hass: HomeAssistant) -> set[str]: - """Exclude unimportant attributes from being recorded in the database.""" - attributes_to_exclude = set(ATTR_TO_PROPERTY) - attributes_to_exclude.discard(ATTR_SOURCES) - return attributes_to_exclude diff --git a/custom_components/average/sensor.py b/custom_components/average/sensor.py index 368e5e2..fac7c2f 100644 --- a/custom_components/average/sensor.py +++ b/custom_components/average/sensor.py @@ -2,28 +2,27 @@ # Creative Commons BY-NC-SA 4.0 International Public License # (see LICENSE.md or https://creativecommons.org/licenses/by-nc-sa/4.0/) -""" -The Average Sensor. +"""The Average Sensor. For more details about this sensor, please refer to the documentation at https://github.com/Limych/ha-average/ """ from __future__ import annotations +from collections.abc import Mapping import datetime import logging import math import numbers -from _sha1 import sha1 -from typing import Any, Mapping, Optional +from typing import Any, Optional -import homeassistant.util.dt as dt_util +from _sha1 import sha1 import voluptuous as vol + from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN from homeassistant.components.group import expand_entity_ids from homeassistant.components.recorder import get_instance, history -from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, \ - SensorEntity +from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity from homeassistant.components.water_heater import DOMAIN as WATER_HEATER_DOMAIN from homeassistant.components.weather import DOMAIN as WEATHER_DOMAIN from homeassistant.const import ( @@ -44,10 +43,18 @@ from homeassistant.helpers.config_validation import PLATFORM_SCHEMA from homeassistant.helpers.event import async_track_state_change from homeassistant.util import Throttle +import homeassistant.util.dt as dt_util from homeassistant.util.unit_conversion import TemperatureConverter from homeassistant.util.unit_system import TEMPERATURE_UNITS from .const import ( + ATTR_AVAILABLE_SOURCES, + ATTR_COUNT, + ATTR_COUNT_SOURCES, + ATTR_END, + ATTR_MAX_VALUE, + ATTR_MIN_VALUE, + ATTR_START, ATTR_TO_PROPERTY, CONF_DURATION, CONF_END, @@ -126,6 +133,18 @@ async def async_setup_platform( class AverageSensor(SensorEntity): """Implementation of an Average sensor.""" + _unrecorded_attributes = frozenset( + { + ATTR_START, + ATTR_END, + ATTR_COUNT_SOURCES, + ATTR_AVAILABLE_SOURCES, + ATTR_COUNT, + ATTR_MAX_VALUE, + ATTR_MIN_VALUE, + } + ) + # pylint: disable=too-many-arguments def __init__( self, @@ -256,7 +275,9 @@ def _get_temperature(self, state: State) -> Optional[float]: return None try: - temperature = TemperatureConverter.convert(float(temperature), entity_unit, ha_unit) + temperature = TemperatureConverter.convert( + float(temperature), entity_unit, ha_unit + ) except ValueError as exc: _LOGGER.error('Could not convert value "%s" to float: %s', state, exc) return None diff --git a/requirements-dev.txt b/requirements-dev.txt index 7cb07d2..ed2ae91 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,6 +2,6 @@ black~=23.9.0 packaging~=23.0 pre-commit~=3.0 -PyGithub~=1.57 -pyupgrade~=3.3 +PyGithub~=1.59 +pyupgrade~=3.13 yamllint~=1.28 diff --git a/requirements-test.txt b/requirements-test.txt index 82883ac..2cbcad2 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -2,11 +2,11 @@ flake8~=6.0 flake8-docstrings~=1.6 fnv-hash-fast~=0.4 -mypy==1.5.0 +mypy~=1.5.0 psutil-home-assistant==0.0.1 pylint~=2.15 pylint-strict-informational==0.1 pytest>=7.2 pytest-cov>=3.0 -pytest-homeassistant-custom-component>=0.13 +pytest-homeassistant-custom-component>=0.12.49 pytest-asyncio>=0.20