mirror of
https://github.com/home-assistant/core.git
synced 2025-06-25 01:21:51 +02:00
blockchain.info sensor (#7856)
* blockchain sensor * Update blockchain.py * Update blockchain.py * add validation of btc addresses
This commit is contained in:
committed by
Paulus Schoutsen
parent
6bfd52ada8
commit
81b1446aad
@ -372,6 +372,7 @@ omit =
|
||||
homeassistant/components/sensor/arwn.py
|
||||
homeassistant/components/sensor/bbox.py
|
||||
homeassistant/components/sensor/bitcoin.py
|
||||
homeassistant/components/sensor/blockchain.py
|
||||
homeassistant/components/sensor/bom.py
|
||||
homeassistant/components/sensor/broadlink.py
|
||||
homeassistant/components/sensor/dublin_bus_transport.py
|
||||
|
62
homeassistant/components/sensor/blockchain.py
Normal file
62
homeassistant/components/sensor/blockchain.py
Normal file
@ -0,0 +1,62 @@
|
||||
"""
|
||||
Support for Blockchain.info sensors.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/sensor.blockchain/
|
||||
"""
|
||||
import logging
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.helpers.entity import Entity
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
import voluptuous as vol
|
||||
|
||||
REQUIREMENTS = ['python-blockchain-api==0.0.2']
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
CONF_ADDRESSES = 'addresses'
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_ADDRESSES): [cv.string]
|
||||
})
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up the blockchain sensors."""
|
||||
from pyblockchain import validate_address
|
||||
addresses = config.get(CONF_ADDRESSES)
|
||||
for address in addresses:
|
||||
if not validate_address(address):
|
||||
_LOGGER.error("Bitcoin address is not valid: " + address)
|
||||
return False
|
||||
add_devices([BlockchainSensor('Bitcoin Balance', addresses)])
|
||||
|
||||
|
||||
class BlockchainSensor(Entity):
|
||||
"""Representation of a blockchain.info sensor."""
|
||||
|
||||
def __init__(self, name, addresses):
|
||||
"""Initialize the sensor."""
|
||||
self._name = name
|
||||
self.addresses = addresses
|
||||
self._state = None
|
||||
self._unit_of_measurement = 'BTC'
|
||||
self.update()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement this sensor expresses itself in."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
def update(self):
|
||||
"""Get the latest state of the sensor."""
|
||||
from pyblockchain import get_balance
|
||||
self._state = get_balance(self.addresses)
|
@ -645,6 +645,9 @@ pysnmp==4.3.7
|
||||
# homeassistant.components.switch.thinkingcleaner
|
||||
pythinkingcleaner==0.0.3
|
||||
|
||||
# homeassistant.components.sensor.blockchain
|
||||
python-blockchain-api==0.0.2
|
||||
|
||||
# homeassistant.components.media_player.clementine
|
||||
python-clementine-remote==1.0.1
|
||||
|
||||
|
Reference in New Issue
Block a user