mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Remove defunct CoinMarketCap integration (#46615)
This commit is contained in:
parent
0bfcd5e1ee
commit
a6912277eb
@ -1 +0,0 @@
|
||||
"""The coinmarketcap component."""
|
@ -1,7 +0,0 @@
|
||||
{
|
||||
"domain": "coinmarketcap",
|
||||
"name": "CoinMarketCap",
|
||||
"documentation": "https://www.home-assistant.io/integrations/coinmarketcap",
|
||||
"requirements": ["coinmarketcap==5.0.3"],
|
||||
"codeowners": []
|
||||
}
|
@ -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)
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
"""Tests for the coinmarketcap component."""
|
@ -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"
|
Loading…
x
Reference in New Issue
Block a user