From 9eac11dcbecc2fd1d38a55c2195bb14b4d58f053 Mon Sep 17 00:00:00 2001 From: Jorim Tielemans Date: Mon, 12 Nov 2018 11:26:05 +0100 Subject: [PATCH] Filter Coinbase account wallets (#18167) Only add sensor entities for accounts with the specified currencies. This is a none breaking change. If it's not specified then all account wallets will be loaded. --- homeassistant/components/coinbase.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/coinbase.py b/homeassistant/components/coinbase.py index 154320b4abd..98c321b9f5a 100644 --- a/homeassistant/components/coinbase.py +++ b/homeassistant/components/coinbase.py @@ -21,6 +21,7 @@ _LOGGER = logging.getLogger(__name__) DOMAIN = 'coinbase' CONF_API_SECRET = 'api_secret' +CONF_ACCOUNT_CURRENCIES = 'account_balance_currencies' CONF_EXCHANGE_CURRENCIES = 'exchange_rate_currencies' MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=1) @@ -31,6 +32,8 @@ CONFIG_SCHEMA = vol.Schema({ DOMAIN: vol.Schema({ vol.Required(CONF_API_KEY): cv.string, vol.Required(CONF_API_SECRET): cv.string, + vol.Optional(CONF_ACCOUNT_CURRENCIES): + vol.All(cv.ensure_list, [cv.string]), vol.Optional(CONF_EXCHANGE_CURRENCIES, default=[]): vol.All(cv.ensure_list, [cv.string]) }) @@ -45,6 +48,7 @@ def setup(hass, config): """ api_key = config[DOMAIN].get(CONF_API_KEY) api_secret = config[DOMAIN].get(CONF_API_SECRET) + account_currencies = config[DOMAIN].get(CONF_ACCOUNT_CURRENCIES) exchange_currencies = config[DOMAIN].get(CONF_EXCHANGE_CURRENCIES) hass.data[DATA_COINBASE] = coinbase_data = CoinbaseData( @@ -53,7 +57,13 @@ def setup(hass, config): if not hasattr(coinbase_data, 'accounts'): return False for account in coinbase_data.accounts.data: - load_platform(hass, 'sensor', DOMAIN, {'account': account}, config) + if (account_currencies is None or + account.currency in account_currencies): + load_platform(hass, + 'sensor', + DOMAIN, + {'account': account}, + config) for currency in exchange_currencies: if currency not in coinbase_data.exchange_rates.rates: _LOGGER.warning("Currency %s not found", currency)