Skip to content
Snippets Groups Projects
Commit f33e432c authored by Christian Biamont's avatar Christian Biamont Committed by Martin Hjelmare
Browse files

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: {}
parent 29984efd
No related branches found
No related tags found
No related merge requests found
...@@ -69,11 +69,9 @@ class BrottsplatskartanSensor(Entity): ...@@ -69,11 +69,9 @@ class BrottsplatskartanSensor(Entity):
def __init__(self, bpk, name): def __init__(self, bpk, name):
"""Initialize the Brottsplatskartan sensor.""" """Initialize the Brottsplatskartan sensor."""
import brottsplatskartan self._attributes = {}
self._attributes = {ATTR_ATTRIBUTION: brottsplatskartan.ATTRIBUTION}
self._brottsplatskartan = bpk self._brottsplatskartan = bpk
self._name = name self._name = name
self._previous_incidents = set()
self._state = None self._state = None
@property @property
...@@ -93,6 +91,7 @@ class BrottsplatskartanSensor(Entity): ...@@ -93,6 +91,7 @@ class BrottsplatskartanSensor(Entity):
def update(self): def update(self):
"""Update device state.""" """Update device state."""
import brottsplatskartan
incident_counts = defaultdict(int) incident_counts = defaultdict(int)
incidents = self._brottsplatskartan.get_incidents() incidents = self._brottsplatskartan.get_incidents()
...@@ -100,13 +99,10 @@ class BrottsplatskartanSensor(Entity): ...@@ -100,13 +99,10 @@ class BrottsplatskartanSensor(Entity):
_LOGGER.debug("Problems fetching incidents") _LOGGER.debug("Problems fetching incidents")
return return
if len(incidents) < len(self._previous_incidents):
self._previous_incidents = set()
for incident in incidents: for incident in incidents:
incident_type = incident.get('title_type') incident_type = incident.get('title_type')
incident_counts[incident_type] += 1 incident_counts[incident_type] += 1
self._previous_incidents.add(incident.get('id'))
self._attributes = {ATTR_ATTRIBUTION: brottsplatskartan.ATTRIBUTION}
self._attributes.update(incident_counts) self._attributes.update(incident_counts)
self._state = len(incidents) self._state = len(incidents)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment