From f33e432cab6584b33f39ee6c2d0ec9b5891bbf7c Mon Sep 17 00:00:00 2001 From: Christian Biamont <christianbiamont@gmail.com> Date: Mon, 28 Jan 2019 12:30:15 +0100 Subject: [PATCH] Reset Brottsplatskartan incident types every day (#20117) * Reset the incident types count every day * Remove functionality that was never implemented We don't need to keep track of previous incidents because it's not used anywhere. * Create empty dictionary with a pair of braces: {} --- homeassistant/components/sensor/brottsplatskartan.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/sensor/brottsplatskartan.py b/homeassistant/components/sensor/brottsplatskartan.py index dc338e6b84a..c308f2eac53 100644 --- a/homeassistant/components/sensor/brottsplatskartan.py +++ b/homeassistant/components/sensor/brottsplatskartan.py @@ -69,11 +69,9 @@ class BrottsplatskartanSensor(Entity): def __init__(self, bpk, name): """Initialize the Brottsplatskartan sensor.""" - import brottsplatskartan - self._attributes = {ATTR_ATTRIBUTION: brottsplatskartan.ATTRIBUTION} + self._attributes = {} self._brottsplatskartan = bpk self._name = name - self._previous_incidents = set() self._state = None @property @@ -93,6 +91,7 @@ class BrottsplatskartanSensor(Entity): def update(self): """Update device state.""" + import brottsplatskartan incident_counts = defaultdict(int) incidents = self._brottsplatskartan.get_incidents() @@ -100,13 +99,10 @@ class BrottsplatskartanSensor(Entity): _LOGGER.debug("Problems fetching incidents") return - if len(incidents) < len(self._previous_incidents): - self._previous_incidents = set() - for incident in incidents: incident_type = incident.get('title_type') incident_counts[incident_type] += 1 - self._previous_incidents.add(incident.get('id')) + self._attributes = {ATTR_ATTRIBUTION: brottsplatskartan.ATTRIBUTION} self._attributes.update(incident_counts) self._state = len(incidents) -- GitLab