Fixes for PEP257 (#11810)

* Fixes for PEP257

* More updates
This commit is contained in:
Fabian Affolter 2018-01-21 07:35:38 +01:00 committed by Paulus Schoutsen
parent 0100f87ff2
commit 47e31dc9ee
143 changed files with 1584 additions and 1761 deletions

View file

@ -5,29 +5,26 @@ For more details about this component, please refer to the documentation at
https://home-assistant.io/components/sensor.vultr/
"""
import logging
import voluptuous as vol
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
from homeassistant.const import (
CONF_MONITORED_CONDITIONS, CONF_NAME)
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.components.vultr import (
CONF_SUBSCRIPTION, ATTR_CURRENT_BANDWIDTH_USED, ATTR_PENDING_CHARGES,
ATTR_CURRENT_BANDWIDTH_USED, ATTR_PENDING_CHARGES, CONF_SUBSCRIPTION,
DATA_VULTR)
# Name defaults to {subscription label} {sensor name}
DEFAULT_NAME = 'Vultr {} {}'
DEPENDENCIES = ['vultr']
from homeassistant.const import CONF_MONITORED_CONDITIONS, CONF_NAME
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__)
# Monitored conditions: name, units, icon
DEFAULT_NAME = 'Vultr {} {}'
DEPENDENCIES = ['vultr']
MONITORED_CONDITIONS = {
ATTR_CURRENT_BANDWIDTH_USED: ['Current Bandwidth Used', 'GB',
'mdi:chart-histogram'],
ATTR_PENDING_CHARGES: ['Pending Charges', 'US$',
'mdi:currency-usd']
ATTR_PENDING_CHARGES: ['Pending Charges', 'US$', 'mdi:currency-usd'],
}
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
@ -48,15 +45,12 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
if subscription not in vultr.data:
_LOGGER.error("Subscription %s not found", subscription)
return False
return
sensors = []
for condition in monitored_conditions:
sensors.append(VultrSensor(vultr,
subscription,
condition,
name))
sensors.append(VultrSensor(vultr, subscription, condition, name))
add_devices(sensors, True)
@ -84,21 +78,21 @@ class VultrSensor(Entity):
"""Return the name of the sensor."""
try:
return self._name.format(self._condition_name)
except IndexError: # name contains more {} than fulfilled
except IndexError:
try:
return self._name.format(self.data['label'],
self._condition_name)
except (KeyError, TypeError): # label key missing or data is None
return self._name.format(
self.data['label'], self._condition_name)
except (KeyError, TypeError):
return self._name
@property
def icon(self):
"""Icon used in the frontend if any."""
"""Return the icon used in the frontend if any."""
return self._icon
@property
def unit_of_measurement(self):
"""The unit of measurement to present the value in."""
"""Return the unit of measurement to present the value in."""
return self._units
@property