Upgrade pyuptimerobot to 0.0.5

pull/14905/head
Fabian Affolter 2018-06-10 10:58:45 +02:00
parent ce7e9e36dd
commit dc447a75c6
No known key found for this signature in database
GPG Key ID: DDF3D6F44AAB1336
2 changed files with 26 additions and 22 deletions

View File

@ -1,23 +1,26 @@
"""A component to monitor Uptime Robot monitors.
"""
A platform that to monitor Uptime Robot monitors.
For more details about this component, please refer to the documentation at
https://www.home-assistant.io/components/binary_sensor.uptimerobot
For more details about this platform, please refer to the documentation at
https://www.home-assistant.io/components/binary_sensor.uptimerobot/
"""
import logging
import voluptuous as vol
from homeassistant.components.binary_sensor import (
BinarySensorDevice, PLATFORM_SCHEMA)
from homeassistant.const import CONF_API_KEY
PLATFORM_SCHEMA, BinarySensorDevice)
from homeassistant.const import ATTR_ATTRIBUTION, CONF_API_KEY
import homeassistant.helpers.config_validation as cv
REQUIREMENTS = ['pyuptimerobot==0.0.4']
REQUIREMENTS = ['pyuptimerobot==0.0.5']
_LOGGER = logging.getLogger(__name__)
ATTR_TARGET = 'target'
CONF_ATTRIBUTION = "Data provided by Uptime Robot"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_API_KEY): cv.string,
})
@ -28,29 +31,29 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
from pyuptimerobot import UptimeRobot
up_robot = UptimeRobot()
apikey = config.get(CONF_API_KEY)
monitors = up_robot.getMonitors(apikey)
api_key = config.get(CONF_API_KEY)
monitors = up_robot.getMonitors(api_key)
devices = []
if not monitors or monitors.get('stat') != 'ok':
_LOGGER.error('Error connecting to uptime robot.')
_LOGGER.error("Error connecting to Uptime Robot")
return
for monitor in monitors['monitors']:
devices.append(UptimeRobotBinarySensor(
apikey, up_robot, monitorid=monitor['id'],
name=monitor['friendly_name'], target=monitor['url']))
api_key, up_robot, monitor['id'], monitor['friendly_name'],
monitor['url']))
add_devices(devices, True)
class UptimeRobotBinarySensor(BinarySensorDevice):
"""Representation of a Uptime Robot binary_sensor."""
"""Representation of a Uptime Robot binary sensor."""
def __init__(self, apikey, up_robot, monitorid, name, target):
"""Initialize the binary_sensor."""
self._apikey = apikey
self._monitorid = str(monitorid)
def __init__(self, api_key, up_robot, monitor_id, name, target):
"""Initialize Uptime Robot the binary sensor."""
self._api_key = api_key
self._monitor_id = str(monitor_id)
self._name = name
self._target = target
self._up_robot = up_robot
@ -58,7 +61,7 @@ class UptimeRobotBinarySensor(BinarySensorDevice):
@property
def name(self):
"""Return the name of the binary_sensor."""
"""Return the name of the binary sensor."""
return self._name
@property
@ -73,16 +76,17 @@ class UptimeRobotBinarySensor(BinarySensorDevice):
@property
def device_state_attributes(self):
"""Return the state attributes of the binary_sensor."""
"""Return the state attributes of the binary sensor."""
return {
ATTR_ATTRIBUTION: CONF_ATTRIBUTION,
ATTR_TARGET: self._target,
}
def update(self):
"""Get the latest state of the binary_sensor."""
monitor = self._up_robot.getMonitors(self._apikey, self._monitorid)
"""Get the latest state of the binary sensor."""
monitor = self._up_robot.getMonitors(self._api_key, self._monitor_id)
if not monitor or monitor.get('stat') != 'ok':
_LOGGER.debug("Failed to get new state, trying again later.")
_LOGGER.warning("Failed to get new state")
return
status = monitor['monitors'][0]['status']
self._state = 1 if status == 2 else 0

View File

@ -1120,7 +1120,7 @@ pyunifi==2.13
pyupnp-async==0.1.0.2
# homeassistant.components.binary_sensor.uptimerobot
pyuptimerobot==0.0.4
pyuptimerobot==0.0.5
# homeassistant.components.keyboard
# pyuserinput==0.1.11