Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions homeassistant/components/compensation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""The Compensation integration."""
import logging
import warnings

import numpy as np
import voluptuous as vol
Expand Down Expand Up @@ -84,22 +83,14 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
# try to get valid coefficients for a polynomial
coefficients = None
with np.errstate(all="raise"):
with warnings.catch_warnings(record=True) as all_warnings:
warnings.simplefilter("always")
try:
coefficients = np.polyfit(x_values, y_values, degree)
except FloatingPointError as error:
_LOGGER.error(
"Setup of %s encountered an error, %s",
compensation,
error,
)
for warning in all_warnings:
_LOGGER.warning(
"Setup of %s encountered a warning, %s",
compensation,
str(warning.message).lower(),
)
try:
coefficients = np.polyfit(x_values, y_values, degree)
except FloatingPointError as error:
_LOGGER.error(
"Setup of %s encountered an error, %s",
compensation,
error,
)

if coefficients is not None:
data = {
Expand Down
9 changes: 0 additions & 9 deletions tests/components/compensation/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,6 @@ async def test_numpy_errors(hass, caplog):
"compensation": {
"test": {
"source": "sensor.uncompensated",
"data_points": [
[1.0, 1.0],
[1.0, 1.0],
],
},
"test2": {
"source": "sensor.uncompensated2",
"data_points": [
[0.0, 1.0],
[0.0, 1.0],
Expand All @@ -170,8 +163,6 @@ async def test_numpy_errors(hass, caplog):
await hass.async_start()
await hass.async_block_till_done()

assert "polyfit may be poorly conditioned" in caplog.text

assert "invalid value encountered in true_divide" in caplog.text


Expand Down