Upgrade pyuptimerobot to 0.0.5

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

View File

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