Corrections due to pylint tests

This commit is contained in:
hydreliox 2016-01-11 06:57:31 +01:00
parent 1f1a46a8bd
commit bcb42674fc

View File

@ -8,7 +8,8 @@ https://home-assistant.io/components/...
""" """
import logging import logging
from datetime import timedelta from datetime import timedelta
from homeassistant.const import (CONF_API_KEY, CONF_USERNAME, CONF_PASSWORD, TEMP_CELCIUS, TEMP_FAHRENHEIT) from homeassistant.const import (CONF_API_KEY, CONF_USERNAME, CONF_PASSWORD,
TEMP_CELCIUS, TEMP_FAHRENHEIT)
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle from homeassistant.util import Throttle
from homeassistant.util.temperature import celcius_to_fahrenheit from homeassistant.util.temperature import celcius_to_fahrenheit
@ -28,7 +29,8 @@ SENSOR_TYPES = {
} }
# Return cached results if last scan was less then this time ago # Return cached results if last scan was less then this time ago
# NetAtmo Data is uploaded to server every 10mn so this time should not be under # NetAtmo Data is uploaded to server every 10mn
# so this time should not be under
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=600) MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=600)
@ -47,8 +49,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
SENSOR_TYPES['temperature'][1] = hass.config.temperature_unit SENSOR_TYPES['temperature'][1] = hass.config.temperature_unit
unit = hass.config.temperature_unit unit = hass.config.temperature_unit
authorization = lnetatmo.ClientAuth(config.get(CONF_API_KEY, None), config.get('secret_key', None), authorization = lnetatmo.ClientAuth(config.get(CONF_API_KEY, None),
config.get(CONF_USERNAME, None), config.get(CONF_PASSWORD, None)) config.get('secret_key', None),
config.get(CONF_USERNAME, None),
config.get(CONF_PASSWORD, None))
if not authorization: if not authorization:
_LOGGER.error( _LOGGER.error(
@ -60,18 +64,19 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
dev = [] dev = []
try: try:
""" Iterate each module """ # Iterate each module
for module_name, monitored_conditions in config['modules'].items(): for module_name, monitored_conditions in config['modules'].items():
""" Test if module exist """ # Test if module exist """
if module_name not in data.get_module_names(): if module_name not in data.get_module_names():
_LOGGER.error('Module name: "%s" not found', module_name) _LOGGER.error('Module name: "%s" not found', module_name)
continue continue
""" Only create sensor for monitored """ # Only create sensor for monitored """
for variable in monitored_conditions: for variable in monitored_conditions:
if variable not in SENSOR_TYPES: if variable not in SENSOR_TYPES:
_LOGGER.error('Sensor type: "%s" does not exist', variable) _LOGGER.error('Sensor type: "%s" does not exist', variable)
else: else:
dev.append(NetAtmoSensor(data, module_name, variable, unit)) dev.append(
NetAtmoSensor(data, module_name, variable, unit))
except KeyError: except KeyError:
pass pass
@ -79,6 +84,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
# pylint: disable=too-many-instance-attributes
class NetAtmoSensor(Entity): class NetAtmoSensor(Entity):
""" Implements a NetAtmo sensor. """ """ Implements a NetAtmo sensor. """
@ -119,7 +125,8 @@ class NetAtmoSensor(Entity):
self._state = round(data['Temperature'], self._state = round(data['Temperature'],
1) 1)
elif self.temp_unit == TEMP_FAHRENHEIT: elif self.temp_unit == TEMP_FAHRENHEIT:
converted_temperature = celcius_to_fahrenheit(data['Temperature']) converted_temperature = celcius_to_fahrenheit(
data['Temperature'])
self._state = round(converted_temperature, 1) self._state = round(converted_temperature, 1)
else: else:
self._state = round(data['Temperature'], 1) self._state = round(data['Temperature'], 1)
@ -141,14 +148,15 @@ class NetAtmoData(object):
self.auth = auth self.auth = auth
self.data = None self.data = None
def get_module_names (self) : def get_module_names(self):
""" Return all module available on the API as a list. """
self.update() self.update()
return self.data.keys() return self.data.keys()
@Throttle(MIN_TIME_BETWEEN_UPDATES) @Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self): def update(self):
""" Call the NetAtmo API to update the data. """
import lnetatmo import lnetatmo
""" Gets the latest data from NetAtmo. """ # Gets the latest data from NetAtmo. """
devList = lnetatmo.DeviceList(self.auth) dev_list = lnetatmo.DeviceList(self.auth)
self.data = devList.lastData(exclude=3600) self.data = dev_list.lastData(exclude=3600)