1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00
This commit is contained in:
Paulus Schoutsen
2019-07-31 12:25:30 -07:00
parent da05dfe708
commit 4de97abc3a
2676 changed files with 163166 additions and 140084 deletions

View File

@@ -5,8 +5,7 @@ from datetime import timedelta
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import (
CONF_DISPLAY_OPTIONS, ATTR_ATTRIBUTION, CONF_CURRENCY)
from homeassistant.const import CONF_DISPLAY_OPTIONS, ATTR_ATTRIBUTION, CONF_CURRENCY
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
@@ -14,41 +13,44 @@ _LOGGER = logging.getLogger(__name__)
ATTRIBUTION = "Data provided by blockchain.info"
DEFAULT_CURRENCY = 'USD'
DEFAULT_CURRENCY = "USD"
ICON = 'mdi:currency-btc'
ICON = "mdi:currency-btc"
SCAN_INTERVAL = timedelta(minutes=5)
OPTION_TYPES = {
'exchangerate': ['Exchange rate (1 BTC)', None],
'trade_volume_btc': ['Trade volume', 'BTC'],
'miners_revenue_usd': ['Miners revenue', 'USD'],
'btc_mined': ['Mined', 'BTC'],
'trade_volume_usd': ['Trade volume', 'USD'],
'difficulty': ['Difficulty', None],
'minutes_between_blocks': ['Time between Blocks', 'min'],
'number_of_transactions': ['No. of Transactions', None],
'hash_rate': ['Hash rate', 'PH/s'],
'timestamp': ['Timestamp', None],
'mined_blocks': ['Mined Blocks', None],
'blocks_size': ['Block size', None],
'total_fees_btc': ['Total fees', 'BTC'],
'total_btc_sent': ['Total sent', 'BTC'],
'estimated_btc_sent': ['Estimated sent', 'BTC'],
'total_btc': ['Total', 'BTC'],
'total_blocks': ['Total Blocks', None],
'next_retarget': ['Next retarget', None],
'estimated_transaction_volume_usd': ['Est. Transaction volume', 'USD'],
'miners_revenue_btc': ['Miners revenue', 'BTC'],
'market_price_usd': ['Market price', 'USD']
"exchangerate": ["Exchange rate (1 BTC)", None],
"trade_volume_btc": ["Trade volume", "BTC"],
"miners_revenue_usd": ["Miners revenue", "USD"],
"btc_mined": ["Mined", "BTC"],
"trade_volume_usd": ["Trade volume", "USD"],
"difficulty": ["Difficulty", None],
"minutes_between_blocks": ["Time between Blocks", "min"],
"number_of_transactions": ["No. of Transactions", None],
"hash_rate": ["Hash rate", "PH/s"],
"timestamp": ["Timestamp", None],
"mined_blocks": ["Mined Blocks", None],
"blocks_size": ["Block size", None],
"total_fees_btc": ["Total fees", "BTC"],
"total_btc_sent": ["Total sent", "BTC"],
"estimated_btc_sent": ["Estimated sent", "BTC"],
"total_btc": ["Total", "BTC"],
"total_blocks": ["Total Blocks", None],
"next_retarget": ["Next retarget", None],
"estimated_transaction_volume_usd": ["Est. Transaction volume", "USD"],
"miners_revenue_btc": ["Miners revenue", "BTC"],
"market_price_usd": ["Market price", "USD"],
}
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_DISPLAY_OPTIONS, default=[]):
vol.All(cv.ensure_list, [vol.In(OPTION_TYPES)]),
vol.Optional(CONF_CURRENCY, default=DEFAULT_CURRENCY): cv.string,
})
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_DISPLAY_OPTIONS, default=[]): vol.All(
cv.ensure_list, [vol.In(OPTION_TYPES)]
),
vol.Optional(CONF_CURRENCY, default=DEFAULT_CURRENCY): cv.string,
}
)
def setup_platform(hass, config, add_entities, discovery_info=None):
@@ -104,9 +106,7 @@ class BitcoinSensor(Entity):
@property
def device_state_attributes(self):
"""Return the state attributes of the sensor."""
return {
ATTR_ATTRIBUTION: ATTRIBUTION,
}
return {ATTR_ATTRIBUTION: ATTRIBUTION}
def update(self):
"""Get the latest data and updates the states."""
@@ -114,52 +114,49 @@ class BitcoinSensor(Entity):
stats = self.data.stats
ticker = self.data.ticker
if self.type == 'exchangerate':
if self.type == "exchangerate":
self._state = ticker[self._currency].p15min
self._unit_of_measurement = self._currency
elif self.type == 'trade_volume_btc':
self._state = '{0:.1f}'.format(stats.trade_volume_btc)
elif self.type == 'miners_revenue_usd':
self._state = '{0:.0f}'.format(stats.miners_revenue_usd)
elif self.type == 'btc_mined':
self._state = '{}'.format(stats.btc_mined * 0.00000001)
elif self.type == 'trade_volume_usd':
self._state = '{0:.1f}'.format(stats.trade_volume_usd)
elif self.type == 'difficulty':
self._state = '{0:.0f}'.format(stats.difficulty)
elif self.type == 'minutes_between_blocks':
self._state = '{0:.2f}'.format(stats.minutes_between_blocks)
elif self.type == 'number_of_transactions':
self._state = '{}'.format(stats.number_of_transactions)
elif self.type == 'hash_rate':
self._state = '{0:.1f}'.format(stats.hash_rate * 0.000001)
elif self.type == 'timestamp':
elif self.type == "trade_volume_btc":
self._state = "{0:.1f}".format(stats.trade_volume_btc)
elif self.type == "miners_revenue_usd":
self._state = "{0:.0f}".format(stats.miners_revenue_usd)
elif self.type == "btc_mined":
self._state = "{}".format(stats.btc_mined * 0.00000001)
elif self.type == "trade_volume_usd":
self._state = "{0:.1f}".format(stats.trade_volume_usd)
elif self.type == "difficulty":
self._state = "{0:.0f}".format(stats.difficulty)
elif self.type == "minutes_between_blocks":
self._state = "{0:.2f}".format(stats.minutes_between_blocks)
elif self.type == "number_of_transactions":
self._state = "{}".format(stats.number_of_transactions)
elif self.type == "hash_rate":
self._state = "{0:.1f}".format(stats.hash_rate * 0.000001)
elif self.type == "timestamp":
self._state = stats.timestamp
elif self.type == 'mined_blocks':
self._state = '{}'.format(stats.mined_blocks)
elif self.type == 'blocks_size':
self._state = '{0:.1f}'.format(stats.blocks_size)
elif self.type == 'total_fees_btc':
self._state = '{0:.2f}'.format(stats.total_fees_btc * 0.00000001)
elif self.type == 'total_btc_sent':
self._state = '{0:.2f}'.format(stats.total_btc_sent * 0.00000001)
elif self.type == 'estimated_btc_sent':
self._state = '{0:.2f}'.format(
stats.estimated_btc_sent * 0.00000001)
elif self.type == 'total_btc':
self._state = '{0:.2f}'.format(stats.total_btc * 0.00000001)
elif self.type == 'total_blocks':
self._state = '{0:.2f}'.format(stats.total_blocks)
elif self.type == 'next_retarget':
self._state = '{0:.2f}'.format(stats.next_retarget)
elif self.type == 'estimated_transaction_volume_usd':
self._state = '{0:.2f}'.format(
stats.estimated_transaction_volume_usd)
elif self.type == 'miners_revenue_btc':
self._state = '{0:.1f}'.format(
stats.miners_revenue_btc * 0.00000001)
elif self.type == 'market_price_usd':
self._state = '{0:.2f}'.format(stats.market_price_usd)
elif self.type == "mined_blocks":
self._state = "{}".format(stats.mined_blocks)
elif self.type == "blocks_size":
self._state = "{0:.1f}".format(stats.blocks_size)
elif self.type == "total_fees_btc":
self._state = "{0:.2f}".format(stats.total_fees_btc * 0.00000001)
elif self.type == "total_btc_sent":
self._state = "{0:.2f}".format(stats.total_btc_sent * 0.00000001)
elif self.type == "estimated_btc_sent":
self._state = "{0:.2f}".format(stats.estimated_btc_sent * 0.00000001)
elif self.type == "total_btc":
self._state = "{0:.2f}".format(stats.total_btc * 0.00000001)
elif self.type == "total_blocks":
self._state = "{0:.2f}".format(stats.total_blocks)
elif self.type == "next_retarget":
self._state = "{0:.2f}".format(stats.next_retarget)
elif self.type == "estimated_transaction_volume_usd":
self._state = "{0:.2f}".format(stats.estimated_transaction_volume_usd)
elif self.type == "miners_revenue_btc":
self._state = "{0:.1f}".format(stats.miners_revenue_btc * 0.00000001)
elif self.type == "market_price_usd":
self._state = "{0:.2f}".format(stats.market_price_usd)
class BitcoinData: