From 717f4e69d5842c3f61bb3a2e97154f472a4d8b5d Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 9 May 2021 22:23:52 +0200 Subject: [PATCH] Remove defunct Spot Crime integration (#50361) --- .coveragerc | 1 - .../components/spotcrime/__init__.py | 1 - .../components/spotcrime/manifest.json | 8 - homeassistant/components/spotcrime/sensor.py | 140 ------------------ requirements_all.txt | 3 - 5 files changed, 153 deletions(-) delete mode 100644 homeassistant/components/spotcrime/__init__.py delete mode 100644 homeassistant/components/spotcrime/manifest.json delete mode 100644 homeassistant/components/spotcrime/sensor.py diff --git a/.coveragerc b/.coveragerc index 95d699be69f..923642733d4 100644 --- a/.coveragerc +++ b/.coveragerc @@ -942,7 +942,6 @@ omit = homeassistant/components/speedtestdotnet/* homeassistant/components/spider/* homeassistant/components/splunk/* - homeassistant/components/spotcrime/sensor.py homeassistant/components/spotify/__init__.py homeassistant/components/spotify/media_player.py homeassistant/components/spotify/system_health.py diff --git a/homeassistant/components/spotcrime/__init__.py b/homeassistant/components/spotcrime/__init__.py deleted file mode 100644 index 26bb50b8b02..00000000000 --- a/homeassistant/components/spotcrime/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""The spotcrime component.""" diff --git a/homeassistant/components/spotcrime/manifest.json b/homeassistant/components/spotcrime/manifest.json deleted file mode 100644 index a668454469d..00000000000 --- a/homeassistant/components/spotcrime/manifest.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "domain": "spotcrime", - "name": "Spot Crime", - "documentation": "https://www.home-assistant.io/integrations/spotcrime", - "requirements": ["spotcrime==1.0.4"], - "codeowners": [], - "iot_class": "cloud_polling" -} diff --git a/homeassistant/components/spotcrime/sensor.py b/homeassistant/components/spotcrime/sensor.py deleted file mode 100644 index 72a6fec84e9..00000000000 --- a/homeassistant/components/spotcrime/sensor.py +++ /dev/null @@ -1,140 +0,0 @@ -"""Sensor for Spot Crime.""" - -from collections import defaultdict -from datetime import timedelta - -import spotcrime -import voluptuous as vol - -from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity -from homeassistant.const import ( - ATTR_ATTRIBUTION, - ATTR_LATITUDE, - ATTR_LONGITUDE, - CONF_API_KEY, - CONF_EXCLUDE, - CONF_INCLUDE, - CONF_LATITUDE, - CONF_LONGITUDE, - CONF_NAME, - CONF_RADIUS, -) -import homeassistant.helpers.config_validation as cv -from homeassistant.util import slugify - -CONF_DAYS = "days" -DEFAULT_DAYS = 1 -NAME = "spotcrime" - -EVENT_INCIDENT = f"{NAME}_incident" - -SCAN_INTERVAL = timedelta(minutes=30) - -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - { - vol.Required(CONF_NAME): cv.string, - vol.Required(CONF_RADIUS): vol.Coerce(float), - vol.Required(CONF_API_KEY): cv.string, - vol.Inclusive(CONF_LATITUDE, "coordinates"): cv.latitude, - vol.Inclusive(CONF_LONGITUDE, "coordinates"): cv.longitude, - vol.Optional(CONF_DAYS, default=DEFAULT_DAYS): cv.positive_int, - vol.Optional(CONF_INCLUDE): vol.All(cv.ensure_list, [cv.string]), - vol.Optional(CONF_EXCLUDE): vol.All(cv.ensure_list, [cv.string]), - } -) - - -def setup_platform(hass, config, add_entities, discovery_info=None): - """Set up the Crime Reports platform.""" - latitude = config.get(CONF_LATITUDE, hass.config.latitude) - longitude = config.get(CONF_LONGITUDE, hass.config.longitude) - name = config[CONF_NAME] - radius = config[CONF_RADIUS] - api_key = config[CONF_API_KEY] - days = config.get(CONF_DAYS) - include = config.get(CONF_INCLUDE) - exclude = config.get(CONF_EXCLUDE) - - add_entities( - [ - SpotCrimeSensor( - name, latitude, longitude, radius, include, exclude, api_key, days - ) - ], - True, - ) - - -class SpotCrimeSensor(SensorEntity): - """Representation of a Spot Crime Sensor.""" - - def __init__( - self, name, latitude, longitude, radius, include, exclude, api_key, days - ): - """Initialize the Spot Crime sensor.""" - - self._name = name - self._include = include - self._exclude = exclude - self.api_key = api_key - self.days = days - self._spotcrime = spotcrime.SpotCrime( - (latitude, longitude), - radius, - self._include, - self._exclude, - self.api_key, - self.days, - ) - self._attributes = None - self._state = None - self._previous_incidents = set() - self._attributes = {ATTR_ATTRIBUTION: spotcrime.ATTRIBUTION} - - @property - def name(self): - """Return the name of the sensor.""" - return self._name - - @property - def state(self): - """Return the state of the sensor.""" - return self._state - - @property - def extra_state_attributes(self): - """Return the state attributes.""" - return self._attributes - - def _incident_event(self, incident): - data = { - "type": incident.get("type"), - "timestamp": incident.get("timestamp"), - "address": incident.get("location"), - } - if incident.get("coordinates"): - data.update( - { - ATTR_LATITUDE: incident.get("lat"), - ATTR_LONGITUDE: incident.get("lon"), - } - ) - self.hass.bus.fire(EVENT_INCIDENT, data) - - def update(self): - """Update device state.""" - incident_counts = defaultdict(int) - incidents = self._spotcrime.get_incidents() - if len(incidents) < len(self._previous_incidents): - self._previous_incidents = set() - for incident in incidents: - incident_type = slugify(incident.get("type")) - incident_counts[incident_type] += 1 - if ( - self._previous_incidents - and incident.get("id") not in self._previous_incidents - ): - self._incident_event(incident) - self._previous_incidents.add(incident.get("id")) - self._attributes.update(incident_counts) - self._state = len(incidents) diff --git a/requirements_all.txt b/requirements_all.txt index 2fcec0aa9c5..4363cc8956c 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2134,9 +2134,6 @@ speedtest-cli==2.1.3 # homeassistant.components.spider spiderpy==1.4.2 -# homeassistant.components.spotcrime -spotcrime==1.0.4 - # homeassistant.components.spotify spotipy==2.18.0