mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Delete sensor.yahoo_finance (#17805)
This commit is contained in:
parent
901c4f18cb
commit
b7b62a90e2
@ -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()
|
|
@ -1567,9 +1567,6 @@ xknx==0.8.5
|
|||||||
# homeassistant.components.sensor.zestimate
|
# homeassistant.components.sensor.zestimate
|
||||||
xmltodict==0.11.0
|
xmltodict==0.11.0
|
||||||
|
|
||||||
# homeassistant.components.sensor.yahoo_finance
|
|
||||||
yahoo-finance==1.4.0
|
|
||||||
|
|
||||||
# homeassistant.components.sensor.yweather
|
# homeassistant.components.sensor.yweather
|
||||||
# homeassistant.components.weather.yweather
|
# homeassistant.components.weather.yweather
|
||||||
yahooweather==0.10
|
yahooweather==0.10
|
||||||
|
@ -254,6 +254,3 @@ wakeonlan==1.1.6
|
|||||||
|
|
||||||
# homeassistant.components.cloud
|
# homeassistant.components.cloud
|
||||||
warrant==0.6.1
|
warrant==0.6.1
|
||||||
|
|
||||||
# homeassistant.components.sensor.yahoo_finance
|
|
||||||
yahoo-finance==1.4.0
|
|
||||||
|
@ -106,7 +106,6 @@ TEST_REQUIREMENTS = (
|
|||||||
'statsd',
|
'statsd',
|
||||||
'uvcclient',
|
'uvcclient',
|
||||||
'warrant',
|
'warrant',
|
||||||
'yahoo-finance',
|
|
||||||
'pythonwhois',
|
'pythonwhois',
|
||||||
'wakeonlan',
|
'wakeonlan',
|
||||||
'vultr',
|
'vultr',
|
||||||
|
@ -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')
|
|
Loading…
x
Reference in New Issue
Block a user