Squelch ongoing alerts so message is only sent once
This commit is contained in:
parent
aa955816f9
commit
cddc49bbfe
@ -15,8 +15,6 @@ class History:
|
|||||||
self._last_price_movement : int = 0
|
self._last_price_movement : int = 0
|
||||||
self._latest_price_datum : Tuple[datetime.datetime, int] | None = None
|
self._latest_price_datum : Tuple[datetime.datetime, int] | None = None
|
||||||
self._update_triggers : List[UpdateTrigger] = []
|
self._update_triggers : List[UpdateTrigger] = []
|
||||||
self._squelched_alerts : List[Alert] = []
|
|
||||||
|
|
||||||
for alert_type in AlertType:
|
for alert_type in AlertType:
|
||||||
self._update_triggers.append(UpdateTrigger(Alert(alert_type, flavor, self._region)))
|
self._update_triggers.append(UpdateTrigger(Alert(alert_type, flavor, self._region)))
|
||||||
|
|
||||||
@ -39,9 +37,8 @@ class History:
|
|||||||
async def _process_update_triggers(self) -> List[Alert]:
|
async def _process_update_triggers(self) -> List[Alert]:
|
||||||
alerts = []
|
alerts = []
|
||||||
for trigger in self._update_triggers:
|
for trigger in self._update_triggers:
|
||||||
if trigger.check_and_update(self._latest_price_datum, self._history) and trigger.alert not in self._squelched_alerts:
|
if trigger.check_and_update(self._latest_price_datum, self._history):
|
||||||
alerts.append(trigger.alert)
|
alerts.append(trigger.alert)
|
||||||
|
|
||||||
return alerts
|
return alerts
|
||||||
|
|
||||||
async def add_price(self, datum: Tuple[datetime.datetime, int]) -> List[Alert]:
|
async def add_price(self, datum: Tuple[datetime.datetime, int]) -> List[Alert]:
|
||||||
|
@ -9,6 +9,7 @@ class UpdateTrigger:
|
|||||||
def __init__(self, alert: Alert):
|
def __init__(self, alert: Alert):
|
||||||
self._alert : Alert = alert
|
self._alert : Alert = alert
|
||||||
self._last_trigger : Tuple[datetime.datetime, int] | None = None
|
self._last_trigger : Tuple[datetime.datetime, int] | None = None
|
||||||
|
self._squelched : bool = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def alert(self) -> Alert:
|
def alert(self) -> Alert:
|
||||||
@ -75,5 +76,9 @@ class UpdateTrigger:
|
|||||||
|
|
||||||
if comparison_operator(new_datum[1], self._last_trigger[1]):
|
if comparison_operator(new_datum[1], self._last_trigger[1]):
|
||||||
self._last_trigger = new_datum
|
self._last_trigger = new_datum
|
||||||
return True
|
was_squelched = self._squelched
|
||||||
|
self._squelched = True
|
||||||
|
return not was_squelched # Returns True if squelched otherwise True
|
||||||
|
elif self._squelched:
|
||||||
|
self._squelched = False
|
||||||
return False
|
return False
|
Loading…
Reference in New Issue
Block a user