From 6bfd52ada862dab0e01461999559cfd57d1cd4d0 Mon Sep 17 00:00:00 2001 From: Nolan Gilley Date: Mon, 5 Jun 2017 01:48:04 -0400 Subject: [PATCH] Etherscan.io sensor (#7855) * etherscan sensor * Update etherscan.py --- .coveragerc | 1 + homeassistant/components/sensor/etherscan.py | 55 ++++++++++++++++++++ requirements_all.txt | 3 ++ 3 files changed, 59 insertions(+) create mode 100644 homeassistant/components/sensor/etherscan.py diff --git a/.coveragerc b/.coveragerc index 171756719a5..93dee127076 100644 --- a/.coveragerc +++ b/.coveragerc @@ -393,6 +393,7 @@ omit = homeassistant/components/sensor/eliqonline.py homeassistant/components/sensor/emoncms.py homeassistant/components/sensor/envirophat.py + homeassistant/components/sensor/etherscan.py homeassistant/components/sensor/fastdotcom.py homeassistant/components/sensor/fedex.py homeassistant/components/sensor/fido.py diff --git a/homeassistant/components/sensor/etherscan.py b/homeassistant/components/sensor/etherscan.py new file mode 100644 index 00000000000..568d83f0e87 --- /dev/null +++ b/homeassistant/components/sensor/etherscan.py @@ -0,0 +1,55 @@ +""" +Support for Etherscan sensors. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/sensor.etherscan/ +""" +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-etherscan-api==0.0.1'] +CONF_ADDRESS = 'address' + +PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ + vol.Required(CONF_ADDRESS): cv.string +}) + + +def setup_platform(hass, config, add_devices, discovery_info=None): + """Set up the etherscan sensors.""" + add_devices([EtherscanSensor('Ethereum Balance', + config.get(CONF_ADDRESS))]) + + +class EtherscanSensor(Entity): + """Representation of an Etherscan.io sensor.""" + + def __init__(self, name, address): + """Initialize the sensor.""" + self._name = name + self.address = address + self._state = None + self._unit_of_measurement = 'ETH' + 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 pyetherscan import get_balance + self._state = get_balance(self.address) diff --git a/requirements_all.txt b/requirements_all.txt index 7fcf54b9809..95500006a37 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -657,6 +657,9 @@ python-ecobee-api==0.0.7 # homeassistant.components.climate.eq3btsmart # python-eq3bt==0.1.5 +# homeassistant.components.sensor.etherscan +python-etherscan-api==0.0.1 + # homeassistant.components.sensor.darksky python-forecastio==1.3.5