Skip to content

Commit

Permalink
Fix ordering with simultaneous alerts
Browse files Browse the repository at this point in the history
Sometimes more than one alert is issued with the same 'sent' date/time. The alert json feed randomly changes the ordering of these alerts in the feed and can result in re-triggering of notifications. The alerts array is now being reverse sorted by 'sent' time and 'id' to keep them consistent when the json feed shuffles them around.
  • Loading branch information
jlverhagen authored Mar 29, 2020
1 parent c769ca4 commit 161b378
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion custom_components/weatheralerts/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from homeassistant.helpers.entity import Entity
import homeassistant.helpers.config_validation as cv

__version__ = '0.1.0'
__version__ = '0.1.1'

CONF_STATE = "state"
CONF_ZONE = "zone"
Expand Down Expand Up @@ -180,6 +180,7 @@ async def async_update(self):
"zoneid": self.feedid,
}
)
alerts.sort(key=lambda x: (x['sent'], x['id']), reverse=True)

self._state = len(alerts)
self._attr = {
Expand Down

0 comments on commit 161b378

Please sign in to comment.