Add display currency setting to CoinMarketCap sensor (#10093)
* Add support for different display currencies in CoinMarkerCap sensor. * Add test for CoinMarketCap sensor. * Add test dependency to gen_requirements_all. * Fix review comments: use string formatting and less string case chanes.
This commit is contained in:
1 parent
2561efe45d
commit
c2ef22bd08
7 files changed
+98
-15
No files matched your search
@@ -0,0 +1,44 @@
|
||||
"""Tests for the CoinMarketCap sensor platform."""
|
||||
import json
|
||||
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
import homeassistant.components.sensor as sensor
|
||||
from homeassistant.setup import setup_component
|
||||
from tests.common import (
|
||||
get_test_home_assistant, load_fixture, assert_setup_component)
|
||||
|
||||
VALID_CONFIG = {
|
||||
'platform': 'coinmarketcap',
|
||||
'currency': 'ethereum',
|
||||
'display_currency': 'EUR',
|
||||
}
|
||||
|
||||
|
||||
class TestCoinMarketCapSensor(unittest.TestCase):
|
||||
"""Test the CoinMarketCap sensor."""
|
||||
|
||||
def setUp(self):
|
||||
"""Set up things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
self.config = VALID_CONFIG
|
||||
|
||||
def tearDown(self):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
@patch('coinmarketcap.Market.ticker',
|
||||
return_value=json.loads(load_fixture('coinmarketcap.json')))
|
||||
def test_setup(self, mock_request):
|
||||
"""Test the setup with custom settings."""
|
||||
with assert_setup_component(1, sensor.DOMAIN):
|
||||
assert setup_component(self.hass, sensor.DOMAIN, {
|
||||
'sensor': VALID_CONFIG})
|
||||
|
||||
state = self.hass.states.get('sensor.ethereum')
|
||||
assert state is not None
|
||||
|
||||
assert state.state == '240.47'
|
||||
assert state.attributes.get('symbol') == 'ETH'
|
||||
assert state.attributes.get('unit_of_measurement') == 'EUR'
|
||||
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
[
|
||||
{
|
||||
"id": "ethereum",
|
||||
"name": "Ethereum",
|
||||
"symbol": "ETH",
|
||||
"rank": "2",
|
||||
"price_usd": "282.423",
|
||||
"price_btc": "0.048844",
|
||||
"24h_volume_usd": "407024000.0",
|
||||
"market_cap_usd": "26908205315.0",
|
||||
"available_supply": "95276253.0",
|
||||
"total_supply": "95276253.0",
|
||||
"percent_change_1h": "0.06",
|
||||
"percent_change_24h": "-4.57",
|
||||
"percent_change_7d": "-16.39",
|
||||
"last_updated": "1508776751",
|
||||
"price_eur": "240.473299695",
|
||||
"24h_volume_eur": "346566690.16",
|
||||
"market_cap_eur": "22911395039.0"
|
||||
}
|
||||
]
|
||||
Reference in new issue
Block a user