mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Remove warnings from compensation (#63691)
This commit is contained in:
parent
2df8ab865f
commit
5f9a351889
@ -1,6 +1,5 @@
|
|||||||
"""The Compensation integration."""
|
"""The Compensation integration."""
|
||||||
import logging
|
import logging
|
||||||
import warnings
|
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
@ -84,22 +83,14 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
# try to get valid coefficients for a polynomial
|
# try to get valid coefficients for a polynomial
|
||||||
coefficients = None
|
coefficients = None
|
||||||
with np.errstate(all="raise"):
|
with np.errstate(all="raise"):
|
||||||
with warnings.catch_warnings(record=True) as all_warnings:
|
try:
|
||||||
warnings.simplefilter("always")
|
coefficients = np.polyfit(x_values, y_values, degree)
|
||||||
try:
|
except FloatingPointError as error:
|
||||||
coefficients = np.polyfit(x_values, y_values, degree)
|
_LOGGER.error(
|
||||||
except FloatingPointError as error:
|
"Setup of %s encountered an error, %s",
|
||||||
_LOGGER.error(
|
compensation,
|
||||||
"Setup of %s encountered an error, %s",
|
error,
|
||||||
compensation,
|
)
|
||||||
error,
|
|
||||||
)
|
|
||||||
for warning in all_warnings:
|
|
||||||
_LOGGER.warning(
|
|
||||||
"Setup of %s encountered a warning, %s",
|
|
||||||
compensation,
|
|
||||||
str(warning.message).lower(),
|
|
||||||
)
|
|
||||||
|
|
||||||
if coefficients is not None:
|
if coefficients is not None:
|
||||||
data = {
|
data = {
|
||||||
|
@ -151,13 +151,6 @@ async def test_numpy_errors(hass, caplog):
|
|||||||
"compensation": {
|
"compensation": {
|
||||||
"test": {
|
"test": {
|
||||||
"source": "sensor.uncompensated",
|
"source": "sensor.uncompensated",
|
||||||
"data_points": [
|
|
||||||
[1.0, 1.0],
|
|
||||||
[1.0, 1.0],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
"test2": {
|
|
||||||
"source": "sensor.uncompensated2",
|
|
||||||
"data_points": [
|
"data_points": [
|
||||||
[0.0, 1.0],
|
[0.0, 1.0],
|
||||||
[0.0, 1.0],
|
[0.0, 1.0],
|
||||||
@ -170,8 +163,6 @@ async def test_numpy_errors(hass, caplog):
|
|||||||
await hass.async_start()
|
await hass.async_start()
|
||||||
await hass.async_block_till_done()
|
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
|
assert "invalid value encountered in true_divide" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user