diff --git a/homeassistant/components/sensor/brottsplatskartan.py b/homeassistant/components/sensor/brottsplatskartan.py index dc338e6b84a00994756cc6ffa30607d1a9a03323..c308f2eac53d63bfc7b90064097b22710fc3c720 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)