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 varspull/18185/head
parent
5418e0510d
commit
42cb23f768
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue