From a6912277eb014571fee3318ec96e8c4a7add831f Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Tue, 16 Feb 2021 11:00:08 +0100 Subject: [PATCH] Remove defunct CoinMarketCap integration (#46615) --- .../components/coinmarketcap/__init__.py | 1 - .../components/coinmarketcap/manifest.json | 7 - .../components/coinmarketcap/sensor.py | 164 ------------------ requirements_all.txt | 3 - requirements_test_all.txt | 3 - tests/components/coinmarketcap/__init__.py | 1 - tests/components/coinmarketcap/test_sensor.py | 42 ----- 7 files changed, 221 deletions(-) delete mode 100644 homeassistant/components/coinmarketcap/__init__.py delete mode 100644 homeassistant/components/coinmarketcap/manifest.json delete mode 100644 homeassistant/components/coinmarketcap/sensor.py delete mode 100644 tests/components/coinmarketcap/__init__.py delete mode 100644 tests/components/coinmarketcap/test_sensor.py diff --git a/homeassistant/components/coinmarketcap/__init__.py b/homeassistant/components/coinmarketcap/__init__.py deleted file mode 100644 index 0cdb5a16a4a..00000000000 --- a/homeassistant/components/coinmarketcap/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""The coinmarketcap component.""" diff --git a/homeassistant/components/coinmarketcap/manifest.json b/homeassistant/components/coinmarketcap/manifest.json deleted file mode 100644 index e3f827f2718..00000000000 --- a/homeassistant/components/coinmarketcap/manifest.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "domain": "coinmarketcap", - "name": "CoinMarketCap", - "documentation": "https://www.home-assistant.io/integrations/coinmarketcap", - "requirements": ["coinmarketcap==5.0.3"], - "codeowners": [] -} diff --git a/homeassistant/components/coinmarketcap/sensor.py b/homeassistant/components/coinmarketcap/sensor.py deleted file mode 100644 index f3fe240c0bc..00000000000 --- a/homeassistant/components/coinmarketcap/sensor.py +++ /dev/null @@ -1,164 +0,0 @@ -"""Details about crypto currencies from CoinMarketCap.""" -from datetime import timedelta -import logging -from urllib.error import HTTPError - -from coinmarketcap import Market -import voluptuous as vol - -from homeassistant.components.sensor import PLATFORM_SCHEMA -from homeassistant.const import ATTR_ATTRIBUTION, CONF_DISPLAY_CURRENCY -import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entity import Entity - -_LOGGER = logging.getLogger(__name__) - -ATTR_VOLUME_24H = "volume_24h" -ATTR_AVAILABLE_SUPPLY = "available_supply" -ATTR_CIRCULATING_SUPPLY = "circulating_supply" -ATTR_MARKET_CAP = "market_cap" -ATTR_PERCENT_CHANGE_24H = "percent_change_24h" -ATTR_PERCENT_CHANGE_7D = "percent_change_7d" -ATTR_PERCENT_CHANGE_1H = "percent_change_1h" -ATTR_PRICE = "price" -ATTR_RANK = "rank" -ATTR_SYMBOL = "symbol" -ATTR_TOTAL_SUPPLY = "total_supply" - -ATTRIBUTION = "Data provided by CoinMarketCap" - -CONF_CURRENCY_ID = "currency_id" -CONF_DISPLAY_CURRENCY_DECIMALS = "display_currency_decimals" - -DEFAULT_CURRENCY_ID = 1 -DEFAULT_DISPLAY_CURRENCY = "USD" -DEFAULT_DISPLAY_CURRENCY_DECIMALS = 2 - -ICON = "mdi:currency-usd" - -SCAN_INTERVAL = timedelta(minutes=15) - - -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( - { - vol.Optional(CONF_CURRENCY_ID, default=DEFAULT_CURRENCY_ID): cv.positive_int, - vol.Optional(CONF_DISPLAY_CURRENCY, default=DEFAULT_DISPLAY_CURRENCY): vol.All( - cv.string, vol.Upper - ), - vol.Optional( - CONF_DISPLAY_CURRENCY_DECIMALS, default=DEFAULT_DISPLAY_CURRENCY_DECIMALS - ): vol.All(vol.Coerce(int), vol.Range(min=1)), - } -) - - -def setup_platform(hass, config, add_entities, discovery_info=None): - """Set up the CoinMarketCap sensor.""" - currency_id = config[CONF_CURRENCY_ID] - display_currency = config[CONF_DISPLAY_CURRENCY] - display_currency_decimals = config[CONF_DISPLAY_CURRENCY_DECIMALS] - - try: - CoinMarketCapData(currency_id, display_currency).update() - except HTTPError: - _LOGGER.warning( - "Currency ID %s or display currency %s " - "is not available. Using 1 (bitcoin) " - "and USD", - currency_id, - display_currency, - ) - currency_id = DEFAULT_CURRENCY_ID - display_currency = DEFAULT_DISPLAY_CURRENCY - - add_entities( - [ - CoinMarketCapSensor( - CoinMarketCapData(currency_id, display_currency), - display_currency_decimals, - ) - ], - True, - ) - - -class CoinMarketCapSensor(Entity): - """Representation of a CoinMarketCap sensor.""" - - def __init__(self, data, display_currency_decimals): - """Initialize the sensor.""" - self.data = data - self.display_currency_decimals = display_currency_decimals - self._ticker = None - self._unit_of_measurement = self.data.display_currency - - @property - def name(self): - """Return the name of the sensor.""" - return self._ticker.get("name") - - @property - def state(self): - """Return the state of the sensor.""" - return round( - float( - self._ticker.get("quotes").get(self.data.display_currency).get("price") - ), - self.display_currency_decimals, - ) - - @property - def unit_of_measurement(self): - """Return the unit the value is expressed in.""" - return self._unit_of_measurement - - @property - def icon(self): - """Return the icon to use in the frontend, if any.""" - return ICON - - @property - def device_state_attributes(self): - """Return the state attributes of the sensor.""" - return { - ATTR_VOLUME_24H: self._ticker.get("quotes") - .get(self.data.display_currency) - .get("volume_24h"), - ATTR_ATTRIBUTION: ATTRIBUTION, - ATTR_CIRCULATING_SUPPLY: self._ticker.get("circulating_supply"), - ATTR_MARKET_CAP: self._ticker.get("quotes") - .get(self.data.display_currency) - .get("market_cap"), - ATTR_PERCENT_CHANGE_24H: self._ticker.get("quotes") - .get(self.data.display_currency) - .get("percent_change_24h"), - ATTR_PERCENT_CHANGE_7D: self._ticker.get("quotes") - .get(self.data.display_currency) - .get("percent_change_7d"), - ATTR_PERCENT_CHANGE_1H: self._ticker.get("quotes") - .get(self.data.display_currency) - .get("percent_change_1h"), - ATTR_RANK: self._ticker.get("rank"), - ATTR_SYMBOL: self._ticker.get("symbol"), - ATTR_TOTAL_SUPPLY: self._ticker.get("total_supply"), - } - - def update(self): - """Get the latest data and updates the states.""" - self.data.update() - self._ticker = self.data.ticker.get("data") - - -class CoinMarketCapData: - """Get the latest data and update the states.""" - - def __init__(self, currency_id, display_currency): - """Initialize the data object.""" - self.currency_id = currency_id - self.display_currency = display_currency - self.ticker = None - - def update(self): - """Get the latest data from coinmarketcap.com.""" - - self.ticker = Market().ticker(self.currency_id, convert=self.display_currency) diff --git a/requirements_all.txt b/requirements_all.txt index 640c2ace4df..6eb19726cb3 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -427,9 +427,6 @@ co2signal==0.4.2 # homeassistant.components.coinbase coinbase==2.1.0 -# homeassistant.components.coinmarketcap -coinmarketcap==5.0.3 - # homeassistant.scripts.check_config colorlog==4.7.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 6b77eaafb9d..11064b63db8 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -224,9 +224,6 @@ buienradar==1.0.4 # homeassistant.components.caldav caldav==0.7.1 -# homeassistant.components.coinmarketcap -coinmarketcap==5.0.3 - # homeassistant.scripts.check_config colorlog==4.7.2 diff --git a/tests/components/coinmarketcap/__init__.py b/tests/components/coinmarketcap/__init__.py deleted file mode 100644 index 9e9b871bbe2..00000000000 --- a/tests/components/coinmarketcap/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Tests for the coinmarketcap component.""" diff --git a/tests/components/coinmarketcap/test_sensor.py b/tests/components/coinmarketcap/test_sensor.py deleted file mode 100644 index 369a006f568..00000000000 --- a/tests/components/coinmarketcap/test_sensor.py +++ /dev/null @@ -1,42 +0,0 @@ -"""Tests for the CoinMarketCap sensor platform.""" -import json -from unittest.mock import patch - -import pytest - -from homeassistant.components.sensor import DOMAIN -from homeassistant.setup import async_setup_component - -from tests.common import assert_setup_component, load_fixture - -VALID_CONFIG = { - DOMAIN: { - "platform": "coinmarketcap", - "currency_id": 1027, - "display_currency": "EUR", - "display_currency_decimals": 3, - } -} - - -@pytest.fixture -async def setup_sensor(hass): - """Set up demo sensor component.""" - with assert_setup_component(1, DOMAIN): - with patch( - "coinmarketcap.Market.ticker", - return_value=json.loads(load_fixture("coinmarketcap.json")), - ): - await async_setup_component(hass, DOMAIN, VALID_CONFIG) - await hass.async_block_till_done() - - -async def test_setup(hass, setup_sensor): - """Test the setup with custom settings.""" - state = hass.states.get("sensor.ethereum") - assert state is not None - - assert state.name == "Ethereum" - assert state.state == "493.455" - assert state.attributes.get("symbol") == "ETH" - assert state.attributes.get("unit_of_measurement") == "EUR"