From b7b62a90e209328e1c79fa3937de30cf23a48dea Mon Sep 17 00:00:00 2001 From: Rohan Kapoor Date: Thu, 25 Oct 2018 23:29:41 -0700 Subject: [PATCH] Delete sensor.yahoo_finance (#17805) --- .../components/sensor/yahoo_finance.py | 127 ------------------ requirements_all.txt | 3 - requirements_test_all.txt | 3 - script/gen_requirements_all.py | 1 - tests/components/sensor/test_yahoo_finance.py | 44 ------ 5 files changed, 178 deletions(-) delete mode 100644 homeassistant/components/sensor/yahoo_finance.py delete mode 100644 tests/components/sensor/test_yahoo_finance.py diff --git a/homeassistant/components/sensor/yahoo_finance.py b/homeassistant/components/sensor/yahoo_finance.py deleted file mode 100644 index 4358dba2b25..00000000000 --- a/homeassistant/components/sensor/yahoo_finance.py +++ /dev/null @@ -1,127 +0,0 @@ -""" -Currency exchange rate support that comes from Yahoo Finance. - -For more details about this platform, please refer to the documentation at -https://home-assistant.io/components/sensor.yahoo_finance/ -""" -import logging -from datetime import timedelta - -import voluptuous as vol - -import homeassistant.helpers.config_validation as cv -from homeassistant.components.sensor import PLATFORM_SCHEMA -from homeassistant.const import ATTR_ATTRIBUTION -from homeassistant.helpers.entity import Entity - -REQUIREMENTS = ['yahoo-finance==1.4.0'] - -_LOGGER = logging.getLogger(__name__) - -ATTR_CHANGE = 'Change' -ATTR_OPEN = 'open' -ATTR_PREV_CLOSE = 'prev_close' - -CONF_ATTRIBUTION = "Stock market information provided by Yahoo! Inc." -CONF_SYMBOLS = 'symbols' - -DEFAULT_NAME = 'Yahoo Stock' -DEFAULT_SYMBOL = 'YHOO' - -ICON = 'mdi:currency-usd' - -SCAN_INTERVAL = timedelta(minutes=5) - -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ - vol.Optional(CONF_SYMBOLS, default=[DEFAULT_SYMBOL]): - vol.All(cv.ensure_list, [cv.string]), -}) - - -def setup_platform(hass, config, add_entities, discovery_info=None): - """Set up the Yahoo Finance sensor.""" - from yahoo_finance import Share - - symbols = config.get(CONF_SYMBOLS) - - dev = [] - for symbol in symbols: - if Share(symbol).get_price() is None: - _LOGGER.warning("Symbol %s unknown", symbol) - break - data = YahooFinanceData(symbol) - dev.append(YahooFinanceSensor(data, symbol)) - - add_entities(dev, True) - - -class YahooFinanceSensor(Entity): - """Representation of a Yahoo Finance sensor.""" - - def __init__(self, data, symbol): - """Initialize the sensor.""" - self._name = symbol - self.data = data - self._symbol = symbol - self._state = None - self._unit_of_measurement = None - - @property - def name(self): - """Return the name of the sensor.""" - return self._name - - @property - def unit_of_measurement(self): - """Return the unit of measurement of this entity, if any.""" - return self._symbol - - @property - def state(self): - """Return the state of the sensor.""" - return self._state - - @property - def device_state_attributes(self): - """Return the state attributes.""" - if self._state is not None: - return { - ATTR_ATTRIBUTION: CONF_ATTRIBUTION, - ATTR_CHANGE: self.data.price_change, - ATTR_OPEN: self.data.price_open, - ATTR_PREV_CLOSE: self.data.prev_close, - } - - @property - def icon(self): - """Return the icon to use in the frontend, if any.""" - return ICON - - def update(self): - """Get the latest data and updates the states.""" - _LOGGER.debug("Updating sensor %s - %s", self._name, self._state) - self.data.update() - self._state = self.data.state - - -class YahooFinanceData: - """Get data from Yahoo Finance.""" - - def __init__(self, symbol): - """Initialize the data object.""" - from yahoo_finance import Share - - self._symbol = symbol - self.state = None - self.price_change = None - self.price_open = None - self.prev_close = None - self.stock = Share(self._symbol) - - def update(self): - """Get the latest data and updates the states.""" - self.stock.refresh() - self.state = self.stock.get_price() - self.price_change = self.stock.get_change() - self.price_open = self.stock.get_open() - self.prev_close = self.stock.get_prev_close() diff --git a/requirements_all.txt b/requirements_all.txt index 1fe3ce3372f..b1443a7815a 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1567,9 +1567,6 @@ xknx==0.8.5 # homeassistant.components.sensor.zestimate xmltodict==0.11.0 -# homeassistant.components.sensor.yahoo_finance -yahoo-finance==1.4.0 - # homeassistant.components.sensor.yweather # homeassistant.components.weather.yweather yahooweather==0.10 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index e81e8664856..09e4c765fd3 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -254,6 +254,3 @@ wakeonlan==1.1.6 # homeassistant.components.cloud warrant==0.6.1 - -# homeassistant.components.sensor.yahoo_finance -yahoo-finance==1.4.0 diff --git a/script/gen_requirements_all.py b/script/gen_requirements_all.py index 945bc60b4ea..97711b5e893 100755 --- a/script/gen_requirements_all.py +++ b/script/gen_requirements_all.py @@ -106,7 +106,6 @@ TEST_REQUIREMENTS = ( 'statsd', 'uvcclient', 'warrant', - 'yahoo-finance', 'pythonwhois', 'wakeonlan', 'vultr', diff --git a/tests/components/sensor/test_yahoo_finance.py b/tests/components/sensor/test_yahoo_finance.py deleted file mode 100644 index d442b9c9b22..00000000000 --- a/tests/components/sensor/test_yahoo_finance.py +++ /dev/null @@ -1,44 +0,0 @@ -"""The tests for the Yahoo Finance platform.""" -import json - -import unittest -from unittest.mock import patch - -import homeassistant.components.sensor as sensor -from homeassistant.setup import setup_component -from tests.common import ( - get_test_home_assistant, load_fixture, assert_setup_component) - -VALID_CONFIG = { - 'platform': 'yahoo_finance', - 'symbols': [ - 'YHOO', - ] -} - - -# pylint: disable=invalid-name -class TestYahooFinanceSetup(unittest.TestCase): - """Test the Yahoo Finance platform.""" - - def setUp(self): - """Initialize values for this testcase class.""" - self.hass = get_test_home_assistant() - self.config = VALID_CONFIG - - def tearDown(self): - """Stop everything that was started.""" - self.hass.stop() - - @patch('yahoo_finance.Base._request', - return_value=json.loads(load_fixture('yahoo_finance.json'))) - def test_default_setup(self, mock_request): - """Test the default setup.""" - with assert_setup_component(1, sensor.DOMAIN): - assert setup_component(self.hass, sensor.DOMAIN, { - 'sensor': VALID_CONFIG}) - - state = self.hass.states.get('sensor.yhoo') - assert '41.69' == state.attributes.get('open') - assert '41.79' == state.attributes.get('prev_close') - assert 'YHOO' == state.attributes.get('unit_of_measurement')