Skip to content
Merged
Changes from 3 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
13 changes: 13 additions & 0 deletions homeassistant/components/sensor/alpha_vantage.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
dev = []
for symbol in symbols:
try:
_LOGGER.debug('Configuring timeseries for symbols: %s',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As per the development guidelines:

Use single quotes ' for single word and " for multiple words or sentences.

symbol[CONF_SYMBOL])
timeseries.get_intraday(symbol[CONF_SYMBOL])
except ValueError:
_LOGGER.error(
Expand All @@ -100,6 +102,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
from_cur = conversion.get(CONF_FROM)
to_cur = conversion.get(CONF_TO)
try:
_LOGGER.debug('Configuring forex %s - %s',
from_cur, to_cur)
forex.get_currency_exchange_rate(
from_currency=from_cur, to_currency=to_cur)
except ValueError as error:
Expand All @@ -110,6 +114,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
dev.append(AlphaVantageForeignExchange(forex, conversion))

add_devices(dev, True)
_LOGGER.debug('Setup completed')


class AlphaVantageSensor(Entity):
Expand Down Expand Up @@ -158,8 +163,10 @@ def icon(self):

def update(self):
"""Get the latest data and updates the states."""
_LOGGER.debug('Requesting new data for symbol %s', self._symbol)
all_values, _ = self._timeseries.get_intraday(self._symbol)
self.values = next(iter(all_values.values()))
_LOGGER.debug('Received new values for symbol %s', self._symbol)


class AlphaVantageForeignExchange(Entity):
Expand Down Expand Up @@ -210,5 +217,11 @@ def device_state_attributes(self):

def update(self):
"""Get the latest data and updates the states."""
_LOGGER.debug('Requesting new data for forex %s - %s',
self._from_currency,
self._to_currency)
self.values, _ = self._foreign_exchange.get_currency_exchange_rate(
from_currency=self._from_currency, to_currency=self._to_currency)
_LOGGER.debug('Received new data for forex %s - %s',
self._from_currency,
self._to_currency)