Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions homeassistant/components/sensor/alpha_vantage.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,13 @@
CONF_SYMBOLS = 'symbols'
CONF_TO = 'to'

DEFAULT_SYMBOL = {
CONF_CURRENCY: 'USD',
CONF_NAME: 'Google',
CONF_SYMBOL: 'GOOGL',
}

DEFAULT_CURRENCY = {
CONF_FROM: 'BTC',
CONF_NAME: 'Bitcon',
CONF_TO: 'USD',
}

ICONS = {
Copy link
Copy Markdown
Member

@OttoWinter OttoWinter Feb 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly unrelated, but why is there a space in 'TRY': 'mdi: currency-try', (after mdi:)... 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

'BTC': 'mdi:currency-btc',
'EUR': 'mdi:currency-eur',
'GBP': 'mdi:currency-gbp',
'INR': 'mdi:currency-inr',
'RUB': 'mdi:currency-rub',
'TRY': 'mdi: currency-try',
'TRY': 'mdi:currency-try',
'USD': 'mdi:currency-usd',
}

Expand All @@ -69,9 +57,9 @@

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_API_KEY): cv.string,
vol.Optional(CONF_FOREIGN_EXCHANGE, default=[DEFAULT_CURRENCY]):
vol.Optional(CONF_FOREIGN_EXCHANGE):
vol.All(cv.ensure_list, [CURRENCY_SCHEMA]),
vol.Optional(CONF_SYMBOLS, default=[DEFAULT_SYMBOL]):
vol.Optional(CONF_SYMBOLS):
vol.All(cv.ensure_list, [SYMBOL_SCHEMA]),
})

Expand All @@ -83,6 +71,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None):

api_key = config.get(CONF_API_KEY)
symbols = config.get(CONF_SYMBOLS)
conversions = config.get(CONF_FOREIGN_EXCHANGE)

if not symbols and not conversions:
msg = 'Warning: No symbols or currencies configured.'
hass.components.persistent_notification.create(
msg, 'Sensor alpha_vantage')
_LOGGER.warning(msg)
return

timeseries = TimeSeries(key=api_key)

Expand All @@ -98,7 +94,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
dev.append(AlphaVantageSensor(timeseries, symbol))

forex = ForeignExchange(key=api_key)
for conversion in config.get(CONF_FOREIGN_EXCHANGE):
for conversion in conversions:
from_cur = conversion.get(CONF_FROM)
to_cur = conversion.get(CONF_TO)
try:
Expand Down