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: {}
This commit is contained in:
Christian Biamont 2019-01-28 12:30:15 +01:00 committed by Martin Hjelmare
parent 29984efd8c
commit f33e432cab

View File

@ -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)