* Add ema calculation class, calculate an emo temperature, use the ema_temperature in auto_window dectection * Removes circular dependency error * Fix ema_temp unknown and remove slope smoothing * 15 sec between two slope calculation * Take Maia feedbacks on the algo. * Maia comments: change MAX_ALPHA to 0.5, add slope calculation at each cycle. * With EMA entity and slope calculation optimisations * Change open_window_detection fake datapoint threshold * Try auto window new algo * Don't store datetime of fake datapoint * Change auto window threshold in °/hour --------- Co-authored-by: Jean-Marc Collin <jean-marc.collin-extern@renault.com>
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
# pylint: disable=line-too-long
|
|
""" Tests de EMA calculation"""
|
|
from datetime import datetime, timedelta
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from custom_components.versatile_thermostat.ema import ExponentialMovingAverage
|
|
|
|
from .commons import get_tz
|
|
|
|
|
|
def test_ema_basics(hass: HomeAssistant):
|
|
"""Test the EMA calculation with basic features"""
|
|
|
|
tz = get_tz(hass) # pylint: disable=invalid-name
|
|
now: datetime = datetime.now(tz=tz)
|
|
|
|
the_ema = ExponentialMovingAverage(
|
|
"test",
|
|
# 5 minutes
|
|
300,
|
|
# Needed for time calculation
|
|
get_tz(hass),
|
|
1,
|
|
)
|
|
|
|
assert the_ema
|
|
|
|
current_timestamp = now
|
|
# First initialization
|
|
assert the_ema.calculate_ema(20, current_timestamp) == 20
|
|
|
|
current_timestamp = current_timestamp + timedelta(minutes=1)
|
|
# One minute later, same temperature. EMA temperature should not have change
|
|
assert the_ema.calculate_ema(20, current_timestamp) == 20
|
|
|
|
# Too short measurement should be ignored
|
|
assert the_ema.calculate_ema(2000, current_timestamp) == 20
|
|
|
|
current_timestamp = current_timestamp + timedelta(seconds=4)
|
|
assert the_ema.calculate_ema(20, current_timestamp) == 20
|
|
|
|
# a new normal measurement 5 minutes later
|
|
current_timestamp = current_timestamp + timedelta(minutes=5)
|
|
ema = the_ema.calculate_ema(25, current_timestamp)
|
|
assert ema > 20
|
|
assert ema == 22.5
|
|
|
|
# a big change in a short time does have a limited effect
|
|
current_timestamp = current_timestamp + timedelta(seconds=5)
|
|
ema = the_ema.calculate_ema(30, current_timestamp)
|
|
assert ema > 22.5
|
|
assert ema < 23
|
|
assert ema == 22.6
|