Update docstrings (sensor.pi_hole, sensor.haveibeenpwned) (#3793)

* Fix docstrings

* Update docstrings
This commit is contained in:
Fabian Affolter 2016-10-10 19:38:32 +02:00 committed by GitHub
parent 552265bc31
commit 3b331eac56
2 changed files with 13 additions and 15 deletions

View File

@ -33,7 +33,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
# pylint: disable=unused-argument # pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None): def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the RESTful sensor.""" """Set up the HaveIBeenPwnedSensor sensor."""
emails = config.get(CONF_EMAIL) emails = config.get(CONF_EMAIL)
data = HaveIBeenPwnedData(emails) data = HaveIBeenPwnedData(emails)
@ -43,15 +43,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
add_devices(devices) add_devices(devices)
# To make sure we get initial data for the sensors # To make sure we get initial data for the sensors ignoring the normal
# ignoring the normal throttle of 15 minutes but using # throttle of 15 minutes but using an update throttle of 5 seconds
# an update throttle of 5 seconds
for sensor in devices: for sensor in devices:
sensor.update_nothrottle() sensor.update_nothrottle()
class HaveIBeenPwnedSensor(Entity): class HaveIBeenPwnedSensor(Entity):
"""Implementation of HaveIBeenPwnedSensor.""" """Implementation of a HaveIBeenPwnedSensor."""
def __init__(self, data, hass, email): def __init__(self, data, hass, email):
"""Initialize the HaveIBeenPwnedSensor sensor.""" """Initialize the HaveIBeenPwnedSensor sensor."""
@ -77,7 +76,7 @@ class HaveIBeenPwnedSensor(Entity):
return self._state return self._state
@property @property
def state_attributes(self): def device_state_attributes(self):
"""Return the atrributes of the sensor.""" """Return the atrributes of the sensor."""
val = {} val = {}
if self._email not in self._data.data: if self._email not in self._data.data:
@ -97,12 +96,11 @@ class HaveIBeenPwnedSensor(Entity):
"""Update sensor without throttle.""" """Update sensor without throttle."""
self._data.update_no_throttle() self._data.update_no_throttle()
# Schedule a forced update 5 seconds in the future if the # Schedule a forced update 5 seconds in the future if the update above
# update above returned no data for this sensors email. # returned no data for this sensors email. This is mainly to make sure
# this is mainly to make sure that we don't # that we don't get HTTP Error "too many requests" and to have initial
# get http error "too many requests" and to have initial # data after hass startup once we have the data it will update as
# data after hass startup once we have the data it will # normal using update
# update as normal using update
if self._email not in self._data.data: if self._email not in self._data.data:
track_point_in_time(self._hass, track_point_in_time(self._hass,
self.update_nothrottle, self.update_nothrottle,

View File

@ -89,8 +89,8 @@ class PiHoleSensor(Entity):
# pylint: disable=no-member # pylint: disable=no-member
@property @property
def state_attributes(self): def device_state_attributes(self):
"""Return the state attributes of the GPS.""" """Return the state attributes of the Pi-Hole."""
return { return {
ATTR_BLOCKED_DOMAINS: self._state.get('domains_being_blocked'), ATTR_BLOCKED_DOMAINS: self._state.get('domains_being_blocked'),
ATTR_PERCENTAGE_TODAY: self._state.get('ads_percentage_today'), ATTR_PERCENTAGE_TODAY: self._state.get('ads_percentage_today'),
@ -98,7 +98,7 @@ class PiHoleSensor(Entity):
} }
def update(self): def update(self):
"""Get the latest data from REST API and updates the state.""" """Get the latest data from the Pi-Hole API and updates the state."""
try: try:
self.rest.update() self.rest.update()
self._state = json.loads(self.rest.data) self._state = json.loads(self.rest.data)