From b87e31617adf9bf4b4d8cd755f60921ba7005e7d Mon Sep 17 00:00:00 2001 From: Nolan Gilley Date: Wed, 7 Jun 2017 04:24:07 -0400 Subject: [PATCH] add ripple sensor (#7935) --- .coveragerc | 1 + homeassistant/components/sensor/ripple.py | 74 +++++++++++++++++++++++ requirements_all.txt | 3 + 3 files changed, 78 insertions(+) create mode 100644 homeassistant/components/sensor/ripple.py diff --git a/.coveragerc b/.coveragerc index 403bf9d70eb..15054df24e0 100644 --- a/.coveragerc +++ b/.coveragerc @@ -444,6 +444,7 @@ omit = homeassistant/components/sensor/pvoutput.py homeassistant/components/sensor/qnap.py homeassistant/components/sensor/radarr.py + homeassistant/components/sensor/ripple.py homeassistant/components/sensor/sabnzbd.py homeassistant/components/sensor/scrape.py homeassistant/components/sensor/sensehat.py diff --git a/homeassistant/components/sensor/ripple.py b/homeassistant/components/sensor/ripple.py new file mode 100644 index 00000000000..bb9ef709bc8 --- /dev/null +++ b/homeassistant/components/sensor/ripple.py @@ -0,0 +1,74 @@ +""" +Support for Ripple sensors. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/sensor.ripple/ +""" +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 (CONF_NAME, ATTR_ATTRIBUTION) +from homeassistant.helpers.entity import Entity + +REQUIREMENTS = ['python-ripple-api==0.0.1'] + +CONF_ADDRESS = 'address' +CONF_ATTRIBUTION = "Data provided by ripple.com" + +DEFAULT_NAME = 'Ripple Balance' + +SCAN_INTERVAL = timedelta(minutes=5) + +PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ + vol.Required(CONF_ADDRESS): cv.string, + vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, +}) + + +def setup_platform(hass, config, add_devices, discovery_info=None): + """Set up the Ripple.com sensors.""" + address = config.get(CONF_ADDRESS) + name = config.get(CONF_NAME) + + add_devices([RippleSensor(name, address)], True) + + +class RippleSensor(Entity): + """Representation of an Ripple.com sensor.""" + + def __init__(self, name, address): + """Initialize the sensor.""" + self._name = name + self.address = address + self._state = None + self._unit_of_measurement = 'XRP' + + @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 + + @property + def device_state_attributes(self): + """Return the state attributes of the sensor.""" + return { + ATTR_ATTRIBUTION: CONF_ATTRIBUTION, + } + + def update(self): + """Get the latest state of the sensor.""" + from pyripple import get_balance + self._state = get_balance(self.address) diff --git a/requirements_all.txt b/requirements_all.txt index cd8188fcc0d..8f913e7a270 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -698,6 +698,9 @@ python-nmap==0.6.1 # homeassistant.components.notify.pushover python-pushover==0.2 +# homeassistant.components.sensor.ripple +python-ripple-api==0.0.1 + # homeassistant.components.media_player.roku python-roku==3.1.3