Skip to content

Commit

Permalink
Fix exclude_attributes (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed Oct 1, 2023
1 parent 9837e93 commit 6caab39
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
14 changes: 0 additions & 14 deletions custom_components/average/recorder.py

This file was deleted.

37 changes: 29 additions & 8 deletions custom_components/average/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6caab39

Please sign in to comment.