From 42cb23f7686e537e83b2539d92989c2198088162 Mon Sep 17 00:00:00 2001 From: Jorim Tielemans Date: Sun, 4 Nov 2018 09:50:00 +0100 Subject: [PATCH] Update Coinbase icons (#18172) * Add extra icons and don't rely on the name * Use dictionary for icons use safe get() with default value * Use better vars --- homeassistant/components/sensor/coinbase.py | 25 +++++++++------------ 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/sensor/coinbase.py b/homeassistant/components/sensor/coinbase.py index 40444dee93c..d25b7b786f8 100644 --- a/homeassistant/components/sensor/coinbase.py +++ b/homeassistant/components/sensor/coinbase.py @@ -9,17 +9,20 @@ from homeassistant.helpers.entity import Entity ATTR_NATIVE_BALANCE = "Balance in native currency" -BTC_ICON = 'mdi:currency-btc' - -COIN_ICON = 'mdi:coin' +CURRENCY_ICONS = { + 'BTC': 'mdi:currency-btc', + 'ETH': 'mdi:currency-eth', + 'EUR': 'mdi:currency-eur', + 'LTC': 'mdi:litecoin', + 'USD': 'mdi:currency-usd' +} +DEFAULT_COIN_ICON = 'mdi:coin' CONF_ATTRIBUTION = "Data provided by coinbase.com" DATA_COINBASE = 'coinbase_cache' DEPENDENCIES = ['coinbase'] -ETH_ICON = 'mdi:currency-eth' - def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Coinbase sensors.""" @@ -68,11 +71,7 @@ class AccountSensor(Entity): @property def icon(self): """Return the icon to use in the frontend, if any.""" - if self._name == "Coinbase BTC Wallet": - return BTC_ICON - if self._name == "Coinbase ETH Wallet": - return ETH_ICON - return COIN_ICON + return CURRENCY_ICONS.get(self._unit_of_measurement, DEFAULT_COIN_ICON) @property def device_state_attributes(self): @@ -122,11 +121,7 @@ class ExchangeRateSensor(Entity): @property def icon(self): """Return the icon to use in the frontend, if any.""" - if self._name == "BTC Exchange Rate": - return BTC_ICON - if self._name == "ETH Exchange Rate": - return ETH_ICON - return COIN_ICON + return CURRENCY_ICONS.get(self.currency, DEFAULT_COIN_ICON) @property def device_state_attributes(self):