From a1beede64c9f92438aaa146604d7f3eb7ecd6450 Mon Sep 17 00:00:00 2001 From: Jorim Tielemans Date: Sat, 3 Nov 2018 23:56:36 +0100 Subject: [PATCH 1/3] Add extra icons and don't rely on the name --- homeassistant/components/sensor/coinbase.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/sensor/coinbase.py b/homeassistant/components/sensor/coinbase.py index 40444dee93c076..857d81239a77d5 100644 --- a/homeassistant/components/sensor/coinbase.py +++ b/homeassistant/components/sensor/coinbase.py @@ -10,7 +10,10 @@ ATTR_NATIVE_BALANCE = "Balance in native currency" BTC_ICON = 'mdi:currency-btc' - +ETH_ICON = 'mdi:currency-eth' +EUR_ICON = 'mdi:currency-eur' +LTC_ICON = 'mdi:litecoin' +USD_ICON = 'mdi:currency-usd' COIN_ICON = 'mdi:coin' CONF_ATTRIBUTION = "Data provided by coinbase.com" @@ -18,8 +21,6 @@ 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,9 +69,9 @@ def unit_of_measurement(self): @property def icon(self): """Return the icon to use in the frontend, if any.""" - if self._name == "Coinbase BTC Wallet": + if self._unit_of_measurement == "BTC": return BTC_ICON - if self._name == "Coinbase ETH Wallet": + if self._unit_of_measurement == "ETH": return ETH_ICON return COIN_ICON @@ -122,9 +123,9 @@ def unit_of_measurement(self): @property def icon(self): """Return the icon to use in the frontend, if any.""" - if self._name == "BTC Exchange Rate": + if self.currency == "BTC": return BTC_ICON - if self._name == "ETH Exchange Rate": + if self.currency == "ETH": return ETH_ICON return COIN_ICON From caec2a9c7a8d4872cc705bfd1e2ca824360ce00c Mon Sep 17 00:00:00 2001 From: Jorim Tielemans Date: Sat, 3 Nov 2018 23:58:25 +0100 Subject: [PATCH 2/3] Use dictionary for icons use safe get() with default value --- homeassistant/components/sensor/coinbase.py | 24 ++++++++------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/sensor/coinbase.py b/homeassistant/components/sensor/coinbase.py index 857d81239a77d5..a18a79b57ef059 100644 --- a/homeassistant/components/sensor/coinbase.py +++ b/homeassistant/components/sensor/coinbase.py @@ -9,11 +9,13 @@ ATTR_NATIVE_BALANCE = "Balance in native currency" -BTC_ICON = 'mdi:currency-btc' -ETH_ICON = 'mdi:currency-eth' -EUR_ICON = 'mdi:currency-eur' -LTC_ICON = 'mdi:litecoin' -USD_ICON = 'mdi:currency-usd' +icons = { + 'BTC': 'mdi:currency-btc', + 'ETH': 'mdi:currency-eth', + 'EUR': 'mdi:currency-eur', + 'LTC': 'mdi:litecoin', + 'USD': 'mdi:currency-usd' +} COIN_ICON = 'mdi:coin' CONF_ATTRIBUTION = "Data provided by coinbase.com" @@ -69,11 +71,7 @@ def unit_of_measurement(self): @property def icon(self): """Return the icon to use in the frontend, if any.""" - if self._unit_of_measurement == "BTC": - return BTC_ICON - if self._unit_of_measurement == "ETH": - return ETH_ICON - return COIN_ICON + return icons.get(self._unit_of_measurement, COIN_ICON) @property def device_state_attributes(self): @@ -123,11 +121,7 @@ def unit_of_measurement(self): @property def icon(self): """Return the icon to use in the frontend, if any.""" - if self.currency == "BTC": - return BTC_ICON - if self.currency == "ETH": - return ETH_ICON - return COIN_ICON + return icons.get(self.currency, COIN_ICON) @property def device_state_attributes(self): From b115e419247b6ea5656957587985ec94ae124761 Mon Sep 17 00:00:00 2001 From: Jorim Tielemans Date: Sun, 4 Nov 2018 00:10:56 +0100 Subject: [PATCH 3/3] Use better vars --- homeassistant/components/sensor/coinbase.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/sensor/coinbase.py b/homeassistant/components/sensor/coinbase.py index a18a79b57ef059..d25b7b786f8a57 100644 --- a/homeassistant/components/sensor/coinbase.py +++ b/homeassistant/components/sensor/coinbase.py @@ -9,14 +9,14 @@ ATTR_NATIVE_BALANCE = "Balance in native currency" -icons = { +CURRENCY_ICONS = { 'BTC': 'mdi:currency-btc', 'ETH': 'mdi:currency-eth', 'EUR': 'mdi:currency-eur', 'LTC': 'mdi:litecoin', 'USD': 'mdi:currency-usd' } -COIN_ICON = 'mdi:coin' +DEFAULT_COIN_ICON = 'mdi:coin' CONF_ATTRIBUTION = "Data provided by coinbase.com" @@ -71,7 +71,7 @@ def unit_of_measurement(self): @property def icon(self): """Return the icon to use in the frontend, if any.""" - return icons.get(self._unit_of_measurement, COIN_ICON) + return CURRENCY_ICONS.get(self._unit_of_measurement, DEFAULT_COIN_ICON) @property def device_state_attributes(self): @@ -121,7 +121,7 @@ def unit_of_measurement(self): @property def icon(self): """Return the icon to use in the frontend, if any.""" - return icons.get(self.currency, COIN_ICON) + return CURRENCY_ICONS.get(self.currency, DEFAULT_COIN_ICON) @property def device_state_attributes(self):