diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index 64ad88f8c8b68e..c5b01916d8c60a 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -35,13 +35,13 @@ def from_config_dict(config: Dict[str, Any], - hass: Optional[core.HomeAssistant]=None, - config_dir: Optional[str]=None, - enable_log: bool=True, - verbose: bool=False, - skip_pip: bool=False, - log_rotate_days: Any=None, - log_file: Any=None) \ + hass: Optional[core.HomeAssistant] = None, + config_dir: Optional[str] = None, + enable_log: bool = True, + verbose: bool = False, + skip_pip: bool = False, + log_rotate_days: Any = None, + log_file: Any = None) \ -> Optional[core.HomeAssistant]: """Try to configure Home Assistant from a configuration dictionary. @@ -68,12 +68,12 @@ def from_config_dict(config: Dict[str, Any], @asyncio.coroutine def async_from_config_dict(config: Dict[str, Any], hass: core.HomeAssistant, - config_dir: Optional[str]=None, - enable_log: bool=True, - verbose: bool=False, - skip_pip: bool=False, - log_rotate_days: Any=None, - log_file: Any=None) \ + config_dir: Optional[str] = None, + enable_log: bool = True, + verbose: bool = False, + skip_pip: bool = False, + log_rotate_days: Any = None, + log_file: Any = None) \ -> Optional[core.HomeAssistant]: """Try to configure Home Assistant from a configuration dictionary. @@ -163,11 +163,11 @@ def async_from_config_dict(config: Dict[str, Any], def from_config_file(config_path: str, - hass: Optional[core.HomeAssistant]=None, - verbose: bool=False, - skip_pip: bool=True, - log_rotate_days: Any=None, - log_file: Any=None): + hass: Optional[core.HomeAssistant] = None, + verbose: bool = False, + skip_pip: bool = True, + log_rotate_days: Any = None, + log_file: Any = None): """Read the configuration file and try to start all the functionality. Will add functionality to 'hass' parameter if given, @@ -188,10 +188,10 @@ def from_config_file(config_path: str, @asyncio.coroutine def async_from_config_file(config_path: str, hass: core.HomeAssistant, - verbose: bool=False, - skip_pip: bool=True, - log_rotate_days: Any=None, - log_file: Any=None): + verbose: bool = False, + skip_pip: bool = True, + log_rotate_days: Any = None, + log_file: Any = None): """Read the configuration file and try to start all the functionality. Will add functionality to 'hass' parameter. @@ -219,7 +219,7 @@ def async_from_config_file(config_path: str, @core.callback -def async_enable_logging(hass: core.HomeAssistant, verbose: bool=False, +def async_enable_logging(hass: core.HomeAssistant, verbose: bool = False, log_rotate_days=None, log_file=None) -> None: """Set up the logging. diff --git a/homeassistant/components/abode.py b/homeassistant/components/abode.py index cbfee2ae21597a..fde21a265b02bf 100644 --- a/homeassistant/components/abode.py +++ b/homeassistant/components/abode.py @@ -7,6 +7,7 @@ import asyncio import logging from functools import partial +from requests.exceptions import HTTPError, ConnectTimeout import voluptuous as vol @@ -17,7 +18,6 @@ from homeassistant.helpers import config_validation as cv from homeassistant.helpers import discovery from homeassistant.helpers.entity import Entity -from requests.exceptions import HTTPError, ConnectTimeout REQUIREMENTS = ['abodepy==0.12.2'] diff --git a/homeassistant/components/alarm_control_panel/canary.py b/homeassistant/components/alarm_control_panel/canary.py index fb5c4c37e8dce6..2e0e9994e100d6 100644 --- a/homeassistant/components/alarm_control_panel/canary.py +++ b/homeassistant/components/alarm_control_panel/canary.py @@ -59,8 +59,7 @@ def state(self): return STATE_ALARM_ARMED_HOME elif mode.name == LOCATION_MODE_NIGHT: return STATE_ALARM_ARMED_NIGHT - else: - return None + return None @property def device_state_attributes(self): diff --git a/homeassistant/components/alarm_control_panel/manual.py b/homeassistant/components/alarm_control_panel/manual.py index 35b255d4b57aae..5beb5261607d01 100644 --- a/homeassistant/components/alarm_control_panel/manual.py +++ b/homeassistant/components/alarm_control_panel/manual.py @@ -172,9 +172,8 @@ def state(self): trigger_time) < dt_util.utcnow(): if self._disarm_after_trigger: return STATE_ALARM_DISARMED - else: - self._state = self._previous_state - return self._state + self._state = self._previous_state + return self._state if self._state in SUPPORTED_PENDING_STATES and \ self._within_pending_time(self._state): @@ -187,8 +186,7 @@ def _active_state(self): """Get the current state.""" if self.state == STATE_ALARM_PENDING: return self._previous_state - else: - return self._state + return self._state def _pending_time(self, state): """Get the pending time.""" diff --git a/homeassistant/components/alarm_control_panel/manual_mqtt.py b/homeassistant/components/alarm_control_panel/manual_mqtt.py index ef12cbe365fe28..4b08ad67292d27 100644 --- a/homeassistant/components/alarm_control_panel/manual_mqtt.py +++ b/homeassistant/components/alarm_control_panel/manual_mqtt.py @@ -208,9 +208,8 @@ def state(self): trigger_time) < dt_util.utcnow(): if self._disarm_after_trigger: return STATE_ALARM_DISARMED - else: - self._state = self._previous_state - return self._state + self._state = self._previous_state + return self._state if self._state in SUPPORTED_PENDING_STATES and \ self._within_pending_time(self._state): @@ -223,8 +222,7 @@ def _active_state(self): """Get the current state.""" if self.state == STATE_ALARM_PENDING: return self._previous_state - else: - return self._state + return self._state def _pending_time(self, state): """Get the pending time.""" diff --git a/homeassistant/components/binary_sensor/envisalink.py b/homeassistant/components/binary_sensor/envisalink.py index 7d35c0c9e94959..0aadcc247ea1e0 100644 --- a/homeassistant/components/binary_sensor/envisalink.py +++ b/homeassistant/components/binary_sensor/envisalink.py @@ -50,7 +50,7 @@ def __init__(self, hass, zone_number, zone_name, zone_type, info, self._zone_type = zone_type self._zone_number = zone_number - _LOGGER.debug('Setting up zone: ' + zone_name) + _LOGGER.debug('Setting up zone: %s', zone_name) super().__init__(zone_name, info, controller) @asyncio.coroutine diff --git a/homeassistant/components/binary_sensor/ihc.py b/homeassistant/components/binary_sensor/ihc.py index 04f8c0d00ddf5a..97de176753ffe8 100644 --- a/homeassistant/components/binary_sensor/ihc.py +++ b/homeassistant/components/binary_sensor/ihc.py @@ -70,7 +70,7 @@ class IHCBinarySensor(IHCDevice, BinarySensorDevice): def __init__(self, ihc_controller, name, ihc_id: int, info: bool, sensor_type: str, inverting: bool, - product: Element=None) -> None: + product: Element = None) -> None: """Initialize the IHC binary sensor.""" super().__init__(ihc_controller, name, ihc_id, info, product) self._state = None diff --git a/homeassistant/components/calendar/todoist.py b/homeassistant/components/calendar/todoist.py index f1c80612f3ba4e..c5ae1dd3c11b3f 100644 --- a/homeassistant/components/calendar/todoist.py +++ b/homeassistant/components/calendar/todoist.py @@ -498,7 +498,7 @@ def update(self): # Organize the best tasks (so users can see all the tasks # they have, organized) - while len(project_tasks) > 0: + while project_tasks: best_task = self.select_best_task(project_tasks) _LOGGER.debug("Found Todoist Task: %s", best_task[SUMMARY]) project_tasks.remove(best_task) diff --git a/homeassistant/components/camera/mjpeg.py b/homeassistant/components/camera/mjpeg.py index 6168eb81939a22..35d30104f6e66d 100644 --- a/homeassistant/components/camera/mjpeg.py +++ b/homeassistant/components/camera/mjpeg.py @@ -119,6 +119,8 @@ def camera_image(self): else: req = requests.get(self._mjpeg_url, stream=True, timeout=10) + # https://github.com/PyCQA/pylint/issues/1437 + # pylint: disable=no-member with closing(req) as response: return extract_image_from_mjpeg(response.iter_content(102400)) diff --git a/homeassistant/components/camera/uvc.py b/homeassistant/components/camera/uvc.py index f7dc4cfd9737bc..20dceb8a1c5da2 100644 --- a/homeassistant/components/camera/uvc.py +++ b/homeassistant/components/camera/uvc.py @@ -188,7 +188,7 @@ def set_motion_detection(self, mode): self._nvr.set_recordmode(self._uuid, set_mode) self._motion_status = mode except NvrError as err: - _LOGGER.error("Unable to set recordmode to " + set_mode) + _LOGGER.error("Unable to set recordmode to %s", set_mode) _LOGGER.debug(err) def enable_motion_detection(self): diff --git a/homeassistant/components/camera/xeoma.py b/homeassistant/components/camera/xeoma.py index b4bcad0064d689..23342b94cdce7d 100644 --- a/homeassistant/components/camera/xeoma.py +++ b/homeassistant/components/camera/xeoma.py @@ -42,7 +42,6 @@ @asyncio.coroutine -# pylint: disable=unused-argument def async_setup_platform(hass, config, async_add_devices, discovery_info=None): """Discover and setup Xeoma Cameras.""" from pyxeoma.xeoma import Xeoma, XeomaError @@ -69,6 +68,8 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None): ] for cam in config[CONF_CAMERAS]: + # https://github.com/PyCQA/pylint/issues/1830 + # pylint: disable=stop-iteration-return camera = next( (dc for dc in discovered_cameras if dc[CONF_IMAGE_NAME] == cam[CONF_IMAGE_NAME]), None) diff --git a/homeassistant/components/climate/__init__.py b/homeassistant/components/climate/__init__.py index ce656eb96e8061..e1a5f71af83fc8 100644 --- a/homeassistant/components/climate/__init__.py +++ b/homeassistant/components/climate/__init__.py @@ -669,16 +669,16 @@ def async_set_humidity(self, humidity): """ return self.hass.async_add_job(self.set_humidity, humidity) - def set_fan_mode(self, fan): + def set_fan_mode(self, fan_mode): """Set new target fan mode.""" raise NotImplementedError() - def async_set_fan_mode(self, fan): + def async_set_fan_mode(self, fan_mode): """Set new target fan mode. This method must be run in the event loop and returns a coroutine. """ - return self.hass.async_add_job(self.set_fan_mode, fan) + return self.hass.async_add_job(self.set_fan_mode, fan_mode) def set_operation_mode(self, operation_mode): """Set new target operation mode.""" diff --git a/homeassistant/components/climate/daikin.py b/homeassistant/components/climate/daikin.py index 0ed4ebe8942e57..531abd4b58163a 100644 --- a/homeassistant/components/climate/daikin.py +++ b/homeassistant/components/climate/daikin.py @@ -236,9 +236,9 @@ def current_fan_mode(self): """Return the fan setting.""" return self.get(ATTR_FAN_MODE) - def set_fan_mode(self, fan): + def set_fan_mode(self, fan_mode): """Set fan mode.""" - self.set({ATTR_FAN_MODE: fan}) + self.set({ATTR_FAN_MODE: fan_mode}) @property def fan_list(self): diff --git a/homeassistant/components/climate/demo.py b/homeassistant/components/climate/demo.py index 102155babea7bc..44491b8cd21e4d 100644 --- a/homeassistant/components/climate/demo.py +++ b/homeassistant/components/climate/demo.py @@ -195,9 +195,9 @@ def set_swing_mode(self, swing_mode): self._current_swing_mode = swing_mode self.schedule_update_ha_state() - def set_fan_mode(self, fan): + def set_fan_mode(self, fan_mode): """Set new target temperature.""" - self._current_fan_mode = fan + self._current_fan_mode = fan_mode self.schedule_update_ha_state() def set_operation_mode(self, operation_mode): @@ -225,9 +225,9 @@ def turn_away_mode_off(self): self._away = False self.schedule_update_ha_state() - def set_hold_mode(self, hold): - """Update hold mode on.""" - self._hold = hold + def set_hold_mode(self, hold_mode): + """Update hold_mode on.""" + self._hold = hold_mode self.schedule_update_ha_state() def turn_aux_heat_on(self): diff --git a/homeassistant/components/climate/ephember.py b/homeassistant/components/climate/ephember.py index e1f1ab7d448b75..419237b4645ae5 100644 --- a/homeassistant/components/climate/ephember.py +++ b/homeassistant/components/climate/ephember.py @@ -98,8 +98,7 @@ def current_operation(self): """Return current operation ie. heat, cool, idle.""" if self._zone['isCurrentlyActive']: return STATE_HEAT - else: - return STATE_IDLE + return STATE_IDLE @property def is_aux_heat_on(self): diff --git a/homeassistant/components/climate/eq3btsmart.py b/homeassistant/components/climate/eq3btsmart.py index 9c712c632e6139..4a402887864ac6 100644 --- a/homeassistant/components/climate/eq3btsmart.py +++ b/homeassistant/components/climate/eq3btsmart.py @@ -53,7 +53,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): add_devices(devices) -# pylint: disable=import-error +# pylint: disable=import-error, no-name-in-module class EQ3BTSmartThermostat(ClimateDevice): """Representation of an eQ-3 Bluetooth Smart thermostat.""" diff --git a/homeassistant/components/climate/flexit.py b/homeassistant/components/climate/flexit.py index 98c03217509cd5..565e913319f4c4 100644 --- a/homeassistant/components/climate/flexit.py +++ b/homeassistant/components/climate/flexit.py @@ -152,6 +152,6 @@ def set_temperature(self, **kwargs): self._target_temperature = kwargs.get(ATTR_TEMPERATURE) self.unit.set_temp(self._target_temperature) - def set_fan_mode(self, fan): + def set_fan_mode(self, fan_mode): """Set new fan mode.""" - self.unit.set_fan_speed(self._fan_list.index(fan)) + self.unit.set_fan_speed(self._fan_list.index(fan_mode)) diff --git a/homeassistant/components/climate/generic_thermostat.py b/homeassistant/components/climate/generic_thermostat.py index c66e611c8e9078..b97dc22129889d 100644 --- a/homeassistant/components/climate/generic_thermostat.py +++ b/homeassistant/components/climate/generic_thermostat.py @@ -190,11 +190,9 @@ def state(self): """Return the current state.""" if self._is_device_active: return self.current_operation - else: - if self._enabled: - return STATE_IDLE - else: - return STATE_OFF + if self._enabled: + return STATE_IDLE + return STATE_OFF @property def should_poll(self): diff --git a/homeassistant/components/climate/melissa.py b/homeassistant/components/climate/melissa.py index 2b3b3bfbab1d1f..96bd66d05a54b8 100644 --- a/homeassistant/components/climate/melissa.py +++ b/homeassistant/components/climate/melissa.py @@ -146,10 +146,10 @@ def set_temperature(self, **kwargs): temp = kwargs.get(ATTR_TEMPERATURE) self.send({self._api.TEMP: temp}) - def set_fan_mode(self, fan): + def set_fan_mode(self, fan_mode): """Set fan mode.""" - fan_mode = self.hass_fan_to_melissa(fan) - self.send({self._api.FAN: fan_mode}) + melissa_fan_mode = self.hass_fan_to_melissa(fan_mode) + self.send({self._api.FAN: melissa_fan_mode}) def set_operation_mode(self, operation_mode): """Set operation mode.""" @@ -174,8 +174,7 @@ def send(self, value): if not self._api.send(self._serial_number, self._cur_settings): self._cur_settings = old_value return False - else: - return True + return True def update(self): """Get latest data from Melissa.""" @@ -196,8 +195,7 @@ def melissa_state_to_hass(self, state): return STATE_OFF elif state == self._api.STATE_IDLE: return STATE_IDLE - else: - return None + return None def melissa_op_to_hass(self, mode): """Translate Melissa modes to hass states.""" @@ -211,10 +209,9 @@ def melissa_op_to_hass(self, mode): return STATE_DRY elif mode == self._api.MODE_FAN: return STATE_FAN_ONLY - else: - _LOGGER.warning( - "Operation mode %s could not be mapped to hass", mode) - return None + _LOGGER.warning( + "Operation mode %s could not be mapped to hass", mode) + return None def melissa_fan_to_hass(self, fan): """Translate Melissa fan modes to hass modes.""" @@ -226,9 +223,8 @@ def melissa_fan_to_hass(self, fan): return SPEED_MEDIUM elif fan == self._api.FAN_HIGH: return SPEED_HIGH - else: - _LOGGER.warning("Fan mode %s could not be mapped to hass", fan) - return None + _LOGGER.warning("Fan mode %s could not be mapped to hass", fan) + return None def hass_mode_to_melissa(self, mode): """Translate hass states to melissa modes.""" diff --git a/homeassistant/components/climate/mqtt.py b/homeassistant/components/climate/mqtt.py index 5929cec3b050cb..1d98a5733f7054 100644 --- a/homeassistant/components/climate/mqtt.py +++ b/homeassistant/components/climate/mqtt.py @@ -482,15 +482,15 @@ def async_set_swing_mode(self, swing_mode): self.async_schedule_update_ha_state() @asyncio.coroutine - def async_set_fan_mode(self, fan): + def async_set_fan_mode(self, fan_mode): """Set new target temperature.""" if self._send_if_off or self._current_operation != STATE_OFF: mqtt.async_publish( self.hass, self._topic[CONF_FAN_MODE_COMMAND_TOPIC], - fan, self._qos, self._retain) + fan_mode, self._qos, self._retain) if self._topic[CONF_FAN_MODE_STATE_TOPIC] is None: - self._current_fan_mode = fan + self._current_fan_mode = fan_mode self.async_schedule_update_ha_state() @asyncio.coroutine @@ -552,15 +552,15 @@ def async_turn_away_mode_off(self): self.async_schedule_update_ha_state() @asyncio.coroutine - def async_set_hold_mode(self, hold): + def async_set_hold_mode(self, hold_mode): """Update hold mode on.""" if self._topic[CONF_HOLD_COMMAND_TOPIC] is not None: mqtt.async_publish(self.hass, self._topic[CONF_HOLD_COMMAND_TOPIC], - hold, self._qos, self._retain) + hold_mode, self._qos, self._retain) if self._topic[CONF_HOLD_STATE_TOPIC] is None: - self._hold = hold + self._hold = hold_mode self.async_schedule_update_ha_state() @asyncio.coroutine diff --git a/homeassistant/components/climate/mysensors.py b/homeassistant/components/climate/mysensors.py index 5553db70f0dfcd..b526d8b066cbeb 100644 --- a/homeassistant/components/climate/mysensors.py +++ b/homeassistant/components/climate/mysensors.py @@ -143,14 +143,14 @@ def set_temperature(self, **kwargs): self._values[value_type] = value self.schedule_update_ha_state() - def set_fan_mode(self, fan): + def set_fan_mode(self, fan_mode): """Set new target temperature.""" set_req = self.gateway.const.SetReq self.gateway.set_child_value( - self.node_id, self.child_id, set_req.V_HVAC_SPEED, fan) + self.node_id, self.child_id, set_req.V_HVAC_SPEED, fan_mode) if self.gateway.optimistic: # Optimistically assume that device has changed state - self._values[set_req.V_HVAC_SPEED] = fan + self._values[set_req.V_HVAC_SPEED] = fan_mode self.schedule_update_ha_state() def set_operation_mode(self, operation_mode): diff --git a/homeassistant/components/climate/nest.py b/homeassistant/components/climate/nest.py index d8d7d6c901ade5..0427514a7b5cf3 100644 --- a/homeassistant/components/climate/nest.py +++ b/homeassistant/components/climate/nest.py @@ -207,9 +207,9 @@ def fan_list(self): """List of available fan modes.""" return self._fan_list - def set_fan_mode(self, fan): + def set_fan_mode(self, fan_mode): """Turn fan on/off.""" - self.device.fan = fan.lower() + self.device.fan = fan_mode.lower() @property def min_temp(self): @@ -225,7 +225,7 @@ def update(self): """Cache value from Python-nest.""" self._location = self.device.where self._name = self.device.name - self._humidity = self.device.humidity, + self._humidity = self.device.humidity self._temperature = self.device.temperature self._mode = self.device.mode self._target_temperature = self.device.target diff --git a/homeassistant/components/climate/nuheat.py b/homeassistant/components/climate/nuheat.py index f41812dbaae2fb..39c66ff94f2047 100644 --- a/homeassistant/components/climate/nuheat.py +++ b/homeassistant/components/climate/nuheat.py @@ -185,7 +185,7 @@ def resume_program(self): self._thermostat.resume_schedule() self._force_update = True - def set_hold_mode(self, hold_mode, **kwargs): + def set_hold_mode(self, hold_mode): """Update the hold mode of the thermostat.""" if hold_mode == MODE_AUTO: schedule_mode = SCHEDULE_RUN diff --git a/homeassistant/components/climate/radiotherm.py b/homeassistant/components/climate/radiotherm.py index 2b31ca93d22934..032d85637ef506 100644 --- a/homeassistant/components/climate/radiotherm.py +++ b/homeassistant/components/climate/radiotherm.py @@ -183,17 +183,16 @@ def fan_list(self): """List of available fan modes.""" if self._is_model_ct80: return CT80_FAN_OPERATION_LIST - else: - return CT30_FAN_OPERATION_LIST + return CT30_FAN_OPERATION_LIST @property def current_fan_mode(self): """Return whether the fan is on.""" return self._fmode - def set_fan_mode(self, fan): + def set_fan_mode(self, fan_mode): """Turn fan on/off.""" - code = FAN_MODE_TO_CODE.get(fan, None) + code = FAN_MODE_TO_CODE.get(fan_mode, None) if code is not None: self.device.fmode = code diff --git a/homeassistant/components/climate/sensibo.py b/homeassistant/components/climate/sensibo.py index 67113e7c48a024..b49d379592f74f 100644 --- a/homeassistant/components/climate/sensibo.py +++ b/homeassistant/components/climate/sensibo.py @@ -240,13 +240,13 @@ def is_on(self): def min_temp(self): """Return the minimum temperature.""" return self._temperatures_list[0] \ - if len(self._temperatures_list) else super().min_temp() + if self._temperatures_list else super().min_temp() @property def max_temp(self): """Return the maximum temperature.""" return self._temperatures_list[-1] \ - if len(self._temperatures_list) else super().max_temp() + if self._temperatures_list else super().max_temp() @asyncio.coroutine def async_set_temperature(self, **kwargs): @@ -273,11 +273,11 @@ def async_set_temperature(self, **kwargs): self._id, 'targetTemperature', temperature, self._ac_states) @asyncio.coroutine - def async_set_fan_mode(self, fan): + def async_set_fan_mode(self, fan_mode): """Set new target fan mode.""" with async_timeout.timeout(TIMEOUT): yield from self._client.async_set_ac_state_property( - self._id, 'fanLevel', fan, self._ac_states) + self._id, 'fanLevel', fan_mode, self._ac_states) @asyncio.coroutine def async_set_operation_mode(self, operation_mode): diff --git a/homeassistant/components/climate/tado.py b/homeassistant/components/climate/tado.py index 868511c0ac4ca8..437c8ec3371bf5 100644 --- a/homeassistant/components/climate/tado.py +++ b/homeassistant/components/climate/tado.py @@ -213,6 +213,7 @@ def set_temperature(self, **kwargs): self._target_temp = temperature self._control_heating() + # pylint: disable=arguments-differ def set_operation_mode(self, readable_operation_mode): """Set new operation mode.""" operation_mode = CONST_MODE_SMART_SCHEDULE diff --git a/homeassistant/components/climate/tesla.py b/homeassistant/components/climate/tesla.py index 459d9c666fdfc1..225c13d975dc34 100644 --- a/homeassistant/components/climate/tesla.py +++ b/homeassistant/components/climate/tesla.py @@ -51,8 +51,7 @@ def current_operation(self): mode = self.tesla_device.is_hvac_enabled() if mode: return OPERATION_LIST[0] # On - else: - return OPERATION_LIST[1] # Off + return OPERATION_LIST[1] # Off @property def operation_list(self): diff --git a/homeassistant/components/climate/venstar.py b/homeassistant/components/climate/venstar.py index 6db1d53bc50348..6e63cc4092b833 100644 --- a/homeassistant/components/climate/venstar.py +++ b/homeassistant/components/climate/venstar.py @@ -111,8 +111,7 @@ def temperature_unit(self): """Return the unit of measurement, as defined by the API.""" if self._client.tempunits == self._client.TEMPUNITS_F: return TEMP_FAHRENHEIT - else: - return TEMP_CELSIUS + return TEMP_CELSIUS @property def fan_list(self): @@ -143,16 +142,14 @@ def current_operation(self): return STATE_COOL elif self._client.mode == self._client.MODE_AUTO: return STATE_AUTO - else: - return STATE_OFF + return STATE_OFF @property def current_fan_mode(self): """Return the fan setting.""" if self._client.fan == self._client.FAN_AUTO: return STATE_AUTO - else: - return STATE_ON + return STATE_ON @property def device_state_attributes(self): @@ -169,24 +166,21 @@ def target_temperature(self): return self._client.heattemp elif self._client.mode == self._client.MODE_COOL: return self._client.cooltemp - else: - return None + return None @property def target_temperature_low(self): """Return the lower bound temp if auto mode is on.""" if self._client.mode == self._client.MODE_AUTO: return self._client.heattemp - else: - return None + return None @property def target_temperature_high(self): """Return the upper bound temp if auto mode is on.""" if self._client.mode == self._client.MODE_AUTO: return self._client.cooltemp - else: - return None + return None @property def target_humidity(self): @@ -245,9 +239,9 @@ def set_temperature(self, **kwargs): if not success: _LOGGER.error("Failed to change the temperature") - def set_fan_mode(self, fan): + def set_fan_mode(self, fan_mode): """Set new target fan mode.""" - if fan == STATE_ON: + if fan_mode == STATE_ON: success = self._client.set_fan(self._client.FAN_ON) else: success = self._client.set_fan(self._client.FAN_AUTO) diff --git a/homeassistant/components/climate/vera.py b/homeassistant/components/climate/vera.py index c9d22e41d81d07..6fb6bc0ff48410 100644 --- a/homeassistant/components/climate/vera.py +++ b/homeassistant/components/climate/vera.py @@ -85,13 +85,13 @@ def fan_list(self): """Return a list of available fan modes.""" return FAN_OPERATION_LIST - def set_fan_mode(self, mode): + def set_fan_mode(self, fan_mode): """Set new target temperature.""" - if mode == FAN_OPERATION_LIST[0]: + if fan_mode == FAN_OPERATION_LIST[0]: self.vera_device.fan_on() - elif mode == FAN_OPERATION_LIST[1]: + elif fan_mode == FAN_OPERATION_LIST[1]: self.vera_device.fan_auto() - elif mode == FAN_OPERATION_LIST[2]: + elif fan_mode == FAN_OPERATION_LIST[2]: return self.vera_device.fan_cycle() @property diff --git a/homeassistant/components/climate/wink.py b/homeassistant/components/climate/wink.py index 50374a3280705e..8c66567a4aadef 100644 --- a/homeassistant/components/climate/wink.py +++ b/homeassistant/components/climate/wink.py @@ -324,9 +324,9 @@ def fan_list(self): return self.wink.fan_modes() return None - def set_fan_mode(self, fan): + def set_fan_mode(self, fan_mode): """Turn fan on/off.""" - self.wink.set_fan_mode(fan.lower()) + self.wink.set_fan_mode(fan_mode.lower()) def turn_aux_heat_on(self): """Turn auxiliary heater on.""" @@ -486,26 +486,25 @@ def current_fan_mode(self): return SPEED_LOW elif speed <= 0.66: return SPEED_MEDIUM - else: - return SPEED_HIGH + return SPEED_HIGH @property def fan_list(self): """Return a list of available fan modes.""" return [SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH] - def set_fan_mode(self, fan): + def set_fan_mode(self, fan_mode): """ Set fan speed. The official Wink app only supports 3 modes [low, medium, high] which are equal to [0.33, 0.66, 1.0] respectively. """ - if fan == SPEED_LOW: + if fan_mode == SPEED_LOW: speed = 0.33 - elif fan == SPEED_MEDIUM: + elif fan_mode == SPEED_MEDIUM: speed = 0.66 - elif fan == SPEED_HIGH: + elif fan_mode == SPEED_HIGH: speed = 1.0 self.wink.set_ac_fan_speed(speed) diff --git a/homeassistant/components/climate/zwave.py b/homeassistant/components/climate/zwave.py index acc3eda1194262..1eec9c82f3ca9a 100644 --- a/homeassistant/components/climate/zwave.py +++ b/homeassistant/components/climate/zwave.py @@ -198,10 +198,10 @@ def set_temperature(self, **kwargs): self.values.primary.data = temperature - def set_fan_mode(self, fan): + def set_fan_mode(self, fan_mode): """Set new target fan mode.""" if self.values.fan_mode: - self.values.fan_mode.data = fan + self.values.fan_mode.data = fan_mode def set_operation_mode(self, operation_mode): """Set new target operation mode.""" diff --git a/homeassistant/components/cloud/auth_api.py b/homeassistant/components/cloud/auth_api.py index e96f2a2d8a5242..c7679c0f262d17 100644 --- a/homeassistant/components/cloud/auth_api.py +++ b/homeassistant/components/cloud/auth_api.py @@ -31,6 +31,8 @@ class InvalidCode(CloudError): class PasswordChangeRequired(CloudError): """Raised when a password change is required.""" + # https://github.com/PyCQA/pylint/issues/1085 + # pylint: disable=useless-super-delegation def __init__(self, message='Password change required.'): """Initialize a password change required error.""" super().__init__(message) diff --git a/homeassistant/components/cover/demo.py b/homeassistant/components/cover/demo.py index 827b50c8af9d1f..70e681f11207fb 100644 --- a/homeassistant/components/cover/demo.py +++ b/homeassistant/components/cover/demo.py @@ -5,7 +5,8 @@ https://home-assistant.io/components/demo/ """ from homeassistant.components.cover import ( - CoverDevice, SUPPORT_OPEN, SUPPORT_CLOSE) + CoverDevice, SUPPORT_OPEN, SUPPORT_CLOSE, ATTR_POSITION, + ATTR_TILT_POSITION) from homeassistant.helpers.event import track_utc_time_change @@ -137,8 +138,9 @@ def open_cover_tilt(self, **kwargs): self._listen_cover_tilt() self._requested_closing_tilt = False - def set_cover_position(self, position, **kwargs): + def set_cover_position(self, **kwargs): """Move the cover to a specific position.""" + position = kwargs.get(ATTR_POSITION) self._set_position = round(position, -1) if self._position == position: return @@ -146,8 +148,9 @@ def set_cover_position(self, position, **kwargs): self._listen_cover() self._requested_closing = position < self._position - def set_cover_tilt_position(self, tilt_position, **kwargs): + def set_cover_tilt_position(self, **kwargs): """Move the cover til to a specific position.""" + tilt_position = kwargs.get(ATTR_TILT_POSITION) self._set_tilt_position = round(tilt_position, -1) if self._tilt_position == tilt_position: return diff --git a/homeassistant/components/cover/garadget.py b/homeassistant/components/cover/garadget.py index 22f5fd889a2dc4..c19aa69c8f04bb 100644 --- a/homeassistant/components/cover/garadget.py +++ b/homeassistant/components/cover/garadget.py @@ -201,21 +201,21 @@ def _check_state(self, now): """Check the state of the service during an operation.""" self.schedule_update_ha_state(True) - def close_cover(self): + def close_cover(self, **kwargs): """Close the cover.""" if self._state not in ['close', 'closing']: ret = self._put_command('setState', 'close') self._start_watcher('close') return ret.get('return_value') == 1 - def open_cover(self): + def open_cover(self, **kwargs): """Open the cover.""" if self._state not in ['open', 'opening']: ret = self._put_command('setState', 'open') self._start_watcher('open') return ret.get('return_value') == 1 - def stop_cover(self): + def stop_cover(self, **kwargs): """Stop the door where it is.""" if self._state not in ['stopped']: ret = self._put_command('setState', 'stop') diff --git a/homeassistant/components/cover/isy994.py b/homeassistant/components/cover/isy994.py index 7d77b1bc3becdd..82ca60e84e6c91 100644 --- a/homeassistant/components/cover/isy994.py +++ b/homeassistant/components/cover/isy994.py @@ -42,10 +42,6 @@ def setup_platform(hass, config: ConfigType, class ISYCoverDevice(ISYDevice, CoverDevice): """Representation of an ISY994 cover device.""" - def __init__(self, node: object) -> None: - """Initialize the ISY994 cover device.""" - super().__init__(node) - @property def current_cover_position(self) -> int: """Return the current cover position.""" @@ -61,8 +57,7 @@ def state(self) -> str: """Get the state of the ISY994 cover device.""" if self.is_unknown(): return None - else: - return VALUE_TO_STATE.get(self.value, STATE_OPEN) + return VALUE_TO_STATE.get(self.value, STATE_OPEN) def open_cover(self, **kwargs) -> None: """Send the open cover command to the ISY994 cover device.""" diff --git a/homeassistant/components/cover/myq.py b/homeassistant/components/cover/myq.py index 8d59a90278c691..f07d3849fae77e 100644 --- a/homeassistant/components/cover/myq.py +++ b/homeassistant/components/cover/myq.py @@ -84,11 +84,11 @@ def is_closed(self): """Return true if cover is closed, else False.""" return self._status == STATE_CLOSED - def close_cover(self): + def close_cover(self, **kwargs): """Issue close command to cover.""" self.myq.close_device(self.device_id) - def open_cover(self): + def open_cover(self, **kwargs): """Issue open command to cover.""" self.myq.open_device(self.device_id) diff --git a/homeassistant/components/cover/opengarage.py b/homeassistant/components/cover/opengarage.py index d98c71e25fb443..38fbaf0acdb9dc 100644 --- a/homeassistant/components/cover/opengarage.py +++ b/homeassistant/components/cover/opengarage.py @@ -119,14 +119,14 @@ def is_closed(self): return None return self._state in [STATE_CLOSED, STATE_OPENING] - def close_cover(self): + def close_cover(self, **kwargs): """Close the cover.""" if self._state not in [STATE_CLOSED, STATE_CLOSING]: self._state_before_move = self._state self._state = STATE_CLOSING self._push_button() - def open_cover(self): + def open_cover(self, **kwargs): """Open the cover.""" if self._state not in [STATE_OPEN, STATE_OPENING]: self._state_before_move = self._state diff --git a/homeassistant/components/cover/rpi_gpio.py b/homeassistant/components/cover/rpi_gpio.py index 981312140eb13a..77cd0b0f7e2700 100644 --- a/homeassistant/components/cover/rpi_gpio.py +++ b/homeassistant/components/cover/rpi_gpio.py @@ -109,12 +109,12 @@ def _trigger(self): sleep(self._relay_time) rpi_gpio.write_output(self._relay_pin, not self._invert_relay) - def close_cover(self): + def close_cover(self, **kwargs): """Close the cover.""" if not self.is_closed: self._trigger() - def open_cover(self): + def open_cover(self, **kwargs): """Open the cover.""" if self.is_closed: self._trigger() diff --git a/homeassistant/components/cover/tahoma.py b/homeassistant/components/cover/tahoma.py index 19bd9f01417266..6fb8e92e051927 100644 --- a/homeassistant/components/cover/tahoma.py +++ b/homeassistant/components/cover/tahoma.py @@ -6,7 +6,7 @@ """ import logging -from homeassistant.components.cover import CoverDevice +from homeassistant.components.cover import CoverDevice, ATTR_POSITION from homeassistant.components.tahoma import ( DOMAIN as TAHOMA_DOMAIN, TahomaDevice) @@ -49,9 +49,9 @@ def current_cover_position(self): except KeyError: return None - def set_cover_position(self, position, **kwargs): + def set_cover_position(self, **kwargs): """Move the cover to a specific position.""" - self.apply_action('setPosition', 100 - position) + self.apply_action('setPosition', 100 - kwargs.get(ATTR_POSITION)) @property def is_closed(self): @@ -64,8 +64,7 @@ def device_class(self): """Return the class of the device.""" if self.tahoma_device.type == 'io:WindowOpenerVeluxIOComponent': return 'window' - else: - return None + return None def open_cover(self, **kwargs): """Open the cover.""" diff --git a/homeassistant/components/cover/vera.py b/homeassistant/components/cover/vera.py index 6cf269b75b35f4..ff9ba6f762b861 100644 --- a/homeassistant/components/cover/vera.py +++ b/homeassistant/components/cover/vera.py @@ -6,7 +6,8 @@ """ import logging -from homeassistant.components.cover import CoverDevice, ENTITY_ID_FORMAT +from homeassistant.components.cover import CoverDevice, ENTITY_ID_FORMAT, \ + ATTR_POSITION from homeassistant.components.vera import ( VERA_CONTROLLER, VERA_DEVICES, VeraDevice) @@ -44,9 +45,9 @@ def current_cover_position(self): return 100 return position - def set_cover_position(self, position, **kwargs): + def set_cover_position(self, **kwargs): """Move the cover to a specific position.""" - self.vera_device.set_level(position) + self.vera_device.set_level(kwargs.get(ATTR_POSITION)) self.schedule_update_ha_state() @property diff --git a/homeassistant/components/cover/wink.py b/homeassistant/components/cover/wink.py index 35f14e80b5b4c0..093ccd43473a56 100644 --- a/homeassistant/components/cover/wink.py +++ b/homeassistant/components/cover/wink.py @@ -6,7 +6,8 @@ """ import asyncio -from homeassistant.components.cover import CoverDevice, STATE_UNKNOWN +from homeassistant.components.cover import CoverDevice, STATE_UNKNOWN, \ + ATTR_POSITION from homeassistant.components.wink import WinkDevice, DOMAIN DEPENDENCIES = ['wink'] @@ -42,17 +43,17 @@ def open_cover(self, **kwargs): """Open the cover.""" self.wink.set_state(1) - def set_cover_position(self, position, **kwargs): + def set_cover_position(self, **kwargs): """Move the cover shutter to a specific position.""" - self.wink.set_state(float(position)/100) + position = kwargs.get(ATTR_POSITION) + self.wink.set_state(position/100) @property def current_cover_position(self): """Return the current position of cover shutter.""" if self.wink.state() is not None: return int(self.wink.state()*100) - else: - return STATE_UNKNOWN + return STATE_UNKNOWN @property def is_closed(self): diff --git a/homeassistant/components/cover/xiaomi_aqara.py b/homeassistant/components/cover/xiaomi_aqara.py index 29cb707fef5777..14321149148a52 100644 --- a/homeassistant/components/cover/xiaomi_aqara.py +++ b/homeassistant/components/cover/xiaomi_aqara.py @@ -1,7 +1,7 @@ """Support for Xiaomi curtain.""" import logging -from homeassistant.components.cover import CoverDevice +from homeassistant.components.cover import CoverDevice, ATTR_POSITION from homeassistant.components.xiaomi_aqara import (PY_XIAOMI_GATEWAY, XiaomiDevice) @@ -55,8 +55,9 @@ def stop_cover(self, **kwargs): """Stop the cover.""" self._write_to_hub(self._sid, **{self._data_key['status']: 'stop'}) - def set_cover_position(self, position, **kwargs): + def set_cover_position(self, **kwargs): """Move the cover to a specific position.""" + position = kwargs.get(ATTR_POSITION) self._write_to_hub(self._sid, **{self._data_key['pos']: str(position)}) def parse_data(self, data, raw_data): diff --git a/homeassistant/components/cover/zwave.py b/homeassistant/components/cover/zwave.py index 151009572429d2..6f4a11684bde61 100644 --- a/homeassistant/components/cover/zwave.py +++ b/homeassistant/components/cover/zwave.py @@ -8,7 +8,7 @@ # pylint: disable=import-error import logging from homeassistant.components.cover import ( - DOMAIN, SUPPORT_OPEN, SUPPORT_CLOSE) + DOMAIN, SUPPORT_OPEN, SUPPORT_CLOSE, ATTR_POSITION) from homeassistant.components.zwave import ZWaveDeviceEntity from homeassistant.components import zwave from homeassistant.components.zwave import async_setup_platform # noqa # pylint: disable=unused-import @@ -97,9 +97,10 @@ def close_cover(self, **kwargs): """Move the roller shutter down.""" self._network.manager.pressButton(self._close_id) - def set_cover_position(self, position, **kwargs): + def set_cover_position(self, **kwargs): """Move the roller shutter to a specific position.""" - self.node.set_dimmer(self.values.primary.value_id, position) + self.node.set_dimmer(self.values.primary.value_id, + kwargs.get(ATTR_POSITION)) def stop_cover(self, **kwargs): """Stop the roller shutter.""" @@ -139,11 +140,11 @@ def is_closed(self): """Return the current position of Zwave garage door.""" return not self._state - def close_cover(self): + def close_cover(self, **kwargs): """Close the garage door.""" self.values.primary.data = False - def open_cover(self): + def open_cover(self, **kwargs): """Open the garage door.""" self.values.primary.data = True @@ -166,10 +167,10 @@ def is_closed(self): """Return the current position of Zwave garage door.""" return self._state == "Closed" - def close_cover(self): + def close_cover(self, **kwargs): """Close the garage door.""" self.values.primary.data = "Closed" - def open_cover(self): + def open_cover(self, **kwargs): """Open the garage door.""" self.values.primary.data = "Opened" diff --git a/homeassistant/components/device_tracker/__init__.py b/homeassistant/components/device_tracker/__init__.py index 2adee1e2330591..3fa87ad697a40e 100644 --- a/homeassistant/components/device_tracker/__init__.py +++ b/homeassistant/components/device_tracker/__init__.py @@ -99,17 +99,17 @@ @bind_hass -def is_on(hass: HomeAssistantType, entity_id: str=None): +def is_on(hass: HomeAssistantType, entity_id: str = None): """Return the state if any or a specified device is home.""" entity = entity_id or ENTITY_ID_ALL_DEVICES return hass.states.is_state(entity, STATE_HOME) -def see(hass: HomeAssistantType, mac: str=None, dev_id: str=None, - host_name: str=None, location_name: str=None, - gps: GPSType=None, gps_accuracy=None, - battery=None, attributes: dict=None): +def see(hass: HomeAssistantType, mac: str = None, dev_id: str = None, + host_name: str = None, location_name: str = None, + gps: GPSType = None, gps_accuracy=None, + battery=None, attributes: dict = None): """Call service to notify you see device.""" data = {key: value for key, value in ((ATTR_MAC, mac), @@ -239,11 +239,11 @@ def __init__(self, hass: HomeAssistantType, consider_home: timedelta, _LOGGER.warning('Duplicate device MAC addresses detected %s', dev.mac) - def see(self, mac: str=None, dev_id: str=None, host_name: str=None, - location_name: str=None, gps: GPSType=None, gps_accuracy=None, - battery: str=None, attributes: dict=None, - source_type: str=SOURCE_TYPE_GPS, picture: str=None, - icon: str=None): + def see(self, mac: str = None, dev_id: str = None, host_name: str = None, + location_name: str = None, gps: GPSType = None, gps_accuracy=None, + battery: str = None, attributes: dict = None, + source_type: str = SOURCE_TYPE_GPS, picture: str = None, + icon: str = None): """Notify the device tracker that you see a device.""" self.hass.add_job( self.async_see(mac, dev_id, host_name, location_name, gps, @@ -252,11 +252,11 @@ def see(self, mac: str=None, dev_id: str=None, host_name: str=None, ) @asyncio.coroutine - def async_see(self, mac: str=None, dev_id: str=None, host_name: str=None, - location_name: str=None, gps: GPSType=None, - gps_accuracy=None, battery: str=None, attributes: dict=None, - source_type: str=SOURCE_TYPE_GPS, picture: str=None, - icon: str=None): + def async_see(self, mac: str = None, dev_id: str = None, + host_name: str = None, location_name: str = None, + gps: GPSType = None, gps_accuracy=None, battery: str = None, + attributes: dict = None, source_type: str = SOURCE_TYPE_GPS, + picture: str = None, icon: str = None): """Notify the device tracker that you see a device. This method is a coroutine. @@ -396,9 +396,9 @@ class Device(Entity): _state = STATE_NOT_HOME def __init__(self, hass: HomeAssistantType, consider_home: timedelta, - track: bool, dev_id: str, mac: str, name: str=None, - picture: str=None, gravatar: str=None, icon: str=None, - hide_if_away: bool=False, vendor: str=None) -> None: + track: bool, dev_id: str, mac: str, name: str = None, + picture: str = None, gravatar: str = None, icon: str = None, + hide_if_away: bool = False, vendor: str = None) -> None: """Initialize a device.""" self.hass = hass self.entity_id = ENTITY_ID_FORMAT.format(dev_id) @@ -475,9 +475,10 @@ def hidden(self): return self.away_hide and self.state != STATE_HOME @asyncio.coroutine - def async_seen(self, host_name: str=None, location_name: str=None, - gps: GPSType=None, gps_accuracy=0, battery: str=None, - attributes: dict=None, source_type: str=SOURCE_TYPE_GPS): + def async_seen(self, host_name: str = None, location_name: str = None, + gps: GPSType = None, gps_accuracy=0, battery: str = None, + attributes: dict = None, + source_type: str = SOURCE_TYPE_GPS): """Mark the device as seen.""" self.source_type = source_type self.last_seen = dt_util.utcnow() @@ -504,7 +505,7 @@ def async_seen(self, host_name: str=None, location_name: str=None, # pylint: disable=not-an-iterable yield from self.async_update() - def stale(self, now: dt_util.dt.datetime=None): + def stale(self, now: dt_util.dt.datetime = None): """Return if device state is stale. Async friendly. @@ -621,16 +622,16 @@ def async_scan_devices(self) -> Any: """ return self.hass.async_add_job(self.scan_devices) - def get_device_name(self, mac: str) -> str: - """Get device name from mac.""" + def get_device_name(self, device: str) -> str: + """Get the name of a device.""" raise NotImplementedError() - def async_get_device_name(self, mac: str) -> Any: - """Get device name from mac. + def async_get_device_name(self, device: str) -> Any: + """Get the name of a device. This method must be run in the event loop and returns a coroutine. """ - return self.hass.async_add_job(self.get_device_name, mac) + return self.hass.async_add_job(self.get_device_name, device) def load_config(path: str, hass: HomeAssistantType, consider_home: timedelta): diff --git a/homeassistant/components/device_tracker/automatic.py b/homeassistant/components/device_tracker/automatic.py index 5ad3995ad2a46a..9c04c6b40a54bb 100644 --- a/homeassistant/components/device_tracker/automatic.py +++ b/homeassistant/components/device_tracker/automatic.py @@ -177,10 +177,9 @@ def get(self, request): # pylint: disable=no-self-use _LOGGER.error( "Error authorizing Automatic: %s", params['error']) return response - else: - _LOGGER.error( - "Error authorizing Automatic. Invalid response returned") - return response + _LOGGER.error( + "Error authorizing Automatic. Invalid response returned") + return response if DATA_CONFIGURING not in hass.data or \ params['state'] not in hass.data[DATA_CONFIGURING]: diff --git a/homeassistant/components/device_tracker/bbox.py b/homeassistant/components/device_tracker/bbox.py index 23a94d093e246a..6d870364dcb641 100644 --- a/homeassistant/components/device_tracker/bbox.py +++ b/homeassistant/components/device_tracker/bbox.py @@ -45,10 +45,10 @@ def scan_devices(self): return [device.mac for device in self.last_results] - def get_device_name(self, mac): + def get_device_name(self, device): """Return the name of the given device or None if we don't know.""" - filter_named = [device.name for device in self.last_results if - device.mac == mac] + filter_named = [result.name for result in self.last_results if + result.mac == device] if filter_named: return filter_named[0] diff --git a/homeassistant/components/device_tracker/bluetooth_le_tracker.py b/homeassistant/components/device_tracker/bluetooth_le_tracker.py index 19582822913d2a..d9cda24b69930b 100644 --- a/homeassistant/components/device_tracker/bluetooth_le_tracker.py +++ b/homeassistant/components/device_tracker/bluetooth_le_tracker.py @@ -102,7 +102,7 @@ def update_ble(now): """Lookup Bluetooth LE devices and update status.""" devs = discover_ble_devices() for mac in devs_to_track: - _LOGGER.debug("Checking " + mac) + _LOGGER.debug("Checking %s", mac) result = mac in devs if not result: # Could not lookup device name diff --git a/homeassistant/components/device_tracker/bluetooth_tracker.py b/homeassistant/components/device_tracker/bluetooth_tracker.py index a535d87105ea53..9d41611d9a26b8 100644 --- a/homeassistant/components/device_tracker/bluetooth_tracker.py +++ b/homeassistant/components/device_tracker/bluetooth_tracker.py @@ -41,7 +41,7 @@ def discover_devices(): result = bluetooth.discover_devices( duration=8, lookup_names=True, flush_cache=True, lookup_class=False) - _LOGGER.debug("Bluetooth devices discovered = " + str(len(result))) + _LOGGER.debug("Bluetooth devices discovered = %d", len(result)) return result yaml_path = hass.config.path(YAML_DEVICES) diff --git a/homeassistant/components/device_tracker/fritz.py b/homeassistant/components/device_tracker/fritz.py index 58c23cb7d763b3..8c9d1988a71327 100644 --- a/homeassistant/components/device_tracker/fritz.py +++ b/homeassistant/components/device_tracker/fritz.py @@ -75,9 +75,9 @@ def scan_devices(self): active_hosts.append(known_host['mac']) return active_hosts - def get_device_name(self, mac): + def get_device_name(self, device): """Return the name of the given device or None if is not known.""" - ret = self.fritz_box.get_specific_host_entry(mac).get( + ret = self.fritz_box.get_specific_host_entry(device).get( 'NewHostName' ) if ret == {}: diff --git a/homeassistant/components/device_tracker/geofency.py b/homeassistant/components/device_tracker/geofency.py index 58d69f39a1dc2e..adb5c6f6d28dfa 100644 --- a/homeassistant/components/device_tracker/geofency.py +++ b/homeassistant/components/device_tracker/geofency.py @@ -120,8 +120,7 @@ def _device_name(data): """Return name of device tracker.""" if 'beaconUUID' in data: return "{}_{}".format(BEACON_DEV_PREFIX, data['name']) - else: - return data['device'] + return data['device'] @asyncio.coroutine def _set_location(self, hass, data, location_name): diff --git a/homeassistant/components/device_tracker/hitron_coda.py b/homeassistant/components/device_tracker/hitron_coda.py index 17dc34d1040118..aa437eeef860e1 100644 --- a/homeassistant/components/device_tracker/hitron_coda.py +++ b/homeassistant/components/device_tracker/hitron_coda.py @@ -60,11 +60,11 @@ def scan_devices(self): return [device.mac for device in self.last_results] - def get_device_name(self, mac): + def get_device_name(self, device): """Return the name of the device with the given MAC address.""" name = next(( - device.name for device in self.last_results - if device.mac == mac), None) + result.name for result in self.last_results + if result.mac == device), None) return name def _login(self): diff --git a/homeassistant/components/device_tracker/huawei_router.py b/homeassistant/components/device_tracker/huawei_router.py index 357dd0d36cfa66..775075b8a4aae9 100644 --- a/homeassistant/components/device_tracker/huawei_router.py +++ b/homeassistant/components/device_tracker/huawei_router.py @@ -86,6 +86,7 @@ def _update_info(self): active_clients = [client for client in data if client.state] self.last_results = active_clients + # pylint: disable=logging-not-lazy _LOGGER.debug("Active clients: " + "\n" .join((client.mac + " " + client.name) for client in active_clients)) diff --git a/homeassistant/components/device_tracker/keenetic_ndms2.py b/homeassistant/components/device_tracker/keenetic_ndms2.py index 5a7db36e4798ab..36dc1182a9294e 100644 --- a/homeassistant/components/device_tracker/keenetic_ndms2.py +++ b/homeassistant/components/device_tracker/keenetic_ndms2.py @@ -67,10 +67,10 @@ def scan_devices(self): return [device.mac for device in self.last_results] - def get_device_name(self, mac): + def get_device_name(self, device): """Return the name of the given device or None if we don't know.""" - filter_named = [device.name for device in self.last_results - if device.mac == mac] + filter_named = [result.name for result in self.last_results + if result.mac == device] if filter_named: return filter_named[0] diff --git a/homeassistant/components/device_tracker/linksys_ap.py b/homeassistant/components/device_tracker/linksys_ap.py index 20dc9052e116a3..8837b628b32650 100644 --- a/homeassistant/components/device_tracker/linksys_ap.py +++ b/homeassistant/components/device_tracker/linksys_ap.py @@ -62,7 +62,7 @@ def scan_devices(self): return self.last_results # pylint: disable=no-self-use - def get_device_name(self, mac): + def get_device_name(self, device): """ Return the name (if known) of the device. diff --git a/homeassistant/components/device_tracker/linksys_smart.py b/homeassistant/components/device_tracker/linksys_smart.py index 4bcbb600b8bdb2..c92f940f526370 100644 --- a/homeassistant/components/device_tracker/linksys_smart.py +++ b/homeassistant/components/device_tracker/linksys_smart.py @@ -45,9 +45,9 @@ def scan_devices(self): return self.last_results.keys() - def get_device_name(self, mac): + def get_device_name(self, device): """Return the name (if known) of the device.""" - return self.last_results.get(mac) + return self.last_results.get(device) def _update_info(self): """Check for connected devices.""" diff --git a/homeassistant/components/device_tracker/meraki.py b/homeassistant/components/device_tracker/meraki.py index 9437486a0aa0f0..9bbc6bf9ffed12 100644 --- a/homeassistant/components/device_tracker/meraki.py +++ b/homeassistant/components/device_tracker/meraki.py @@ -85,7 +85,7 @@ def post(self, request): return self.json_message('Invalid device type', HTTP_UNPROCESSABLE_ENTITY) _LOGGER.debug("Processing %s", data['type']) - if len(data["data"]["observations"]) == 0: + if not data["data"]["observations"]: _LOGGER.debug("No observations found") return self._handle(request.app['hass'], data) @@ -107,8 +107,7 @@ def _handle(self, hass, data): if lat == "NaN" or lng == "NaN": _LOGGER.debug( - "No coordinates received, skipping location for: " + mac - ) + "No coordinates received, skipping location for: %s", mac) gps_location = None accuracy = None else: diff --git a/homeassistant/components/device_tracker/mikrotik.py b/homeassistant/components/device_tracker/mikrotik.py index 1805559c2524b0..1d9161c0d45663 100644 --- a/homeassistant/components/device_tracker/mikrotik.py +++ b/homeassistant/components/device_tracker/mikrotik.py @@ -137,9 +137,9 @@ def scan_devices(self): self._update_info() return [device for device in self.last_results] - def get_device_name(self, mac): + def get_device_name(self, device): """Return the name of the given device or None if we don't know.""" - return self.last_results.get(mac) + return self.last_results.get(device) def _update_info(self): """Retrieve latest information from the Mikrotik box.""" diff --git a/homeassistant/components/device_tracker/netgear.py b/homeassistant/components/device_tracker/netgear.py index d2b8bc274ca3ae..25d5d38b2a7d01 100644 --- a/homeassistant/components/device_tracker/netgear.py +++ b/homeassistant/components/device_tracker/netgear.py @@ -70,11 +70,11 @@ def scan_devices(self): return (device.mac for device in self.last_results) - def get_device_name(self, mac): + def get_device_name(self, device): """Return the name of the given device or None if we don't know.""" try: - return next(device.name for device in self.last_results - if device.mac == mac) + return next(result.name for result in self.last_results + if result.mac == device) except StopIteration: return None diff --git a/homeassistant/components/device_tracker/nmap_tracker.py b/homeassistant/components/device_tracker/nmap_tracker.py index e9d70142ad11ec..3c3fd954a739b1 100644 --- a/homeassistant/components/device_tracker/nmap_tracker.py +++ b/homeassistant/components/device_tracker/nmap_tracker.py @@ -85,10 +85,10 @@ def scan_devices(self): return [device.mac for device in self.last_results] - def get_device_name(self, mac): + def get_device_name(self, device): """Return the name of the given device or None if we don't know.""" - filter_named = [device.name for device in self.last_results - if device.mac == mac] + filter_named = [result.name for result in self.last_results + if result.mac == device] if filter_named: return filter_named[0] diff --git a/homeassistant/components/device_tracker/tado.py b/homeassistant/components/device_tracker/tado.py index fca4998f7b5d52..dcf06036ea09e5 100644 --- a/homeassistant/components/device_tracker/tado.py +++ b/homeassistant/components/device_tracker/tado.py @@ -83,10 +83,10 @@ def async_scan_devices(self): return [device.mac for device in self.last_results] @asyncio.coroutine - def async_get_device_name(self, mac): + def async_get_device_name(self, device): """Return the name of the given device or None if we don't know.""" - filter_named = [device.name for device in self.last_results - if device.mac == mac] + filter_named = [result.name for result in self.last_results + if result.mac == device] if filter_named: return filter_named[0] diff --git a/homeassistant/components/device_tracker/ubus.py b/homeassistant/components/device_tracker/ubus.py index e66bb95a11a501..946aae5fe56a5e 100644 --- a/homeassistant/components/device_tracker/ubus.py +++ b/homeassistant/components/device_tracker/ubus.py @@ -96,11 +96,11 @@ def _generate_mac2name(self): raise NotImplementedError @_refresh_on_access_denied - def get_device_name(self, mac): + def get_device_name(self, device): """Return the name of the given device or None if we don't know.""" if self.mac2name is None: self._generate_mac2name() - name = self.mac2name.get(mac.upper(), None) + name = self.mac2name.get(device.upper(), None) return name @_refresh_on_access_denied diff --git a/homeassistant/components/device_tracker/unifi.py b/homeassistant/components/device_tracker/unifi.py index d5b6b044f1f1e5..59b538cd824a77 100644 --- a/homeassistant/components/device_tracker/unifi.py +++ b/homeassistant/components/device_tracker/unifi.py @@ -101,13 +101,13 @@ def scan_devices(self): self._update() return self._clients.keys() - def get_device_name(self, mac): + def get_device_name(self, device): """Return the name (if known) of the device. If a name has been set in Unifi, then return that, else return the hostname if it has been detected. """ - client = self._clients.get(mac, {}) + client = self._clients.get(device, {}) name = client.get('name') or client.get('hostname') - _LOGGER.debug("Device mac %s name %s", mac, name) + _LOGGER.debug("Device mac %s name %s", device, name) return name diff --git a/homeassistant/components/dominos.py b/homeassistant/components/dominos.py index 4bdb4c80add9aa..2c9f763aaa843d 100644 --- a/homeassistant/components/dominos.py +++ b/homeassistant/components/dominos.py @@ -140,21 +140,20 @@ def get_menu(self): if self.closest_store is None: _LOGGER.warning('Cannot get menu. Store may be closed') return [] - else: - menu = self.closest_store.get_menu() - product_entries = [] + menu = self.closest_store.get_menu() + product_entries = [] - for product in menu.products: - item = {} - if isinstance(product.menu_data['Variants'], list): - variants = ', '.join(product.menu_data['Variants']) - else: - variants = product.menu_data['Variants'] - item['name'] = product.name - item['variants'] = variants - product_entries.append(item) + for product in menu.products: + item = {} + if isinstance(product.menu_data['Variants'], list): + variants = ', '.join(product.menu_data['Variants']) + else: + variants = product.menu_data['Variants'] + item['name'] = product.name + item['variants'] = variants + product_entries.append(item) - return product_entries + return product_entries class DominosProductListView(http.HomeAssistantView): @@ -203,8 +202,7 @@ def state(self): """Return the state either closed, orderable or unorderable.""" if self.dominos.closest_store is None: return 'closed' - else: - return 'orderable' if self._orderable else 'unorderable' + return 'orderable' if self._orderable else 'unorderable' @Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self): diff --git a/homeassistant/components/fan/__init__.py b/homeassistant/components/fan/__init__.py index 6e6d377986d0cf..66790d0268729d 100644 --- a/homeassistant/components/fan/__init__.py +++ b/homeassistant/components/fan/__init__.py @@ -118,7 +118,7 @@ @bind_hass -def is_on(hass, entity_id: str=None) -> bool: +def is_on(hass, entity_id: str = None) -> bool: """Return if the fans are on based on the statemachine.""" entity_id = entity_id or ENTITY_ID_ALL_FANS state = hass.states.get(entity_id) @@ -126,7 +126,7 @@ def is_on(hass, entity_id: str=None) -> bool: @bind_hass -def turn_on(hass, entity_id: str=None, speed: str=None) -> None: +def turn_on(hass, entity_id: str = None, speed: str = None) -> None: """Turn all or specified fan on.""" data = { key: value for key, value in [ @@ -139,7 +139,7 @@ def turn_on(hass, entity_id: str=None, speed: str=None) -> None: @bind_hass -def turn_off(hass, entity_id: str=None) -> None: +def turn_off(hass, entity_id: str = None) -> None: """Turn all or specified fan off.""" data = {ATTR_ENTITY_ID: entity_id} if entity_id else {} @@ -147,7 +147,7 @@ def turn_off(hass, entity_id: str=None) -> None: @bind_hass -def toggle(hass, entity_id: str=None) -> None: +def toggle(hass, entity_id: str = None) -> None: """Toggle all or specified fans.""" data = { ATTR_ENTITY_ID: entity_id @@ -157,7 +157,8 @@ def toggle(hass, entity_id: str=None) -> None: @bind_hass -def oscillate(hass, entity_id: str=None, should_oscillate: bool=True) -> None: +def oscillate(hass, entity_id: str = None, + should_oscillate: bool = True) -> None: """Set oscillation on all or specified fan.""" data = { key: value for key, value in [ @@ -170,7 +171,7 @@ def oscillate(hass, entity_id: str=None, should_oscillate: bool=True) -> None: @bind_hass -def set_speed(hass, entity_id: str=None, speed: str=None) -> None: +def set_speed(hass, entity_id: str = None, speed: str = None) -> None: """Set speed for all or specified fan.""" data = { key: value for key, value in [ @@ -183,7 +184,7 @@ def set_speed(hass, entity_id: str=None, speed: str=None) -> None: @bind_hass -def set_direction(hass, entity_id: str=None, direction: str=None) -> None: +def set_direction(hass, entity_id: str = None, direction: str = None) -> None: """Set direction for all or specified fan.""" data = { key: value for key, value in [ @@ -258,11 +259,13 @@ def async_set_direction(self: ToggleEntity, direction: str): """ return self.hass.async_add_job(self.set_direction, direction) - def turn_on(self: ToggleEntity, speed: str=None, **kwargs) -> None: + # pylint: disable=arguments-differ + def turn_on(self: ToggleEntity, speed: str = None, **kwargs) -> None: """Turn on the fan.""" raise NotImplementedError() - def async_turn_on(self: ToggleEntity, speed: str=None, **kwargs): + # pylint: disable=arguments-differ + def async_turn_on(self: ToggleEntity, speed: str = None, **kwargs): """Turn on the fan. This method must be run in the event loop and returns a coroutine. diff --git a/homeassistant/components/fan/comfoconnect.py b/homeassistant/components/fan/comfoconnect.py index c6d1232801f695..12dc0b1104f29c 100644 --- a/homeassistant/components/fan/comfoconnect.py +++ b/homeassistant/components/fan/comfoconnect.py @@ -87,7 +87,7 @@ def speed_list(self): """List of available fan modes.""" return [SPEED_OFF, SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH] - def turn_on(self, speed: str=None, **kwargs) -> None: + def turn_on(self, speed: str = None, **kwargs) -> None: """Turn on the fan.""" if speed is None: speed = SPEED_LOW @@ -97,21 +97,21 @@ def turn_off(self, **kwargs) -> None: """Turn off the fan (to away).""" self.set_speed(SPEED_OFF) - def set_speed(self, mode): + def set_speed(self, speed: str): """Set fan speed.""" - _LOGGER.debug('Changing fan mode to %s.', mode) + _LOGGER.debug('Changing fan speed to %s.', speed) from pycomfoconnect import ( CMD_FAN_MODE_AWAY, CMD_FAN_MODE_LOW, CMD_FAN_MODE_MEDIUM, CMD_FAN_MODE_HIGH) - if mode == SPEED_OFF: + if speed == SPEED_OFF: self._ccb.comfoconnect.cmd_rmi_request(CMD_FAN_MODE_AWAY) - elif mode == SPEED_LOW: + elif speed == SPEED_LOW: self._ccb.comfoconnect.cmd_rmi_request(CMD_FAN_MODE_LOW) - elif mode == SPEED_MEDIUM: + elif speed == SPEED_MEDIUM: self._ccb.comfoconnect.cmd_rmi_request(CMD_FAN_MODE_MEDIUM) - elif mode == SPEED_HIGH: + elif speed == SPEED_HIGH: self._ccb.comfoconnect.cmd_rmi_request(CMD_FAN_MODE_HIGH) # Update current mode diff --git a/homeassistant/components/fan/demo.py b/homeassistant/components/fan/demo.py index bdb1b784c8bea3..b328ebb310174b 100644 --- a/homeassistant/components/fan/demo.py +++ b/homeassistant/components/fan/demo.py @@ -59,13 +59,13 @@ def speed_list(self) -> list: """Get the list of available speeds.""" return [STATE_OFF, SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH] - def turn_on(self, speed: str=None) -> None: + def turn_on(self, speed: str = None, **kwargs) -> None: """Turn on the entity.""" if speed is None: speed = SPEED_MEDIUM self.set_speed(speed) - def turn_off(self) -> None: + def turn_off(self, **kwargs) -> None: """Turn off the entity.""" self.oscillate(False) self.set_speed(STATE_OFF) diff --git a/homeassistant/components/fan/dyson.py b/homeassistant/components/fan/dyson.py index c5e5b8736ae713..5b689ece6ed20c 100644 --- a/homeassistant/components/fan/dyson.py +++ b/homeassistant/components/fan/dyson.py @@ -113,7 +113,7 @@ def set_speed(self: ToggleEntity, speed: str) -> None: self._device.set_configuration( fan_mode=FanMode.FAN, fan_speed=fan_speed) - def turn_on(self: ToggleEntity, speed: str=None, **kwargs) -> None: + def turn_on(self: ToggleEntity, speed: str = None, **kwargs) -> None: """Turn on the fan.""" from libpurecoollink.const import FanSpeed, FanMode diff --git a/homeassistant/components/fan/insteon_local.py b/homeassistant/components/fan/insteon_local.py index e6f9424d8529d2..b8a5c99add42cb 100644 --- a/homeassistant/components/fan/insteon_local.py +++ b/homeassistant/components/fan/insteon_local.py @@ -91,7 +91,7 @@ def supported_features(self): """Flag supported features.""" return SUPPORT_INSTEON_LOCAL - def turn_on(self: ToggleEntity, speed: str=None, **kwargs) -> None: + def turn_on(self: ToggleEntity, speed: str = None, **kwargs) -> None: """Turn device on.""" if speed is None: if ATTR_SPEED in kwargs: diff --git a/homeassistant/components/fan/isy994.py b/homeassistant/components/fan/isy994.py index 137bc400d0d95a..847ca3b325b2bc 100644 --- a/homeassistant/components/fan/isy994.py +++ b/homeassistant/components/fan/isy994.py @@ -48,10 +48,6 @@ def setup_platform(hass, config: ConfigType, class ISYFanDevice(ISYDevice, FanEntity): """Representation of an ISY994 fan device.""" - def __init__(self, node) -> None: - """Initialize the ISY994 fan device.""" - super().__init__(node) - @property def speed(self) -> str: """Return the current speed.""" @@ -66,7 +62,7 @@ def set_speed(self, speed: str) -> None: """Send the set speed command to the ISY994 fan device.""" self._node.on(val=STATE_TO_VALUE.get(speed, 255)) - def turn_on(self, speed: str=None, **kwargs) -> None: + def turn_on(self, speed: str = None, **kwargs) -> None: """Send the turn on command to the ISY994 fan device.""" self.set_speed(speed) @@ -99,7 +95,7 @@ def turn_off(self, **kwargs) -> None: if not self._actions.runThen(): _LOGGER.error("Unable to turn off the fan") - def turn_on(self, **kwargs) -> None: + def turn_on(self, speed: str = None, **kwargs) -> None: """Send the turn off command to ISY994 fan program.""" if not self._actions.runElse(): _LOGGER.error("Unable to turn on the fan") diff --git a/homeassistant/components/fan/mqtt.py b/homeassistant/components/fan/mqtt.py index 1ecbb12bcb4369..95ff587c613350 100644 --- a/homeassistant/components/fan/mqtt.py +++ b/homeassistant/components/fan/mqtt.py @@ -252,7 +252,7 @@ def oscillating(self): return self._oscillation @asyncio.coroutine - def async_turn_on(self, speed: str=None) -> None: + def async_turn_on(self, speed: str = None, **kwargs) -> None: """Turn on the entity. This method is a coroutine. @@ -264,7 +264,7 @@ def async_turn_on(self, speed: str=None) -> None: yield from self.async_set_speed(speed) @asyncio.coroutine - def async_turn_off(self) -> None: + def async_turn_off(self, **kwargs) -> None: """Turn off the entity. This method is a coroutine. diff --git a/homeassistant/components/fan/velbus.py b/homeassistant/components/fan/velbus.py index c0d125aa5ab6b1..e8208d1c9907a9 100644 --- a/homeassistant/components/fan/velbus.py +++ b/homeassistant/components/fan/velbus.py @@ -128,13 +128,13 @@ def speed_list(self): """Get the list of available speeds.""" return [STATE_OFF, SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH] - def turn_on(self, speed, **kwargs): + def turn_on(self, speed=None, **kwargs): """Turn on the entity.""" if speed is None: speed = SPEED_MEDIUM self.set_speed(speed) - def turn_off(self): + def turn_off(self, **kwargs): """Turn off the entity.""" self.set_speed(STATE_OFF) diff --git a/homeassistant/components/fan/wink.py b/homeassistant/components/fan/wink.py index 827f134cc08590..0cebd9cb9f8312 100644 --- a/homeassistant/components/fan/wink.py +++ b/homeassistant/components/fan/wink.py @@ -47,7 +47,7 @@ def set_speed(self: ToggleEntity, speed: str) -> None: """Set the speed of the fan.""" self.wink.set_state(True, speed) - def turn_on(self: ToggleEntity, speed: str=None, **kwargs) -> None: + def turn_on(self: ToggleEntity, speed: str = None, **kwargs) -> None: """Turn on the fan.""" self.wink.set_state(True, speed) diff --git a/homeassistant/components/fan/xiaomi_miio.py b/homeassistant/components/fan/xiaomi_miio.py index 942aff4ec5722b..2749bf298c0776 100644 --- a/homeassistant/components/fan/xiaomi_miio.py +++ b/homeassistant/components/fan/xiaomi_miio.py @@ -214,7 +214,7 @@ def _try_command(self, mask_error, func, *args, **kwargs): return False @asyncio.coroutine - def async_turn_on(self: ToggleEntity, speed: str=None, **kwargs) -> None: + def async_turn_on(self: ToggleEntity, speed: str = None, **kwargs) -> None: """Turn the fan on.""" if speed: # If operation mode was set the device must not be turned on. @@ -283,7 +283,7 @@ def speed(self): @asyncio.coroutine def async_set_speed(self: ToggleEntity, speed: str) -> None: """Set the speed of the fan.""" - _LOGGER.debug("Setting the operation mode to: " + speed) + _LOGGER.debug("Setting the operation mode to: %s", speed) from miio.airpurifier import OperationMode yield from self._try_command( @@ -333,7 +333,7 @@ def async_set_child_lock_off(self): self._air_purifier.set_child_lock, False) @asyncio.coroutine - def async_set_led_brightness(self, brightness: int=2): + def async_set_led_brightness(self, brightness: int = 2): """Set the led brightness.""" from miio.airpurifier import LedBrightness @@ -342,7 +342,7 @@ def async_set_led_brightness(self, brightness: int=2): self._air_purifier.set_led_brightness, LedBrightness(brightness)) @asyncio.coroutine - def async_set_favorite_level(self, level: int=1): + def async_set_favorite_level(self, level: int = 1): """Set the favorite level.""" yield from self._try_command( "Setting the favorite level of the air purifier failed.", diff --git a/homeassistant/components/http/ban.py b/homeassistant/components/http/ban.py index f636ad80c36e67..8423c53716b713 100644 --- a/homeassistant/components/http/ban.py +++ b/homeassistant/components/http/ban.py @@ -103,7 +103,7 @@ def process_wrong_login(request): class IpBan(object): """Represents banned IP address.""" - def __init__(self, ip_ban: str, banned_at: datetime=None) -> None: + def __init__(self, ip_ban: str, banned_at: datetime = None) -> None: """Initialize IP Ban object.""" self.ip_address = ip_address(ip_ban) self.banned_at = banned_at or datetime.utcnow() diff --git a/homeassistant/components/ihc/ihcdevice.py b/homeassistant/components/ihc/ihcdevice.py index 999dda420155ee..59f4d95f0a1f24 100644 --- a/homeassistant/components/ihc/ihcdevice.py +++ b/homeassistant/components/ihc/ihcdevice.py @@ -14,7 +14,7 @@ class IHCDevice(Entity): """ def __init__(self, ihc_controller, name, ihc_id: int, info: bool, - product: Element=None) -> None: + product: Element = None) -> None: """Initialize IHC attributes.""" self.ihc_controller = ihc_controller self._name = name diff --git a/homeassistant/components/isy994.py b/homeassistant/components/isy994.py index d85883e472af6c..04437d7055cc08 100644 --- a/homeassistant/components/isy994.py +++ b/homeassistant/components/isy994.py @@ -135,7 +135,7 @@ def _check_for_node_def(hass: HomeAssistant, node, - single_domain: str=None) -> bool: + single_domain: str = None) -> bool: """Check if the node matches the node_def_id for any domains. This is only present on the 5.0 ISY firmware, and is the most reliable @@ -157,7 +157,7 @@ def _check_for_node_def(hass: HomeAssistant, node, def _check_for_insteon_type(hass: HomeAssistant, node, - single_domain: str=None) -> bool: + single_domain: str = None) -> bool: """Check if the node matches the Insteon type for any domains. This is for (presumably) every version of the ISY firmware, but only @@ -180,7 +180,8 @@ def _check_for_insteon_type(hass: HomeAssistant, node, def _check_for_uom_id(hass: HomeAssistant, node, - single_domain: str=None, uom_list: list=None) -> bool: + single_domain: str = None, + uom_list: list = None) -> bool: """Check if a node's uom matches any of the domains uom filter. This is used for versions of the ISY firmware that report uoms as a single @@ -207,8 +208,8 @@ def _check_for_uom_id(hass: HomeAssistant, node, def _check_for_states_in_uom(hass: HomeAssistant, node, - single_domain: str=None, - states_list: list=None) -> bool: + single_domain: str = None, + states_list: list = None) -> bool: """Check if a list of uoms matches two possible filters. This is for versions of the ISY firmware that report uoms as a list of all @@ -302,24 +303,25 @@ def _categorize_programs(hass: HomeAssistant, programs: dict) -> None: pass else: for dtype, _, node_id in folder.children: - if dtype == KEY_FOLDER: - entity_folder = folder[node_id] - try: - status = entity_folder[KEY_STATUS] - assert status.dtype == 'program', 'Not a program' - if domain != 'binary_sensor': - actions = entity_folder[KEY_ACTIONS] - assert actions.dtype == 'program', 'Not a program' - else: - actions = None - except (AttributeError, KeyError, AssertionError): - _LOGGER.warning("Program entity '%s' not loaded due " - "to invalid folder structure.", - entity_folder.name) - continue - - entity = (entity_folder.name, status, actions) - hass.data[ISY994_PROGRAMS][domain].append(entity) + if dtype != KEY_FOLDER: + continue + entity_folder = folder[node_id] + try: + status = entity_folder[KEY_STATUS] + assert status.dtype == 'program', 'Not a program' + if domain != 'binary_sensor': + actions = entity_folder[KEY_ACTIONS] + assert actions.dtype == 'program', 'Not a program' + else: + actions = None + except (AttributeError, KeyError, AssertionError): + _LOGGER.warning("Program entity '%s' not loaded due " + "to invalid folder structure.", + entity_folder.name) + continue + + entity = (entity_folder.name, status, actions) + hass.data[ISY994_PROGRAMS][domain].append(entity) def _categorize_weather(hass: HomeAssistant, climate) -> None: @@ -461,8 +463,7 @@ def state(self): """Return the state of the ISY device.""" if self.is_unknown(): return None - else: - return super().state + return super().state @property def device_state_attributes(self) -> Dict: diff --git a/homeassistant/components/light/avion.py b/homeassistant/components/light/avion.py index 5344c3dce6df44..b4b9f4e777567c 100644 --- a/homeassistant/components/light/avion.py +++ b/homeassistant/components/light/avion.py @@ -37,7 +37,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): """Set up an Avion switch.""" - # pylint: disable=import-error + # pylint: disable=import-error, no-member import avion lights = [] @@ -70,7 +70,7 @@ class AvionLight(Light): def __init__(self, device): """Initialize the light.""" - # pylint: disable=import-error + # pylint: disable=import-error, no-member import avion self._name = device['name'] @@ -117,7 +117,7 @@ def assumed_state(self): def set_state(self, brightness): """Set the state of this lamp to the provided brightness.""" - # pylint: disable=import-error + # pylint: disable=import-error, no-member import avion # Bluetooth LE is unreliable, and the connection may drop at any diff --git a/homeassistant/components/light/blinkt.py b/homeassistant/components/light/blinkt.py index e331fba32c203a..db3171cf4cf488 100644 --- a/homeassistant/components/light/blinkt.py +++ b/homeassistant/components/light/blinkt.py @@ -29,7 +29,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the Blinkt Light platform.""" - # pylint: disable=import-error + # pylint: disable=import-error, no-member import blinkt # ensure that the lights are off when exiting diff --git a/homeassistant/components/light/decora.py b/homeassistant/components/light/decora.py index 03441dd8ea6c3c..c7478b435ee3e0 100644 --- a/homeassistant/components/light/decora.py +++ b/homeassistant/components/light/decora.py @@ -37,7 +37,7 @@ def retry(method): @wraps(method) def wrapper_retry(device, *args, **kwargs): """Try send command and retry on error.""" - # pylint: disable=import-error + # pylint: disable=import-error, no-member import decora import bluepy @@ -75,7 +75,7 @@ class DecoraLight(Light): def __init__(self, device): """Initialize the light.""" - # pylint: disable=import-error + # pylint: disable=import-error, no-member import decora self._name = device['name'] diff --git a/homeassistant/components/light/decora_wifi.py b/homeassistant/components/light/decora_wifi.py index 971ad21e84baaf..111d39f20190ac 100644 --- a/homeassistant/components/light/decora_wifi.py +++ b/homeassistant/components/light/decora_wifi.py @@ -36,7 +36,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the Decora WiFi platform.""" - # pylint: disable=import-error + # pylint: disable=import-error, no-member, no-name-in-module from decora_wifi import DecoraWiFiSession from decora_wifi.models.person import Person from decora_wifi.models.residential_account import ResidentialAccount @@ -93,8 +93,7 @@ def supported_features(self): """Return supported features.""" if self._switch.canSetLevel: return SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION - else: - return 0 + return 0 @property def name(self): diff --git a/homeassistant/components/light/hive.py b/homeassistant/components/light/hive.py index 5ba162a20d2a64..e57bdf2c04625b 100644 --- a/homeassistant/components/light/hive.py +++ b/homeassistant/components/light/hive.py @@ -116,7 +116,7 @@ def turn_on(self, **kwargs): for entity in self.session.entities: entity.handle_update(self.data_updatesource) - def turn_off(self): + def turn_off(self, **kwargs): """Instruct the light to turn off.""" self.session.light.turn_off(self.node_id) for entity in self.session.entities: diff --git a/homeassistant/components/light/hue.py b/homeassistant/components/light/hue.py index 07ba069d831838..ffca48743e9090 100644 --- a/homeassistant/components/light/hue.py +++ b/homeassistant/components/light/hue.py @@ -91,7 +91,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): if discovery_info is None or 'bridge_id' not in discovery_info: return - if config is not None and len(config) > 0: + if config is not None and config: # Legacy configuration, will be removed in 0.60 config_str = yaml.dump([config]) # Indent so it renders in a fixed-width font diff --git a/homeassistant/components/light/ihc.py b/homeassistant/components/light/ihc.py index ead0f1535625d6..c9ceda8651ac46 100644 --- a/homeassistant/components/light/ihc.py +++ b/homeassistant/components/light/ihc.py @@ -64,7 +64,7 @@ class IhcLight(IHCDevice, Light): """ def __init__(self, ihc_controller, name, ihc_id: int, info: bool, - dimmable=False, product: Element=None) -> None: + dimmable=False, product: Element = None) -> None: """Initialize the light.""" super().__init__(ihc_controller, name, ihc_id, info, product) self._brightness = 0 diff --git a/homeassistant/components/light/isy994.py b/homeassistant/components/light/isy994.py index cee8155c32248f..d2ed865892e6f5 100644 --- a/homeassistant/components/light/isy994.py +++ b/homeassistant/components/light/isy994.py @@ -29,10 +29,6 @@ def setup_platform(hass, config: ConfigType, class ISYLightDevice(ISYDevice, Light): """Representation of an ISY994 light device.""" - def __init__(self, node: object) -> None: - """Initialize the ISY994 light device.""" - super().__init__(node) - @property def is_on(self) -> bool: """Get whether the ISY994 light is on.""" @@ -48,6 +44,7 @@ def turn_off(self, **kwargs) -> None: if not self._node.off(): _LOGGER.debug("Unable to turn off light") + # pylint: disable=arguments-differ def turn_on(self, brightness=None, **kwargs) -> None: """Send the turn on command to the ISY994 light device.""" if not self._node.on(val=brightness): diff --git a/homeassistant/components/light/limitlessled.py b/homeassistant/components/light/limitlessled.py index 0c6b1143bbd308..94c02577a6b16d 100644 --- a/homeassistant/components/light/limitlessled.py +++ b/homeassistant/components/light/limitlessled.py @@ -198,6 +198,7 @@ def brightness(self): """Return the brightness property.""" return self._brightness + # pylint: disable=arguments-differ @state(False) def turn_off(self, transition_time, pipeline, **kwargs): """Turn off a group.""" @@ -231,6 +232,7 @@ def supported_features(self): """Flag supported features.""" return SUPPORT_LIMITLESSLED_WHITE + # pylint: disable=arguments-differ @state(True) def turn_on(self, transition_time, pipeline, **kwargs): """Turn on (or adjust property of) a group.""" @@ -271,6 +273,7 @@ def supported_features(self): """Flag supported features.""" return SUPPORT_LIMITLESSLED_RGB + # pylint: disable=arguments-differ @state(True) def turn_on(self, transition_time, pipeline, **kwargs): """Turn on (or adjust property of) a group.""" @@ -337,6 +340,7 @@ def supported_features(self): """Flag supported features.""" return SUPPORT_LIMITLESSLED_RGBWW + # pylint: disable=arguments-differ @state(True) def turn_on(self, transition_time, pipeline, **kwargs): """Turn on (or adjust property of) a group.""" diff --git a/homeassistant/components/light/mysensors.py b/homeassistant/components/light/mysensors.py index 9a48b13ed3b197..a37553017e7e10 100644 --- a/homeassistant/components/light/mysensors.py +++ b/homeassistant/components/light/mysensors.py @@ -130,7 +130,7 @@ def _turn_on_rgb_and_w(self, hex_template, **kwargs): self._white = white self._values[self.value_type] = hex_color - def turn_off(self): + def turn_off(self, **kwargs): """Turn the device off.""" value_type = self.gateway.const.SetReq.V_LIGHT self.gateway.set_child_value( diff --git a/homeassistant/components/light/tplink.py b/homeassistant/components/light/tplink.py index 6aee02ee914f81..f87d624b83aafd 100644 --- a/homeassistant/components/light/tplink.py +++ b/homeassistant/components/light/tplink.py @@ -118,7 +118,7 @@ def turn_on(self, **kwargs): rgb = kwargs.get(ATTR_RGB_COLOR) self.smartbulb.hsv = rgb_to_hsv(rgb) - def turn_off(self): + def turn_off(self, **kwargs): """Turn the light off.""" self.smartbulb.state = self.smartbulb.BULB_STATE_OFF diff --git a/homeassistant/components/light/wink.py b/homeassistant/components/light/wink.py index 02605d24faf8f1..e329fa04837dbf 100644 --- a/homeassistant/components/light/wink.py +++ b/homeassistant/components/light/wink.py @@ -118,6 +118,6 @@ def turn_on(self, **kwargs): self.wink.set_state(True, **state_kwargs) - def turn_off(self): + def turn_off(self, **kwargs): """Turn the switch off.""" self.wink.set_state(False) diff --git a/homeassistant/components/light/xiaomi_miio.py b/homeassistant/components/light/xiaomi_miio.py index a3c5fa9f62ea21..06d585b8593243 100644 --- a/homeassistant/components/light/xiaomi_miio.py +++ b/homeassistant/components/light/xiaomi_miio.py @@ -242,7 +242,7 @@ def async_update(self): _LOGGER.error("Got exception while fetching the state: %s", ex) @asyncio.coroutine - def async_set_scene(self, scene: int=1): + def async_set_scene(self, scene: int = 1): """Set the fixed scene.""" yield from self._try_command( "Setting a fixed scene failed.", @@ -260,10 +260,6 @@ def translate(value, left_min, left_max, right_min, right_max): class XiaomiPhilipsLightBall(XiaomiPhilipsGenericLight, Light): """Representation of a Xiaomi Philips Light Ball.""" - def __init__(self, name, light, device_info): - """Initialize the light device.""" - super().__init__(name, light, device_info) - @property def color_temp(self): """Return the color temperature.""" @@ -345,10 +341,6 @@ def async_update(self): class XiaomiPhilipsCeilingLamp(XiaomiPhilipsLightBall, Light): """Representation of a Xiaomi Philips Ceiling Lamp.""" - def __init__(self, name, light, device_info): - """Initialize the light device.""" - super().__init__(name, light, device_info) - @property def min_mireds(self): """Return the coldest color_temp that this light supports.""" @@ -363,6 +355,4 @@ def max_mireds(self): class XiaomiPhilipsEyecareLamp(XiaomiPhilipsGenericLight, Light): """Representation of a Xiaomi Philips Eyecare Lamp 2.""" - def __init__(self, name, light, device_info): - """Initialize the light device.""" - super().__init__(name, light, device_info) + pass diff --git a/homeassistant/components/lirc.py b/homeassistant/components/lirc.py index ea4df658ef6553..0cd49ab6c9a322 100644 --- a/homeassistant/components/lirc.py +++ b/homeassistant/components/lirc.py @@ -4,7 +4,7 @@ For more details about this component, please refer to the documentation at https://home-assistant.io/components/lirc/ """ -# pylint: disable=import-error +# pylint: disable=import-error,no-member import threading import time import logging diff --git a/homeassistant/components/lock/isy994.py b/homeassistant/components/lock/isy994.py index 33e2a0bea251d0..50371fdc9ae8fb 100644 --- a/homeassistant/components/lock/isy994.py +++ b/homeassistant/components/lock/isy994.py @@ -53,8 +53,7 @@ def state(self) -> str: """Get the state of the lock.""" if self.is_unknown(): return None - else: - return VALUE_TO_STATE.get(self.value, STATE_UNKNOWN) + return VALUE_TO_STATE.get(self.value, STATE_UNKNOWN) def lock(self, **kwargs) -> None: """Send the lock command to the ISY994 device.""" diff --git a/homeassistant/components/media_extractor.py b/homeassistant/components/media_extractor.py index f712007ccecd63..a2ec11cc948659 100644 --- a/homeassistant/components/media_extractor.py +++ b/homeassistant/components/media_extractor.py @@ -85,7 +85,7 @@ def extract_and_send(self): else: entities = self.get_entities() - if len(entities) == 0: + if not entities: self.call_media_player_service(stream_selector, None) for entity_id in entities: @@ -108,7 +108,7 @@ def get_stream_selector(self): _LOGGER.warning( "Playlists are not supported, looking for the first video") entries = list(all_media['entries']) - if len(entries) > 0: + if entries: selected_media = entries[0] else: _LOGGER.error("Playlist is empty") diff --git a/homeassistant/components/media_player/aquostv.py b/homeassistant/components/media_player/aquostv.py index ae6d9e04643b1e..6933286f0fe584 100644 --- a/homeassistant/components/media_player/aquostv.py +++ b/homeassistant/components/media_player/aquostv.py @@ -201,9 +201,9 @@ def volume_down(self): self._remote.volume(int(self._volume * 60) - 2) @_retry - def set_volume_level(self, level): + def set_volume_level(self, volume): """Set Volume media player.""" - self._remote.volume(int(level * 60)) + self._remote.volume(int(volume * 60)) @_retry def mute_volume(self, mute): diff --git a/homeassistant/components/media_player/bluesound.py b/homeassistant/components/media_player/bluesound.py index 848c6abe91f851..d7664d68ce5245 100644 --- a/homeassistant/components/media_player/bluesound.py +++ b/homeassistant/components/media_player/bluesound.py @@ -440,8 +440,7 @@ def state(self): return STATE_PAUSED elif status == 'stream' or status == 'play': return STATE_PLAYING - else: - return STATE_IDLE + return STATE_IDLE @property def media_title(self): @@ -595,7 +594,7 @@ def source(self): # But it works with radio service_items will catch playlists. items = [x for x in self._preset_items if 'url2' in x and parse.unquote(x['url2']) == stream_url] - if len(items) > 0: + if items: return items[0]['title'] # This could be a bit difficult to detect. Bluetooth could be named @@ -606,11 +605,11 @@ def source(self): if title == 'bluetooth' or stream_url == 'Capture:hw:2,0/44100/16/2': items = [x for x in self._capture_items if x['url'] == "Capture%3Abluez%3Abluetooth"] - if len(items) > 0: + if items: return items[0]['title'] items = [x for x in self._capture_items if x['url'] == stream_url] - if len(items) > 0: + if items: return items[0]['title'] if stream_url[:8] == 'Capture:': @@ -631,12 +630,12 @@ def source(self): items = [x for x in self._capture_items if x['name'] == current_service] - if len(items) > 0: + if items: return items[0]['title'] items = [x for x in self._services_items if x['name'] == current_service] - if len(items) > 0: + if items: return items[0]['title'] if self._status.get('streamUrl', '') != '': diff --git a/homeassistant/components/media_player/hdmi_cec.py b/homeassistant/components/media_player/hdmi_cec.py index e1fffefed1890c..f5b4cbd48546b8 100644 --- a/homeassistant/components/media_player/hdmi_cec.py +++ b/homeassistant/components/media_player/hdmi_cec.py @@ -87,7 +87,7 @@ def media_stop(self): self.send_keypress(KEY_STOP) self._state = STATE_IDLE - def play_media(self, media_type, media_id): + def play_media(self, media_type, media_id, **kwargs): """Not supported.""" raise NotImplementedError() diff --git a/homeassistant/components/media_player/mpd.py b/homeassistant/components/media_player/mpd.py index 4307b68e709dfd..81a18ab93c5389 100644 --- a/homeassistant/components/media_player/mpd.py +++ b/homeassistant/components/media_player/mpd.py @@ -182,8 +182,7 @@ def media_title(self): if name is None and title is None: if file_name is None: return "None" - else: - return os.path.basename(file_name) + return os.path.basename(file_name) elif name is None: return title elif title is None: diff --git a/homeassistant/components/media_player/soundtouch.py b/homeassistant/components/media_player/soundtouch.py index e4c3fa623c9543..9c4a0e9fa17e1c 100644 --- a/homeassistant/components/media_player/soundtouch.py +++ b/homeassistant/components/media_player/soundtouch.py @@ -296,7 +296,7 @@ def media_album_name(self): def play_media(self, media_type, media_id, **kwargs): """Play a piece of media.""" - _LOGGER.debug("Starting media with media_id: " + str(media_id)) + _LOGGER.debug("Starting media with media_id: %s", media_id) if re.match(r'http://', str(media_id)): # URL _LOGGER.debug("Playing URL %s", str(media_id)) @@ -307,11 +307,10 @@ def play_media(self, media_type, media_id, **kwargs): preset = next([preset for preset in presets if preset.preset_id == str(media_id)].__iter__(), None) if preset is not None: - _LOGGER.debug("Playing preset: " + preset.name) + _LOGGER.debug("Playing preset: %s", preset.name) self._device.select_preset(preset) else: - _LOGGER.warning( - "Unable to find preset with id " + str(media_id)) + _LOGGER.warning("Unable to find preset with id %s", media_id) def create_zone(self, slaves): """ @@ -323,8 +322,8 @@ def create_zone(self, slaves): if not slaves: _LOGGER.warning("Unable to create zone without slaves") else: - _LOGGER.info( - "Creating zone with master " + str(self.device.config.name)) + _LOGGER.info("Creating zone with master %s", + self.device.config.name) self.device.create_zone([slave.device for slave in slaves]) def remove_zone_slave(self, slaves): @@ -341,8 +340,8 @@ def remove_zone_slave(self, slaves): if not slaves: _LOGGER.warning("Unable to find slaves to remove") else: - _LOGGER.info("Removing slaves from zone with master " + - str(self.device.config.name)) + _LOGGER.info("Removing slaves from zone with master %s", + self.device.config.name) self.device.remove_zone_slave([slave.device for slave in slaves]) def add_zone_slave(self, slaves): @@ -357,7 +356,6 @@ def add_zone_slave(self, slaves): if not slaves: _LOGGER.warning("Unable to find slaves to add") else: - _LOGGER.info( - "Adding slaves to zone with master " + str( - self.device.config.name)) + _LOGGER.info("Adding slaves to zone with master %s", + self.device.config.name) self.device.add_zone_slave([slave.device for slave in slaves]) diff --git a/homeassistant/components/media_player/webostv.py b/homeassistant/components/media_player/webostv.py index 3ccd3c7dbe9252..acd1ffad6eb469 100644 --- a/homeassistant/components/media_player/webostv.py +++ b/homeassistant/components/media_player/webostv.py @@ -270,8 +270,7 @@ def media_title(self): """Title of current playing media.""" if (self._channel is not None) and ('channelName' in self._channel): return self._channel['channelName'] - else: - return None + return None @property def media_image_url(self): diff --git a/homeassistant/components/notify/html5.py b/homeassistant/components/notify/html5.py index f2611cf65d3972..5d41004ba1dcc2 100644 --- a/homeassistant/components/notify/html5.py +++ b/homeassistant/components/notify/html5.py @@ -136,7 +136,7 @@ def _load_config(filename): class JSONBytesDecoder(json.JSONEncoder): """JSONEncoder to decode bytes objects to unicode.""" - # pylint: disable=method-hidden + # pylint: disable=method-hidden, arguments-differ def default(self, obj): """Decode object if it's a bytes object, else defer to base class.""" if isinstance(obj, bytes): diff --git a/homeassistant/components/notify/llamalab_automate.py b/homeassistant/components/notify/llamalab_automate.py index 606c0fafc8b805..0ddcb450bcf7d0 100644 --- a/homeassistant/components/notify/llamalab_automate.py +++ b/homeassistant/components/notify/llamalab_automate.py @@ -56,4 +56,4 @@ def send_message(self, message="", **kwargs): response = requests.post(_RESOURCE, json=data) if response.status_code != 200: - _LOGGER.error("Error sending message: " + str(response)) + _LOGGER.error("Error sending message: %s", response) diff --git a/homeassistant/components/plant.py b/homeassistant/components/plant.py index 24b8c682d02e6f..048851e97f5420 100644 --- a/homeassistant/components/plant.py +++ b/homeassistant/components/plant.py @@ -9,6 +9,7 @@ from collections import deque import voluptuous as vol +from homeassistant.exceptions import HomeAssistantError from homeassistant.const import ( STATE_OK, STATE_PROBLEM, STATE_UNKNOWN, TEMP_CELSIUS, ATTR_TEMPERATURE, CONF_SENSORS, ATTR_UNIT_OF_MEASUREMENT) @@ -198,8 +199,8 @@ def state_changed(self, entity_id, _, new_state): self._brightness_history.add_measurement(self._brightness, new_state.last_updated) else: - raise _LOGGER.error("Unknown reading from sensor %s: %s", - entity_id, value) + raise HomeAssistantError( + "Unknown reading from sensor {}: {}".format(entity_id, value)) if ATTR_UNIT_OF_MEASUREMENT in new_state.attributes: self._unit_of_measurement[reading] = \ new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) diff --git a/homeassistant/components/python_script.py b/homeassistant/components/python_script.py index b49b280791affc..dedc39ef3a2762 100644 --- a/homeassistant/components/python_script.py +++ b/homeassistant/components/python_script.py @@ -208,5 +208,4 @@ def wrapper(*args, **kw): """Wrap to return callable method if callable.""" return attribute(*args, **kw) return wrapper - else: - return attribute + return attribute diff --git a/homeassistant/components/raspihats.py b/homeassistant/components/raspihats.py index e3c1ab8ff88bb4..3bc45eab34ece4 100644 --- a/homeassistant/components/raspihats.py +++ b/homeassistant/components/raspihats.py @@ -4,6 +4,7 @@ For more details about this component, please refer to the documentation at https://home-assistant.io/components/raspihats/ """ +# pylint: disable=import-error,no-name-in-module import logging import threading import time @@ -143,7 +144,6 @@ def register_board(self, board, address): def run(self): """Keep alive for I2C-HATs.""" - # pylint: disable=import-error from raspihats.i2c_hats import ResponseException _LOGGER.info(log_message(self, "starting")) @@ -206,7 +206,6 @@ def register_online_callback(self, address, channel, callback): def read_di(self, address, channel): """Read a value from a I2C-HAT digital input.""" - # pylint: disable=import-error from raspihats.i2c_hats import ResponseException with self._lock: @@ -219,7 +218,6 @@ def read_di(self, address, channel): def write_dq(self, address, channel, value): """Write a value to a I2C-HAT digital output.""" - # pylint: disable=import-error from raspihats.i2c_hats import ResponseException with self._lock: @@ -231,7 +229,6 @@ def write_dq(self, address, channel, value): def read_dq(self, address, channel): """Read a value from a I2C-HAT digital output.""" - # pylint: disable=import-error from raspihats.i2c_hats import ResponseException with self._lock: diff --git a/homeassistant/components/recorder/__init__.py b/homeassistant/components/recorder/__init__.py index b2628f954fc68a..09922665ae152e 100644 --- a/homeassistant/components/recorder/__init__.py +++ b/homeassistant/components/recorder/__init__.py @@ -94,7 +94,7 @@ def wait_connection_ready(hass): return hass.data[DATA_INSTANCE].async_db_ready -def run_information(hass, point_in_time: Optional[datetime]=None): +def run_information(hass, point_in_time: Optional[datetime] = None): """Return information about current run. There is also the run that covers point_in_time. diff --git a/homeassistant/components/remote/harmony.py b/homeassistant/components/remote/harmony.py index 39f09ea66a2f37..ae48f26998698c 100644 --- a/homeassistant/components/remote/harmony.py +++ b/homeassistant/components/remote/harmony.py @@ -207,6 +207,7 @@ def turn_off(self, **kwargs): """Start the PowerOff activity.""" self._client.power_off() + # pylint: disable=arguments-differ def send_command(self, commands, **kwargs): """Send a list of commands to one device.""" device = kwargs.get(ATTR_DEVICE) diff --git a/homeassistant/components/remote/xiaomi_miio.py b/homeassistant/components/remote/xiaomi_miio.py index aa05246c9cd729..3f5234dd8f21e4 100644 --- a/homeassistant/components/remote/xiaomi_miio.py +++ b/homeassistant/components/remote/xiaomi_miio.py @@ -210,8 +210,7 @@ def device_state_attributes(self): """Hide remote by default.""" if self._is_hidden: return {'hidden': 'true'} - else: - return + return # pylint: disable=R0201 @asyncio.coroutine diff --git a/homeassistant/components/rflink.py b/homeassistant/components/rflink.py index d97d4f38f0276b..db35b8caf9fc57 100644 --- a/homeassistant/components/rflink.py +++ b/homeassistant/components/rflink.py @@ -8,9 +8,10 @@ from collections import defaultdict import functools as ft import logging - import async_timeout +import voluptuous as vol + from homeassistant.const import ( ATTR_ENTITY_ID, CONF_COMMAND, CONF_HOST, CONF_PORT, EVENT_HOMEASSISTANT_STOP, STATE_UNKNOWN) @@ -19,7 +20,6 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.deprecation import get_deprecated from homeassistant.helpers.entity import Entity -import voluptuous as vol REQUIREMENTS = ['rflink==0.0.34'] diff --git a/homeassistant/components/rfxtrx.py b/homeassistant/components/rfxtrx.py index de8a0c00d80ce5..e7301836d7efde 100644 --- a/homeassistant/components/rfxtrx.py +++ b/homeassistant/components/rfxtrx.py @@ -188,8 +188,8 @@ def find_possible_pt2262_device(device_id): for dev_id, device in RFX_DEVICES.items(): if hasattr(device, 'is_lighting4') and len(dev_id) == len(device_id): size = None - for i in range(0, len(dev_id)): - if dev_id[i] != device_id[i]: + for i, (char1, char2) in enumerate(zip(dev_id, device_id)): + if char1 != char2: break size = i diff --git a/homeassistant/components/ring.py b/homeassistant/components/ring.py index 62bd07d2c27f4e..6e70ddb244de94 100644 --- a/homeassistant/components/ring.py +++ b/homeassistant/components/ring.py @@ -5,13 +5,13 @@ https://home-assistant.io/components/ring/ """ import logging +from requests.exceptions import HTTPError, ConnectTimeout + import voluptuous as vol -import homeassistant.helpers.config_validation as cv +import homeassistant.helpers.config_validation as cv from homeassistant.const import CONF_USERNAME, CONF_PASSWORD -from requests.exceptions import HTTPError, ConnectTimeout - REQUIREMENTS = ['ring_doorbell==0.1.8'] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/scene/deconz.py b/homeassistant/components/scene/deconz.py index 067db1f93a3eac..b3400c306afca5 100644 --- a/homeassistant/components/scene/deconz.py +++ b/homeassistant/components/scene/deconz.py @@ -34,7 +34,7 @@ def __init__(self, scene): self._scene = scene @asyncio.coroutine - def async_activate(self, **kwargs): + def async_activate(self): """Activate the scene.""" yield from self._scene.async_set_state({}) diff --git a/homeassistant/components/scene/litejet.py b/homeassistant/components/scene/litejet.py index 432ce060774bfc..b8f3a82c0e301d 100644 --- a/homeassistant/components/scene/litejet.py +++ b/homeassistant/components/scene/litejet.py @@ -54,6 +54,6 @@ def device_state_attributes(self): ATTR_NUMBER: self._index } - def activate(self, **kwargs): + def activate(self): """Activate the scene.""" self._lj.activate_scene(self._index) diff --git a/homeassistant/components/scene/lutron_caseta.py b/homeassistant/components/scene/lutron_caseta.py index 53df0da76174e5..5f96e12632147b 100644 --- a/homeassistant/components/scene/lutron_caseta.py +++ b/homeassistant/components/scene/lutron_caseta.py @@ -53,6 +53,6 @@ def is_on(self): return False @asyncio.coroutine - def async_activate(self, **kwargs): + def async_activate(self): """Activate the scene.""" self._bridge.activate_scene(self._scene_id) diff --git a/homeassistant/components/scene/velux.py b/homeassistant/components/scene/velux.py index 9da7a6621173e6..8c87b434471f3e 100644 --- a/homeassistant/components/scene/velux.py +++ b/homeassistant/components/scene/velux.py @@ -48,6 +48,6 @@ def is_on(self): """There is no way of detecting if a scene is active (yet).""" return False - def activate(self, **kwargs): + def activate(self): """Activate the scene.""" self.hass.async_add_job(self.scene.run()) diff --git a/homeassistant/components/scene/vera.py b/homeassistant/components/scene/vera.py index 3dbb68d214fc63..24dfaef1fb1f42 100644 --- a/homeassistant/components/scene/vera.py +++ b/homeassistant/components/scene/vera.py @@ -40,7 +40,7 @@ def update(self): """Update the scene status.""" self.vera_scene.refresh() - def activate(self, **kwargs): + def activate(self): """Activate the scene.""" self.vera_scene.activate() diff --git a/homeassistant/components/scene/wink.py b/homeassistant/components/scene/wink.py index 2d4a6d0621c580..0f617511818db5 100644 --- a/homeassistant/components/scene/wink.py +++ b/homeassistant/components/scene/wink.py @@ -43,6 +43,6 @@ def is_on(self): """Python-wink will always return False.""" return self.wink.state() - def activate(self, **kwargs): + def activate(self): """Activate the scene.""" self.wink.activate() diff --git a/homeassistant/components/sensor/bme680.py b/homeassistant/components/sensor/bme680.py index 470d7749ea2564..2dbda26ac32312 100644 --- a/homeassistant/components/sensor/bme680.py +++ b/homeassistant/components/sensor/bme680.py @@ -116,7 +116,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None): return -# pylint: disable=import-error +# pylint: disable=import-error, no-member def _setup_bme680(config): """Set up and configure the BME680 sensor.""" from smbus import SMBus diff --git a/homeassistant/components/sensor/cups.py b/homeassistant/components/sensor/cups.py index f4d826c250d170..7c1d9fc3d49cd8 100644 --- a/homeassistant/components/sensor/cups.py +++ b/homeassistant/components/sensor/cups.py @@ -128,7 +128,7 @@ def update(self): self._printer = self.data.printers.get(self._name) -# pylint: disable=import-error +# pylint: disable=import-error, no-name-in-module class CupsData(object): """Get the latest data from CUPS and update the state.""" diff --git a/homeassistant/components/sensor/dovado.py b/homeassistant/components/sensor/dovado.py index eba6596efc4dcf..ee2292d412215e 100644 --- a/homeassistant/components/sensor/dovado.py +++ b/homeassistant/components/sensor/dovado.py @@ -79,7 +79,7 @@ def setup(self, hass, config, add_devices): def send_sms(service): """Send SMS through the router.""" - number = service.data.get('number'), + number = service.data.get('number') message = service.data.get('message') _LOGGER.debug("message for %s: %s", number, message) self._dovado.send_sms(number, message) diff --git a/homeassistant/components/sensor/dsmr.py b/homeassistant/components/sensor/dsmr.py index 32c888bad3bc09..e712f5b3751f9a 100644 --- a/homeassistant/components/sensor/dsmr.py +++ b/homeassistant/components/sensor/dsmr.py @@ -9,13 +9,14 @@ from functools import partial import logging +import voluptuous as vol + from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.const import ( CONF_HOST, CONF_PORT, EVENT_HOMEASSISTANT_STOP, STATE_UNKNOWN) from homeassistant.core import CoreState import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity -import voluptuous as vol _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/sensor/dwd_weather_warnings.py b/homeassistant/components/sensor/dwd_weather_warnings.py index 0eeaa9424e8228..d718349418146a 100644 --- a/homeassistant/components/sensor/dwd_weather_warnings.py +++ b/homeassistant/components/sensor/dwd_weather_warnings.py @@ -137,11 +137,11 @@ def device_state_attributes(self): data['warning_{}_name'.format(i)] = event['event'] data['warning_{}_level'.format(i)] = event['level'] data['warning_{}_type'.format(i)] = event['type'] - if len(event['headline']) > 0: + if event['headline']: data['warning_{}_headline'.format(i)] = event['headline'] - if len(event['description']) > 0: + if event['description']: data['warning_{}_description'.format(i)] = event['description'] - if len(event['instruction']) > 0: + if event['instruction']: data['warning_{}_instruction'.format(i)] = event['instruction'] if event['start'] is not None: diff --git a/homeassistant/components/sensor/fritzbox_netmonitor.py b/homeassistant/components/sensor/fritzbox_netmonitor.py index c7486b56c25537..f4f774cad1e89e 100644 --- a/homeassistant/components/sensor/fritzbox_netmonitor.py +++ b/homeassistant/components/sensor/fritzbox_netmonitor.py @@ -6,6 +6,7 @@ """ import logging from datetime import timedelta +from requests.exceptions import RequestException import voluptuous as vol @@ -15,8 +16,6 @@ import homeassistant.helpers.config_validation as cv from homeassistant.util import Throttle -from requests.exceptions import RequestException - REQUIREMENTS = ['fritzconnection==0.6.5'] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/sensor/hp_ilo.py b/homeassistant/components/sensor/hp_ilo.py index 016d68b3b0ee9d..387d0fae5a07c6 100644 --- a/homeassistant/components/sensor/hp_ilo.py +++ b/homeassistant/components/sensor/hp_ilo.py @@ -172,4 +172,4 @@ def update(self): password=self._password, port=self._port) except (hpilo.IloError, hpilo.IloCommunicationError, hpilo.IloLoginFailed) as error: - raise ValueError("Unable to init HP ILO, %s", error) + raise ValueError("Unable to init HP ILO, {}".format(error)) diff --git a/homeassistant/components/sensor/ihc.py b/homeassistant/components/sensor/ihc.py index b6440a407a44a9..b30a242c17c191 100644 --- a/homeassistant/components/sensor/ihc.py +++ b/homeassistant/components/sensor/ihc.py @@ -62,7 +62,7 @@ class IHCSensor(IHCDevice, Entity): """Implementation of the IHC sensor.""" def __init__(self, ihc_controller, name, ihc_id: int, info: bool, - unit, product: Element=None) -> None: + unit, product: Element = None) -> None: """Initialize the IHC sensor.""" super().__init__(ihc_controller, name, ihc_id, info, product) self._state = None diff --git a/homeassistant/components/sensor/irish_rail_transport.py b/homeassistant/components/sensor/irish_rail_transport.py index 0c34a5f6ce8073..fc012d9589a27a 100644 --- a/homeassistant/components/sensor/irish_rail_transport.py +++ b/homeassistant/components/sensor/irish_rail_transport.py @@ -92,7 +92,7 @@ def state(self): @property def device_state_attributes(self): """Return the state attributes.""" - if len(self._times) > 0: + if self._times: next_up = "None" if len(self._times) > 1: next_up = self._times[1][ATTR_ORIGIN] + " to " @@ -126,7 +126,7 @@ def update(self): """Get the latest data and update the states.""" self.data.update() self._times = self.data.info - if len(self._times) > 0: + if self._times: self._state = self._times[0][ATTR_DUE_IN] else: self._state = None @@ -164,7 +164,7 @@ def update(self): ATTR_TRAIN_TYPE: train.get('type')} self.info.append(train_data) - if not self.info or len(self.info) == 0: + if not self.info or not self.info: self.info = self._empty_train_data() def _empty_train_data(self): diff --git a/homeassistant/components/sensor/isy994.py b/homeassistant/components/sensor/isy994.py index 39c9d8a3b9d1bf..c34a4a8fca75a1 100644 --- a/homeassistant/components/sensor/isy994.py +++ b/homeassistant/components/sensor/isy994.py @@ -254,10 +254,6 @@ def setup_platform(hass, config: ConfigType, class ISYSensorDevice(ISYDevice): """Representation of an ISY994 sensor device.""" - def __init__(self, node) -> None: - """Initialize the ISY994 sensor device.""" - super().__init__(node) - @property def raw_unit_of_measurement(self) -> str: """Get the raw unit of measurement for the ISY994 sensor device.""" @@ -313,10 +309,6 @@ def unit_of_measurement(self) -> str: class ISYWeatherDevice(ISYDevice): """Representation of an ISY994 weather device.""" - def __init__(self, node) -> None: - """Initialize the ISY994 weather device.""" - super().__init__(node) - @property def raw_units(self) -> str: """Return the raw unit of measurement.""" diff --git a/homeassistant/components/sensor/lacrosse.py b/homeassistant/components/sensor/lacrosse.py index b402fc5c70f3a8..3e0a5af283f3b8 100644 --- a/homeassistant/components/sensor/lacrosse.py +++ b/homeassistant/components/sensor/lacrosse.py @@ -133,10 +133,6 @@ def name(self): """Return the name of the sensor.""" return self._name - def update(self, *args): - """Get the latest data.""" - pass - @property def device_state_attributes(self): """Return the state attributes.""" diff --git a/homeassistant/components/sensor/linux_battery.py b/homeassistant/components/sensor/linux_battery.py index 89647d258b430f..3d28c44d606dac 100644 --- a/homeassistant/components/sensor/linux_battery.py +++ b/homeassistant/components/sensor/linux_battery.py @@ -119,24 +119,23 @@ def device_state_attributes(self): ATTR_HEALTH: self._battery_stat.health, ATTR_STATUS: self._battery_stat.status, } - else: - return { - ATTR_NAME: self._battery_stat.name, - ATTR_PATH: self._battery_stat.path, - ATTR_ALARM: self._battery_stat.alarm, - ATTR_CAPACITY_LEVEL: self._battery_stat.capacity_level, - ATTR_CYCLE_COUNT: self._battery_stat.cycle_count, - ATTR_ENERGY_FULL: self._battery_stat.energy_full, - ATTR_ENERGY_FULL_DESIGN: self._battery_stat.energy_full_design, - ATTR_ENERGY_NOW: self._battery_stat.energy_now, - ATTR_MANUFACTURER: self._battery_stat.manufacturer, - ATTR_MODEL_NAME: self._battery_stat.model_name, - ATTR_POWER_NOW: self._battery_stat.power_now, - ATTR_SERIAL_NUMBER: self._battery_stat.serial_number, - ATTR_STATUS: self._battery_stat.status, - ATTR_VOLTAGE_MIN_DESIGN: self._battery_stat.voltage_min_design, - ATTR_VOLTAGE_NOW: self._battery_stat.voltage_now, - } + return { + ATTR_NAME: self._battery_stat.name, + ATTR_PATH: self._battery_stat.path, + ATTR_ALARM: self._battery_stat.alarm, + ATTR_CAPACITY_LEVEL: self._battery_stat.capacity_level, + ATTR_CYCLE_COUNT: self._battery_stat.cycle_count, + ATTR_ENERGY_FULL: self._battery_stat.energy_full, + ATTR_ENERGY_FULL_DESIGN: self._battery_stat.energy_full_design, + ATTR_ENERGY_NOW: self._battery_stat.energy_now, + ATTR_MANUFACTURER: self._battery_stat.manufacturer, + ATTR_MODEL_NAME: self._battery_stat.model_name, + ATTR_POWER_NOW: self._battery_stat.power_now, + ATTR_SERIAL_NUMBER: self._battery_stat.serial_number, + ATTR_STATUS: self._battery_stat.status, + ATTR_VOLTAGE_MIN_DESIGN: self._battery_stat.voltage_min_design, + ATTR_VOLTAGE_NOW: self._battery_stat.voltage_now, + } def update(self): """Get the latest data and updates the states.""" diff --git a/homeassistant/components/sensor/mold_indicator.py b/homeassistant/components/sensor/mold_indicator.py index b47367cafc8567..057718400c4b59 100644 --- a/homeassistant/components/sensor/mold_indicator.py +++ b/homeassistant/components/sensor/mold_indicator.py @@ -174,7 +174,7 @@ def _calc_dewpoint(self): self._dewpoint = \ MAGNUS_K3 * (alpha + math.log(self._indoor_hum / 100.0)) / \ (beta - math.log(self._indoor_hum / 100.0)) - _LOGGER.debug("Dewpoint: %f " + TEMP_CELSIUS, self._dewpoint) + _LOGGER.debug("Dewpoint: %f %s", self._dewpoint, TEMP_CELSIUS) def _calc_moldindicator(self): """Calculate the humidity at the (cold) calibration point.""" @@ -192,8 +192,8 @@ def _calc_moldindicator(self): self._outdoor_temp + (self._indoor_temp - self._outdoor_temp) / \ self._calib_factor - _LOGGER.debug("Estimated Critical Temperature: %f " + - TEMP_CELSIUS, self._crit_temp) + _LOGGER.debug("Estimated Critical Temperature: %f %s", + self._crit_temp, TEMP_CELSIUS) # Then calculate the humidity at this point alpha = MAGNUS_K2 * self._crit_temp / (MAGNUS_K3 + self._crit_temp) diff --git a/homeassistant/components/sensor/nederlandse_spoorwegen.py b/homeassistant/components/sensor/nederlandse_spoorwegen.py index ec534047cccbc2..431a44c56e35c7 100644 --- a/homeassistant/components/sensor/nederlandse_spoorwegen.py +++ b/homeassistant/components/sensor/nederlandse_spoorwegen.py @@ -71,7 +71,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): NSDepartureSensor( nsapi, departure.get(CONF_NAME), departure.get(CONF_FROM), departure.get(CONF_TO), departure.get(CONF_VIA))) - if len(sensors): + if sensors: add_devices(sensors, True) diff --git a/homeassistant/components/sensor/qnap.py b/homeassistant/components/sensor/qnap.py index 3caebad200715a..badec6624d7efa 100644 --- a/homeassistant/components/sensor/qnap.py +++ b/homeassistant/components/sensor/qnap.py @@ -7,6 +7,8 @@ import logging from datetime import timedelta +import voluptuous as vol + from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.helpers.entity import Entity from homeassistant.const import ( @@ -15,8 +17,6 @@ from homeassistant.util import Throttle import homeassistant.helpers.config_validation as cv -import voluptuous as vol - REQUIREMENTS = ['qnapstats==0.2.4'] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/sensor/skybeacon.py b/homeassistant/components/sensor/skybeacon.py index 3c14625202ee5a..eabc33312b24a8 100644 --- a/homeassistant/components/sensor/skybeacon.py +++ b/homeassistant/components/sensor/skybeacon.py @@ -140,7 +140,7 @@ def __init__(self, hass, mac, name): def run(self): """Thread that keeps connection alive.""" - # pylint: disable=import-error + # pylint: disable=import-error, no-name-in-module, no-member import pygatt from pygatt.backends import Characteristic from pygatt.exceptions import ( diff --git a/homeassistant/components/sensor/statistics.py b/homeassistant/components/sensor/statistics.py index b26fd5cc804f59..7b2ae537d4b1ec 100644 --- a/homeassistant/components/sensor/statistics.py +++ b/homeassistant/components/sensor/statistics.py @@ -173,7 +173,7 @@ def _purge_old(self): """Remove states which are older than self._max_age.""" now = dt_util.utcnow() - while (len(self.ages) > 0) and (now - self.ages[0]) > self._max_age: + while self.ages and (now - self.ages[0]) > self._max_age: self.ages.popleft() self.states.popleft() diff --git a/homeassistant/components/sensor/teksavvy.py b/homeassistant/components/sensor/teksavvy.py index cb78caae095bce..33e5c0cf4ceef9 100644 --- a/homeassistant/components/sensor/teksavvy.py +++ b/homeassistant/components/sensor/teksavvy.py @@ -6,9 +6,11 @@ """ from datetime import timedelta import logging - import asyncio import async_timeout + +import voluptuous as vol + from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.const import ( CONF_API_KEY, CONF_MONITORED_VARIABLES, CONF_NAME) @@ -16,7 +18,6 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle -import voluptuous as vol _LOGGER = logging.getLogger(__name__) @@ -142,18 +143,17 @@ def async_update(self): if req.status != 200: _LOGGER.error("Request failed with status: %u", req.status) return False - else: - data = yield from req.json() - for (api, ha_name) in API_HA_MAP: - self.data[ha_name] = float(data["value"][0][api]) - on_peak_download = self.data["onpeak_download"] - on_peak_upload = self.data["onpeak_upload"] - off_peak_download = self.data["offpeak_download"] - off_peak_upload = self.data["offpeak_upload"] - limit = self.data["limit"] - self.data["usage"] = 100*on_peak_download/self.bandwidth_cap - self.data["usage_gb"] = on_peak_download - self.data["onpeak_total"] = on_peak_download + on_peak_upload - self.data["offpeak_total"] = off_peak_download + off_peak_upload - self.data["onpeak_remaining"] = limit - on_peak_download - return True + data = yield from req.json() + for (api, ha_name) in API_HA_MAP: + self.data[ha_name] = float(data["value"][0][api]) + on_peak_download = self.data["onpeak_download"] + on_peak_upload = self.data["onpeak_upload"] + off_peak_download = self.data["offpeak_download"] + off_peak_upload = self.data["offpeak_upload"] + limit = self.data["limit"] + self.data["usage"] = 100*on_peak_download/self.bandwidth_cap + self.data["usage_gb"] = on_peak_download + self.data["onpeak_total"] = on_peak_download + on_peak_upload + self.data["offpeak_total"] = off_peak_download + off_peak_upload + self.data["onpeak_remaining"] = limit - on_peak_download + return True diff --git a/homeassistant/components/sensor/viaggiatreno.py b/homeassistant/components/sensor/viaggiatreno.py index a7f4b070f2d43f..43ba80d2630548 100644 --- a/homeassistant/components/sensor/viaggiatreno.py +++ b/homeassistant/components/sensor/viaggiatreno.py @@ -76,9 +76,8 @@ def async_http_request(hass, uri): req = yield from session.get(uri) if req.status != 200: return {'error': req.status} - else: - json_response = yield from req.json() - return json_response + json_response = yield from req.json() + return json_response except (asyncio.TimeoutError, aiohttp.ClientError) as exc: _LOGGER.error("Cannot connect to ViaggiaTreno API endpoint: %s", exc) except ValueError: diff --git a/homeassistant/components/sensor/volvooncall.py b/homeassistant/components/sensor/volvooncall.py index 32b228ca1f99ac..343bcdf20333f4 100644 --- a/homeassistant/components/sensor/volvooncall.py +++ b/homeassistant/components/sensor/volvooncall.py @@ -42,12 +42,10 @@ def state(self): val /= 10 # L/1000km -> L/100km if 'mil' in self.unit_of_measurement: return round(val, 2) - else: - return round(val, 1) + return round(val, 1) elif self._attribute == 'distance_to_empty': return int(floor(val)) - else: - return int(round(val)) + return int(round(val)) @property def unit_of_measurement(self): @@ -56,8 +54,7 @@ def unit_of_measurement(self): if self._state.config[CONF_SCANDINAVIAN_MILES] and 'km' in unit: if self._attribute == 'average_fuel_consumption': return 'L/mil' - else: - return unit.replace('km', 'mil') + return unit.replace('km', 'mil') return unit @property diff --git a/homeassistant/components/sensor/worldtidesinfo.py b/homeassistant/components/sensor/worldtidesinfo.py index f23d244cf3ae7a..8884d790eed036 100644 --- a/homeassistant/components/sensor/worldtidesinfo.py +++ b/homeassistant/components/sensor/worldtidesinfo.py @@ -90,10 +90,8 @@ def state(self): tidetime = time.strftime('%I:%M %p', time.localtime( self.data['extremes'][0]['dt'])) return "Low tide at %s" % (tidetime) - else: - return STATE_UNKNOWN - else: return STATE_UNKNOWN + return STATE_UNKNOWN def update(self): """Get the latest data from WorldTidesInfo API.""" diff --git a/homeassistant/components/sensor/yr.py b/homeassistant/components/sensor/yr.py index 71a4e60e8a67fb..244ad58eb9a418 100644 --- a/homeassistant/components/sensor/yr.py +++ b/homeassistant/components/sensor/yr.py @@ -226,7 +226,7 @@ def try_again(err: str): # Update all devices tasks = [] - if len(ordered_entries) > 0: + if ordered_entries: for dev in self.devices: new_state = None @@ -258,5 +258,5 @@ def try_again(err: str): dev._state = new_state tasks.append(dev.async_update_ha_state()) - if len(tasks) > 0: + if tasks: yield from asyncio.wait(tasks, loop=self.hass.loop) diff --git a/homeassistant/components/sensor/zigbee.py b/homeassistant/components/sensor/zigbee.py index a1d549cb382dd3..37cc6fabe2e71d 100644 --- a/homeassistant/components/sensor/zigbee.py +++ b/homeassistant/components/sensor/zigbee.py @@ -70,7 +70,7 @@ def unit_of_measurement(self): """Return the unit of measurement the value is expressed in.""" return TEMP_CELSIUS - def update(self, *args): + def update(self): """Get the latest data.""" try: self._temp = zigbee.DEVICE.get_temperature(self._config.address) diff --git a/homeassistant/components/sleepiq.py b/homeassistant/components/sleepiq.py index baf6d154c669e3..3b74b79b36b018 100644 --- a/homeassistant/components/sleepiq.py +++ b/homeassistant/components/sleepiq.py @@ -6,6 +6,7 @@ """ import logging from datetime import timedelta +from requests.exceptions import HTTPError import voluptuous as vol @@ -14,7 +15,6 @@ from homeassistant.helpers.entity import Entity from homeassistant.const import CONF_USERNAME, CONF_PASSWORD from homeassistant.util import Throttle -from requests.exceptions import HTTPError DOMAIN = 'sleepiq' diff --git a/homeassistant/components/switch/acer_projector.py b/homeassistant/components/switch/acer_projector.py index 8fd70ec7ed8559..527456d6d19fcc 100644 --- a/homeassistant/components/switch/acer_projector.py +++ b/homeassistant/components/switch/acer_projector.py @@ -155,13 +155,13 @@ def update(self): awns = self._write_read_format(msg) self._attributes[key] = awns - def turn_on(self): + def turn_on(self, **kwargs): """Turn the projector on.""" msg = CMD_DICT[STATE_ON] self._write_read(msg) self._state = STATE_ON - def turn_off(self): + def turn_off(self, **kwargs): """Turn the projector off.""" msg = CMD_DICT[STATE_OFF] self._write_read(msg) diff --git a/homeassistant/components/switch/anel_pwrctrl.py b/homeassistant/components/switch/anel_pwrctrl.py index bfa6e2af976e8d..9144222e5c78df 100644 --- a/homeassistant/components/switch/anel_pwrctrl.py +++ b/homeassistant/components/switch/anel_pwrctrl.py @@ -101,11 +101,11 @@ def update(self): """Trigger update for all switches on the parent device.""" self._parent_device.update() - def turn_on(self): + def turn_on(self, **kwargs): """Turn the switch on.""" self._port.on() - def turn_off(self): + def turn_off(self, **kwargs): """Turn the switch off.""" self._port.off() diff --git a/homeassistant/components/switch/arduino.py b/homeassistant/components/switch/arduino.py index 3aa61feffc8e9c..1547f4f1dee363 100644 --- a/homeassistant/components/switch/arduino.py +++ b/homeassistant/components/switch/arduino.py @@ -83,12 +83,12 @@ def is_on(self): """Return true if pin is high/on.""" return self._state - def turn_on(self): + def turn_on(self, **kwargs): """Turn the pin to high/on.""" self._state = True self.turn_on_handler(self._pin) - def turn_off(self): + def turn_off(self, **kwargs): """Turn the pin to low/off.""" self._state = False self.turn_off_handler(self._pin) diff --git a/homeassistant/components/switch/dlink.py b/homeassistant/components/switch/dlink.py index f6ed6dac018c1f..5d727e72138db7 100644 --- a/homeassistant/components/switch/dlink.py +++ b/homeassistant/components/switch/dlink.py @@ -117,7 +117,7 @@ def turn_on(self, **kwargs): """Turn the switch on.""" self.data.smartplug.state = 'ON' - def turn_off(self): + def turn_off(self, **kwargs): """Turn the switch off.""" self.data.smartplug.state = 'OFF' diff --git a/homeassistant/components/switch/edimax.py b/homeassistant/components/switch/edimax.py index c5973c3ee04779..d4b02749c1bf45 100644 --- a/homeassistant/components/switch/edimax.py +++ b/homeassistant/components/switch/edimax.py @@ -77,7 +77,7 @@ def turn_on(self, **kwargs): """Turn the switch on.""" self.smartplug.state = 'ON' - def turn_off(self): + def turn_off(self, **kwargs): """Turn the switch off.""" self.smartplug.state = 'OFF' diff --git a/homeassistant/components/switch/fritzdect.py b/homeassistant/components/switch/fritzdect.py index 8ddfca05fb6ce1..58ad745a2d2dd8 100644 --- a/homeassistant/components/switch/fritzdect.py +++ b/homeassistant/components/switch/fritzdect.py @@ -130,7 +130,7 @@ def turn_on(self, **kwargs): _LOGGER.error("Fritz!Box query failed, triggering relogin") self.data.is_online = False - def turn_off(self): + def turn_off(self, **kwargs): """Turn the switch off.""" if not self.data.is_online: _LOGGER.error("turn_off: Not online skipping request") diff --git a/homeassistant/components/switch/gc100.py b/homeassistant/components/switch/gc100.py index ed50c3f63f6616..f4175926aa0610 100644 --- a/homeassistant/components/switch/gc100.py +++ b/homeassistant/components/switch/gc100.py @@ -56,11 +56,11 @@ def is_on(self): """Return the state of the entity.""" return self._state - def turn_on(self): + def turn_on(self, **kwargs): """Turn the device on.""" self._gc100.write_switch(self._port_addr, 1, self.set_state) - def turn_off(self): + def turn_off(self, **kwargs): """Turn the device off.""" self._gc100.write_switch(self._port_addr, 0, self.set_state) diff --git a/homeassistant/components/switch/hdmi_cec.py b/homeassistant/components/switch/hdmi_cec.py index 65a7a762c0f9d0..e81c09894abb8d 100644 --- a/homeassistant/components/switch/hdmi_cec.py +++ b/homeassistant/components/switch/hdmi_cec.py @@ -47,7 +47,7 @@ def turn_off(self, **kwargs) -> None: self._device.turn_off() self._state = STATE_ON - def toggle(self): + def toggle(self, **kwargs): """Toggle the entity.""" self._device.toggle() if self._state == STATE_ON: diff --git a/homeassistant/components/switch/ihc.py b/homeassistant/components/switch/ihc.py index eab88035c73313..499a4ca53a7195 100644 --- a/homeassistant/components/switch/ihc.py +++ b/homeassistant/components/switch/ihc.py @@ -53,7 +53,7 @@ class IHCSwitch(IHCDevice, SwitchDevice): """IHC Switch.""" def __init__(self, ihc_controller, name: str, ihc_id: int, - info: bool, product: Element=None) -> None: + info: bool, product: Element = None) -> None: """Initialize the IHC switch.""" super().__init__(ihc_controller, name, ihc_id, product) self._state = False diff --git a/homeassistant/components/switch/isy994.py b/homeassistant/components/switch/isy994.py index f0fd397710e1b0..efdda6ed40cb79 100644 --- a/homeassistant/components/switch/isy994.py +++ b/homeassistant/components/switch/isy994.py @@ -33,10 +33,6 @@ def setup_platform(hass, config: ConfigType, class ISYSwitchDevice(ISYDevice, SwitchDevice): """Representation of an ISY994 switch device.""" - def __init__(self, node) -> None: - """Initialize the ISY994 switch device.""" - super().__init__(node) - @property def is_on(self) -> bool: """Get whether the ISY994 device is in the on state.""" diff --git a/homeassistant/components/switch/netio.py b/homeassistant/components/switch/netio.py index 2a72703c5dfbf9..365bbaa3679d14 100644 --- a/homeassistant/components/switch/netio.py +++ b/homeassistant/components/switch/netio.py @@ -141,11 +141,11 @@ def available(self): """Return true if entity is available.""" return not hasattr(self, 'telnet') - def turn_on(self): + def turn_on(self, **kwargs): """Turn switch on.""" self._set(True) - def turn_off(self): + def turn_off(self, **kwargs): """Turn switch off.""" self._set(False) diff --git a/homeassistant/components/switch/pilight.py b/homeassistant/components/switch/pilight.py index 1ce599366a1bfc..57fa4b00c98733 100644 --- a/homeassistant/components/switch/pilight.py +++ b/homeassistant/components/switch/pilight.py @@ -188,10 +188,10 @@ def set_state(self, turn_on, send_code=True): self._state = turn_on self.schedule_update_ha_state() - def turn_on(self): + def turn_on(self, **kwargs): """Turn the switch on by calling pilight.send service with on code.""" self.set_state(turn_on=True) - def turn_off(self): + def turn_off(self, **kwargs): """Turn the switch on by calling pilight.send service with off code.""" self.set_state(turn_on=False) diff --git a/homeassistant/components/switch/rachio.py b/homeassistant/components/switch/rachio.py index d8d424be3612d0..dc661c3e5bfb10 100644 --- a/homeassistant/components/switch/rachio.py +++ b/homeassistant/components/switch/rachio.py @@ -216,7 +216,7 @@ def update(self): _LOGGER.debug("Updated %s", str(self)) - def turn_on(self): + def turn_on(self, **kwargs): """Start the zone.""" # Stop other zones first self.turn_off() @@ -224,7 +224,7 @@ def turn_on(self): _LOGGER.info("Watering %s for %d s", self.name, self._manual_run_secs) self.rachio.zone.start(self.zone_id, self._manual_run_secs) - def turn_off(self): + def turn_off(self, **kwargs): """Stop all zones.""" _LOGGER.info("Stopping watering of all zones") self.rachio.device.stopWater(self._device.device_id) diff --git a/homeassistant/components/switch/raincloud.py b/homeassistant/components/switch/raincloud.py index a18d6544acc831..8a5c4347cf7c08 100644 --- a/homeassistant/components/switch/raincloud.py +++ b/homeassistant/components/switch/raincloud.py @@ -59,7 +59,7 @@ def is_on(self): """Return true if device is on.""" return self._state - def turn_on(self): + def turn_on(self, **kwargs): """Turn the device on.""" if self._sensor_type == 'manual_watering': self.data.watering_time = self._default_watering_timer @@ -67,7 +67,7 @@ def turn_on(self): self.data.auto_watering = True self._state = True - def turn_off(self): + def turn_off(self, **kwargs): """Turn the device off.""" if self._sensor_type == 'manual_watering': self.data.watering_time = 'off' diff --git a/homeassistant/components/switch/raspihats.py b/homeassistant/components/switch/raspihats.py index 183ee6edb77490..a8177c017929d4 100644 --- a/homeassistant/components/switch/raspihats.py +++ b/homeassistant/components/switch/raspihats.py @@ -121,7 +121,7 @@ def is_on(self): _LOGGER.error(self._log_message("Is ON check failed, " + str(ex))) return False - def turn_on(self): + def turn_on(self, **kwargs): """Turn the device on.""" try: state = True if self._invert_logic is False else False @@ -130,7 +130,7 @@ def turn_on(self): except I2CHatsException as ex: _LOGGER.error(self._log_message("Turn ON failed, " + str(ex))) - def turn_off(self): + def turn_off(self, **kwargs): """Turn the device off.""" try: state = False if self._invert_logic is False else True diff --git a/homeassistant/components/switch/rpi_pfio.py b/homeassistant/components/switch/rpi_pfio.py index a493a8e958955f..bd964e3d2ad659 100644 --- a/homeassistant/components/switch/rpi_pfio.py +++ b/homeassistant/components/switch/rpi_pfio.py @@ -75,13 +75,13 @@ def is_on(self): """Return true if device is on.""" return self._state - def turn_on(self): + def turn_on(self, **kwargs): """Turn the device on.""" rpi_pfio.write_output(self._port, 0 if self._invert_logic else 1) self._state = True self.schedule_update_ha_state() - def turn_off(self): + def turn_off(self, **kwargs): """Turn the device off.""" rpi_pfio.write_output(self._port, 1 if self._invert_logic else 0) self._state = False diff --git a/homeassistant/components/switch/rpi_rf.py b/homeassistant/components/switch/rpi_rf.py index 94a61314d1d351..40200f05806343 100644 --- a/homeassistant/components/switch/rpi_rf.py +++ b/homeassistant/components/switch/rpi_rf.py @@ -44,7 +44,7 @@ }) -# pylint: disable=unused-argument, import-error +# pylint: disable=unused-argument, import-error, no-member def setup_platform(hass, config, add_devices, discovery_info=None): """Find and return switches controlled by a generic RF device via GPIO.""" import rpi_rf @@ -117,13 +117,13 @@ def _send_code(self, code_list, protocol, pulselength): self._rfdevice.tx_code(code, protocol, pulselength) return True - def turn_on(self): + def turn_on(self, **kwargs): """Turn the switch on.""" if self._send_code(self._code_on, self._protocol, self._pulselength): self._state = True self.schedule_update_ha_state() - def turn_off(self): + def turn_off(self, **kwargs): """Turn the switch off.""" if self._send_code(self._code_off, self._protocol, self._pulselength): self._state = False diff --git a/homeassistant/components/switch/snmp.py b/homeassistant/components/switch/snmp.py index 8aa9744b3da5a2..b0c192cdafad42 100644 --- a/homeassistant/components/switch/snmp.py +++ b/homeassistant/components/switch/snmp.py @@ -95,13 +95,13 @@ def __init__(self, name, host, port, community, self._payload_on = payload_on self._payload_off = payload_off - def turn_on(self): + def turn_on(self, **kwargs): """Turn on the switch.""" from pyasn1.type.univ import (Integer) self._set(Integer(self._command_payload_on)) - def turn_off(self): + def turn_off(self, **kwargs): """Turn off the switch.""" from pyasn1.type.univ import (Integer) diff --git a/homeassistant/components/switch/toon.py b/homeassistant/components/switch/toon.py index 09dc45c6587b22..94086d819e2a44 100644 --- a/homeassistant/components/switch/toon.py +++ b/homeassistant/components/switch/toon.py @@ -64,7 +64,7 @@ def turn_on(self, **kwargs): """Turn the switch on.""" return self.smartplug.turn_on() - def turn_off(self): + def turn_off(self, **kwargs): """Turn the switch off.""" return self.smartplug.turn_off() diff --git a/homeassistant/components/switch/tplink.py b/homeassistant/components/switch/tplink.py index 14faa98fb59ce5..1eca5284f76f2d 100644 --- a/homeassistant/components/switch/tplink.py +++ b/homeassistant/components/switch/tplink.py @@ -75,7 +75,7 @@ def turn_on(self, **kwargs): """Turn the switch on.""" self.smartplug.turn_on() - def turn_off(self): + def turn_off(self, **kwargs): """Turn the switch off.""" self.smartplug.turn_off() diff --git a/homeassistant/components/switch/verisure.py b/homeassistant/components/switch/verisure.py index 710580c2ec661f..810946a505883b 100644 --- a/homeassistant/components/switch/verisure.py +++ b/homeassistant/components/switch/verisure.py @@ -60,13 +60,13 @@ def available(self): "$.smartPlugs[?(@.deviceLabel == '%s')]", self._device_label) is not None - def turn_on(self): + def turn_on(self, **kwargs): """Set smartplug status on.""" hub.session.set_smartplug_state(self._device_label, True) self._state = True self._change_timestamp = time() - def turn_off(self): + def turn_off(self, **kwargs): """Set smartplug status off.""" hub.session.set_smartplug_state(self._device_label, False) self._state = False diff --git a/homeassistant/components/switch/vultr.py b/homeassistant/components/switch/vultr.py index a044fca297286c..fe3d67470d79b1 100644 --- a/homeassistant/components/switch/vultr.py +++ b/homeassistant/components/switch/vultr.py @@ -90,12 +90,12 @@ def device_state_attributes(self): ATTR_VCPUS: self.data.get('vcpu_count'), } - def turn_on(self): + def turn_on(self, **kwargs): """Boot-up the subscription.""" if self.data['power_status'] != 'running': self._vultr.start(self.subscription) - def turn_off(self): + def turn_off(self, **kwargs): """Halt the subscription.""" if self.data['power_status'] == 'running': self._vultr.halt(self.subscription) diff --git a/homeassistant/components/switch/wake_on_lan.py b/homeassistant/components/switch/wake_on_lan.py index ecaff14e2e21b7..80102621f7daf2 100644 --- a/homeassistant/components/switch/wake_on_lan.py +++ b/homeassistant/components/switch/wake_on_lan.py @@ -78,7 +78,7 @@ def name(self): """Return the name of the switch.""" return self._name - def turn_on(self): + def turn_on(self, **kwargs): """Turn the device on.""" if self._broadcast_address: self._wol.send_magic_packet( @@ -86,7 +86,7 @@ def turn_on(self): else: self._wol.send_magic_packet(self._mac_address) - def turn_off(self): + def turn_off(self, **kwargs): """Turn the device off if an off action is present.""" if self._off_script is not None: self._off_script.run() diff --git a/homeassistant/components/switch/wink.py b/homeassistant/components/switch/wink.py index 5a43de9425c242..6a2446150651e7 100644 --- a/homeassistant/components/switch/wink.py +++ b/homeassistant/components/switch/wink.py @@ -54,7 +54,7 @@ def turn_on(self, **kwargs): """Turn the device on.""" self.wink.set_state(True) - def turn_off(self): + def turn_off(self, **kwargs): """Turn the device off.""" self.wink.set_state(False) diff --git a/homeassistant/components/switch/xiaomi_aqara.py b/homeassistant/components/switch/xiaomi_aqara.py index 578036a167774c..1688b6b89e11b2 100644 --- a/homeassistant/components/switch/xiaomi_aqara.py +++ b/homeassistant/components/switch/xiaomi_aqara.py @@ -101,7 +101,7 @@ def turn_on(self, **kwargs): self._state = True self.schedule_update_ha_state() - def turn_off(self): + def turn_off(self, **kwargs): """Turn the switch off.""" if self._write_to_hub(self._sid, **{self._data_key: 'off'}): self._state = False diff --git a/homeassistant/components/switch/zoneminder.py b/homeassistant/components/switch/zoneminder.py index 5dffd99c3249e8..adf3bf2d9bd624 100644 --- a/homeassistant/components/switch/zoneminder.py +++ b/homeassistant/components/switch/zoneminder.py @@ -75,14 +75,14 @@ def is_on(self): """Return True if entity is on.""" return self._state - def turn_on(self): + def turn_on(self, **kwargs): """Turn the entity on.""" zoneminder.change_state( 'api/monitors/%i.json' % self._monitor_id, {'Monitor[Function]': self._on_state} ) - def turn_off(self): + def turn_off(self, **kwargs): """Turn the entity off.""" zoneminder.change_state( 'api/monitors/%i.json' % self._monitor_id, diff --git a/homeassistant/components/telegram_bot/polling.py b/homeassistant/components/telegram_bot/polling.py index 0ce1144184369d..bec239ba1dde48 100644 --- a/homeassistant/components/telegram_bot/polling.py +++ b/homeassistant/components/telegram_bot/polling.py @@ -93,7 +93,7 @@ def get_updates(self, offset): _json = yield from resp.json() return _json else: - raise WrongHttpStatus('wrong status %s', resp.status) + raise WrongHttpStatus('wrong status {}'.format(resp.status)) finally: if resp is not None: yield from resp.release() diff --git a/homeassistant/components/tellduslive.py b/homeassistant/components/tellduslive.py index 28bf65bc4c5059..dfb4b1e5fa9c24 100644 --- a/homeassistant/components/tellduslive.py +++ b/homeassistant/components/tellduslive.py @@ -7,6 +7,8 @@ from datetime import datetime, timedelta import logging +import voluptuous as vol + from homeassistant.const import ( ATTR_BATTERY_LEVEL, DEVICE_DEFAULT_NAME, CONF_TOKEN, CONF_HOST, @@ -18,7 +20,6 @@ from homeassistant.helpers.event import track_point_in_utc_time from homeassistant.util.dt import utcnow from homeassistant.util.json import load_json, save_json -import voluptuous as vol APPLICATION_NAME = 'Home Assistant' @@ -352,8 +353,7 @@ def _battery_level(self): return None elif self.device.battery == BATTERY_OK: return 100 - else: - return self.device.battery # Percentage + return self.device.battery # Percentage @property def _last_updated(self): diff --git a/homeassistant/components/tts/__init__.py b/homeassistant/components/tts/__init__.py index 532b4529eca188..17aa66ea825a1e 100644 --- a/homeassistant/components/tts/__init__.py +++ b/homeassistant/components/tts/__init__.py @@ -411,7 +411,7 @@ def async_read_tts(self, filename): if key not in self.mem_cache: if key not in self.file_cache: - raise HomeAssistantError("%s not in cache!", key) + raise HomeAssistantError("{} not in cache!".format(key)) yield from self.async_file_to_mem(key) content, _ = mimetypes.guess_type(filename) diff --git a/homeassistant/components/upnp.py b/homeassistant/components/upnp.py index 87990495cf4ef1..960d8f3780e5fb 100644 --- a/homeassistant/components/upnp.py +++ b/homeassistant/components/upnp.py @@ -51,7 +51,7 @@ }, extra=vol.ALLOW_EXTRA) -# pylint: disable=import-error, no-member, broad-except +# pylint: disable=import-error, no-member, broad-except, c-extension-no-member def setup(hass, config): """Register a port mapping for Home Assistant via UPnP.""" config = config[DOMAIN] diff --git a/homeassistant/components/vacuum/roomba.py b/homeassistant/components/vacuum/roomba.py index 500b98420fc0ce..6485f0025e2d4c 100644 --- a/homeassistant/components/vacuum/roomba.py +++ b/homeassistant/components/vacuum/roomba.py @@ -242,7 +242,7 @@ def async_set_fan_speed(self, fan_speed, **kwargs): self.vacuum.set_preference, 'vacHigh', str(high_perf)) @asyncio.coroutine - def async_send_command(self, command, params, **kwargs): + def async_send_command(self, command, params=None, **kwargs): """Send raw command.""" _LOGGER.debug("async_send_command %s (%s), %s", command, params, kwargs) diff --git a/homeassistant/components/vacuum/xiaomi_miio.py b/homeassistant/components/vacuum/xiaomi_miio.py index d64f7a754ee6e8..3f194b7eeac1a2 100644 --- a/homeassistant/components/vacuum/xiaomi_miio.py +++ b/homeassistant/components/vacuum/xiaomi_miio.py @@ -341,9 +341,9 @@ def async_remote_control_stop(self): @asyncio.coroutine def async_remote_control_move(self, - rotation: int=0, - velocity: float=0.3, - duration: int=1500): + rotation: int = 0, + velocity: float = 0.3, + duration: int = 1500): """Move vacuum with remote control mode.""" yield from self._try_command( "Unable to move with remote control the vacuum: %s", @@ -352,9 +352,9 @@ def async_remote_control_move(self, @asyncio.coroutine def async_remote_control_move_step(self, - rotation: int=0, - velocity: float=0.2, - duration: int=1500): + rotation: int = 0, + velocity: float = 0.2, + duration: int = 1500): """Move vacuum one step with remote control mode.""" yield from self._try_command( "Unable to remote control the vacuum: %s", diff --git a/homeassistant/components/volvooncall.py b/homeassistant/components/volvooncall.py index 3e36d0a302828b..6557be2fb1bebd 100644 --- a/homeassistant/components/volvooncall.py +++ b/homeassistant/components/volvooncall.py @@ -4,10 +4,11 @@ For more details about this component, please refer to the documentation at https://home-assistant.io/components/volvooncall/ """ - from datetime import timedelta import logging +import voluptuous as vol + from homeassistant.const import (CONF_USERNAME, CONF_PASSWORD, CONF_NAME, CONF_RESOURCES) from homeassistant.helpers import discovery @@ -16,7 +17,6 @@ from homeassistant.helpers.event import track_point_in_utc_time from homeassistant.helpers.dispatcher import dispatcher_send from homeassistant.util.dt import utcnow -import voluptuous as vol DOMAIN = 'volvooncall' @@ -143,8 +143,7 @@ def vehicle_name(self, vehicle): return vehicle.registration_number elif vehicle.vin: return vehicle.vin - else: - return '' + return '' class VolvoEntity(Entity): diff --git a/homeassistant/components/weather/buienradar.py b/homeassistant/components/weather/buienradar.py index f37914b3b0f744..b06ae4dcea1094 100644 --- a/homeassistant/components/weather/buienradar.py +++ b/homeassistant/components/weather/buienradar.py @@ -6,6 +6,9 @@ """ import logging import asyncio + +import voluptuous as vol + from homeassistant.components.weather import ( WeatherEntity, PLATFORM_SCHEMA, ATTR_FORECAST_TEMP, ATTR_FORECAST_TIME) from homeassistant.const import \ @@ -14,7 +17,6 @@ # Reuse data and API logic from the sensor implementation from homeassistant.components.sensor.buienradar import ( BrData) -import voluptuous as vol REQUIREMENTS = ['buienradar==0.9'] diff --git a/homeassistant/config.py b/homeassistant/config.py index 5e82ef1baa03ca..f48f93b39fa66c 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -166,7 +166,7 @@ def get_default_config_dir() -> str: return os.path.join(data_dir, CONFIG_DIR_NAME) -def ensure_config_exists(config_dir: str, detect_location: bool=True) -> str: +def ensure_config_exists(config_dir: str, detect_location: bool = True) -> str: """Ensure a configuration file exists in given configuration directory. Creating a default one if needed. @@ -677,7 +677,7 @@ def async_check_ha_config_file(hass): @callback -def async_notify_setup_error(hass, component, link=False): +def async_notify_setup_error(hass, component, display_link=False): """Print a persistent notification. This method must be run in the event loop. @@ -689,7 +689,7 @@ def async_notify_setup_error(hass, component, link=False): if errors is None: errors = hass.data[DATA_PERSISTENT_ERRORS] = {} - errors[component] = errors.get(component) or link + errors[component] = errors.get(component) or display_link message = 'The following components and platforms could not be set up:\n\n' diff --git a/homeassistant/helpers/condition.py b/homeassistant/helpers/condition.py index 87b84a8081538f..382a7c27d7862a 100644 --- a/homeassistant/helpers/condition.py +++ b/homeassistant/helpers/condition.py @@ -47,7 +47,7 @@ def condition_if(hass, variables=None): return factory -def async_from_config(config: ConfigType, config_validation: bool=True): +def async_from_config(config: ConfigType, config_validation: bool = True): """Turn a condition configuration into a method. Should be run on the event loop. @@ -70,7 +70,7 @@ def async_from_config(config: ConfigType, config_validation: bool=True): from_config = _threaded_factory(async_from_config) -def async_and_from_config(config: ConfigType, config_validation: bool=True): +def async_and_from_config(config: ConfigType, config_validation: bool = True): """Create multi condition matcher using 'AND'.""" if config_validation: config = cv.AND_CONDITION_SCHEMA(config) @@ -101,7 +101,7 @@ def if_and_condition(hass: HomeAssistant, and_from_config = _threaded_factory(async_and_from_config) -def async_or_from_config(config: ConfigType, config_validation: bool=True): +def async_or_from_config(config: ConfigType, config_validation: bool = True): """Create multi condition matcher using 'OR'.""" if config_validation: config = cv.OR_CONDITION_SCHEMA(config) diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index c7653d5d5b955a..97aef44278fc26 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -22,8 +22,8 @@ def generate_entity_id(entity_id_format: str, name: Optional[str], - current_ids: Optional[List[str]]=None, - hass: Optional[HomeAssistant]=None) -> str: + current_ids: Optional[List[str]] = None, + hass: Optional[HomeAssistant] = None) -> str: """Generate a unique entity ID based on given entity IDs or used IDs.""" if current_ids is None: if hass is None: @@ -42,8 +42,8 @@ def generate_entity_id(entity_id_format: str, name: Optional[str], @callback def async_generate_entity_id(entity_id_format: str, name: Optional[str], - current_ids: Optional[List[str]]=None, - hass: Optional[HomeAssistant]=None) -> str: + current_ids: Optional[List[str]] = None, + hass: Optional[HomeAssistant] = None) -> str: """Generate a unique entity ID based on given entity IDs or used IDs.""" if current_ids is None: if hass is None: diff --git a/homeassistant/helpers/entityfilter.py b/homeassistant/helpers/entityfilter.py index f78c70e57d3ed7..c9554488aa75ef 100644 --- a/homeassistant/helpers/entityfilter.py +++ b/homeassistant/helpers/entityfilter.py @@ -74,8 +74,7 @@ def entity_filter_4a(entity_id): domain = split_entity_id(entity_id)[0] if domain in include_d: return entity_id not in exclude_e - else: - return entity_id in include_e + return entity_id in include_e return entity_filter_4a @@ -88,8 +87,7 @@ def entity_filter_4b(entity_id): domain = split_entity_id(entity_id)[0] if domain in exclude_d: return entity_id in include_e - else: - return entity_id not in exclude_e + return entity_id not in exclude_e return entity_filter_4b diff --git a/homeassistant/helpers/icon.py b/homeassistant/helpers/icon.py index e4c78fcbed247e..e3fb983f69147e 100644 --- a/homeassistant/helpers/icon.py +++ b/homeassistant/helpers/icon.py @@ -2,8 +2,8 @@ from typing import Optional -def icon_for_battery_level(battery_level: Optional[int]=None, - charging: bool=False) -> str: +def icon_for_battery_level(battery_level: Optional[int] = None, + charging: bool = False) -> str: """Return a battery icon valid identifier.""" icon = 'mdi:battery' if battery_level is None: diff --git a/homeassistant/helpers/script.py b/homeassistant/helpers/script.py index 1ef9aa15674c30..7a989267572f30 100644 --- a/homeassistant/helpers/script.py +++ b/homeassistant/helpers/script.py @@ -33,7 +33,7 @@ def call_from_config(hass: HomeAssistant, config: ConfigType, - variables: Optional[Sequence]=None) -> None: + variables: Optional[Sequence] = None) -> None: """Call a script based on a config entry.""" Script(hass, cv.SCRIPT_SCHEMA(config)).run(variables) @@ -41,7 +41,7 @@ def call_from_config(hass: HomeAssistant, config: ConfigType, class Script(): """Representation of a script.""" - def __init__(self, hass: HomeAssistant, sequence, name: str=None, + def __init__(self, hass: HomeAssistant, sequence, name: str = None, change_listener=None) -> None: """Initialize the script.""" self.hass = hass @@ -69,7 +69,7 @@ def run(self, variables=None): self.async_run(variables), self.hass.loop).result() @asyncio.coroutine - def async_run(self, variables: Optional[Sequence]=None) -> None: + def async_run(self, variables: Optional[Sequence] = None) -> None: """Run script. This method is a coroutine. diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index b381e1c2b0e61c..6fab1c6c844450 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -271,8 +271,7 @@ def __getattribute__(self, name): """Return an attribute of the state.""" if name in TemplateState.__dict__: return object.__getattribute__(self, name) - else: - return getattr(object.__getattribute__(self, '_state'), name) + return getattr(object.__getattribute__(self, '_state'), name) def __repr__(self): """Representation of Template State.""" diff --git a/homeassistant/remote.py b/homeassistant/remote.py index 7d032303548458..566f37a621ae9d 100644 --- a/homeassistant/remote.py +++ b/homeassistant/remote.py @@ -45,8 +45,9 @@ def __str__(self) -> str: class API(object): """Object to pass around Home Assistant API location and credentials.""" - def __init__(self, host: str, api_password: Optional[str]=None, - port: Optional[int]=SERVER_PORT, use_ssl: bool=False) -> None: + def __init__(self, host: str, api_password: Optional[str] = None, + port: Optional[int] = SERVER_PORT, + use_ssl: bool = False) -> None: """Init the API.""" self.host = host self.port = port @@ -68,7 +69,7 @@ def __init__(self, host: str, api_password: Optional[str]=None, if api_password is not None: self._headers[HTTP_HEADER_HA_AUTH] = api_password - def validate_api(self, force_validate: bool=False) -> bool: + def validate_api(self, force_validate: bool = False) -> bool: """Test if we can communicate with the API.""" if self.status is None or force_validate: self.status = validate_api(self) diff --git a/homeassistant/scripts/credstash.py b/homeassistant/scripts/credstash.py index 12516e55c7df00..84ba20619d8f8e 100644 --- a/homeassistant/scripts/credstash.py +++ b/homeassistant/scripts/credstash.py @@ -24,7 +24,7 @@ def run(args): 'value', help="The value to save when putting a secret", nargs='?', default=None) - # pylint: disable=import-error + # pylint: disable=import-error, no-member import credstash import botocore diff --git a/homeassistant/scripts/db_migrator.py b/homeassistant/scripts/db_migrator.py index bf4dddc94fe465..419f1138bf0668 100644 --- a/homeassistant/scripts/db_migrator.py +++ b/homeassistant/scripts/db_migrator.py @@ -23,8 +23,9 @@ def ts_to_dt(timestamp: Optional[float]) -> Optional[datetime]: # Based on code at # http://stackoverflow.com/questions/3173320/text-progress-bar-in-the-console -def print_progress(iteration: int, total: int, prefix: str='', suffix: str='', - decimals: int=2, bar_length: int=68) -> None: +def print_progress(iteration: int, total: int, prefix: str = '', + suffix: str = '', decimals: int = 2, + bar_length: int = 68) -> None: """Print progress bar. Call in a loop to create terminal progress bar diff --git a/homeassistant/scripts/influxdb_import.py b/homeassistant/scripts/influxdb_import.py index e91aeb8a0d75e8..421e84d503a7ca 100644 --- a/homeassistant/scripts/influxdb_import.py +++ b/homeassistant/scripts/influxdb_import.py @@ -257,8 +257,9 @@ def run(script_args: List) -> int: # Based on code at # http://stackoverflow.com/questions/3173320/text-progress-bar-in-the-console -def print_progress(iteration: int, total: int, prefix: str='', suffix: str='', - decimals: int=2, bar_length: int=68) -> None: +def print_progress(iteration: int, total: int, prefix: str = '', + suffix: str = '', decimals: int = 2, + bar_length: int = 68) -> None: """Print progress bar. Call in a loop to create terminal progress bar diff --git a/homeassistant/scripts/influxdb_migrator.py b/homeassistant/scripts/influxdb_migrator.py index f41240bad74e11..a4c0df74b091ac 100644 --- a/homeassistant/scripts/influxdb_migrator.py +++ b/homeassistant/scripts/influxdb_migrator.py @@ -8,8 +8,9 @@ # Based on code at # http://stackoverflow.com/questions/3173320/text-progress-bar-in-the-console -def print_progress(iteration: int, total: int, prefix: str='', suffix: str='', - decimals: int=2, bar_length: int=68) -> None: +def print_progress(iteration: int, total: int, prefix: str = '', + suffix: str = '', decimals: int = 2, + bar_length: int = 68) -> None: """Print progress bar. Call in a loop to create terminal progress bar diff --git a/homeassistant/setup.py b/homeassistant/setup.py index 3221ea35d487db..364bbc9423084d 100644 --- a/homeassistant/setup.py +++ b/homeassistant/setup.py @@ -24,7 +24,7 @@ def setup_component(hass: core.HomeAssistant, domain: str, - config: Optional[Dict]=None) -> bool: + config: Optional[Dict] = None) -> bool: """Set up a component and all its dependencies.""" return run_coroutine_threadsafe( async_setup_component(hass, domain, config), loop=hass.loop).result() @@ -32,7 +32,7 @@ def setup_component(hass: core.HomeAssistant, domain: str, @asyncio.coroutine def async_setup_component(hass: core.HomeAssistant, domain: str, - config: Optional[Dict]=None) -> bool: + config: Optional[Dict] = None) -> bool: """Set up a component and all its dependencies. This method is a coroutine. diff --git a/homeassistant/util/__init__.py b/homeassistant/util/__init__.py index c4fea2846c5e12..75721a374661bc 100644 --- a/homeassistant/util/__init__.py +++ b/homeassistant/util/__init__.py @@ -61,7 +61,7 @@ def repr_helper(inp: Any) -> str: def convert(value: T, to_type: Callable[[T], U], - default: Optional[U]=None) -> Optional[U]: + default: Optional[U] = None) -> Optional[U]: """Convert value to to_type, returns default if fails.""" try: return default if value is None else to_type(value) @@ -164,6 +164,7 @@ def __contains__(self, key): """Check if key is in set.""" return key in self.map + # pylint: disable=arguments-differ def add(self, key): """Add an element to the end of the set.""" if key not in self.map: @@ -180,6 +181,7 @@ def promote(self, key): curr = begin[1] curr[2] = begin[1] = self.map[key] = [key, curr, begin] + # pylint: disable=arguments-differ def discard(self, key): """Discard an element from the set.""" if key in self.map: diff --git a/homeassistant/util/color.py b/homeassistant/util/color.py index 9c7fa0d70e74d1..089e1e733ed488 100644 --- a/homeassistant/util/color.py +++ b/homeassistant/util/color.py @@ -392,8 +392,8 @@ def color_temperature_to_rgb(color_temperature_kelvin): return (red, green, blue) -def _bound(color_component: float, minimum: float=0, - maximum: float=255) -> float: +def _bound(color_component: float, minimum: float = 0, + maximum: float = 255) -> float: """ Bound the given color component value between the given min and max values. diff --git a/homeassistant/util/dt.py b/homeassistant/util/dt.py index c3400bac9be773..7b5b996a3a3555 100644 --- a/homeassistant/util/dt.py +++ b/homeassistant/util/dt.py @@ -51,7 +51,7 @@ def utcnow() -> dt.datetime: return dt.datetime.now(UTC) -def now(time_zone: dt.tzinfo=None) -> dt.datetime: +def now(time_zone: dt.tzinfo = None) -> dt.datetime: """Get now in specified time zone.""" return dt.datetime.now(time_zone or DEFAULT_TIME_ZONE) diff --git a/homeassistant/util/location.py b/homeassistant/util/location.py index 35b266cb104207..0cd0b14d3ab0a8 100644 --- a/homeassistant/util/location.py +++ b/homeassistant/util/location.py @@ -84,7 +84,7 @@ def elevation(latitude, longitude): # License: https://github.com/maurycyp/vincenty/blob/master/LICENSE # pylint: disable=invalid-name, unused-variable, invalid-sequence-index def vincenty(point1: Tuple[float, float], point2: Tuple[float, float], - miles: bool=False) -> Optional[float]: + miles: bool = False) -> Optional[float]: """ Vincenty formula (inverse method) to calculate the distance. diff --git a/homeassistant/util/package.py b/homeassistant/util/package.py index a82a50f4e0265c..e8149a85262f51 100644 --- a/homeassistant/util/package.py +++ b/homeassistant/util/package.py @@ -17,9 +17,9 @@ INSTALL_LOCK = threading.Lock() -def install_package(package: str, upgrade: bool=True, - target: Optional[str]=None, - constraints: Optional[str]=None) -> bool: +def install_package(package: str, upgrade: bool = True, + target: Optional[str] = None, + constraints: Optional[str] = None) -> bool: """Install a package on PyPi. Accepts pip compatible package strings. Return boolean if install successful. diff --git a/homeassistant/util/yaml.py b/homeassistant/util/yaml.py index d0d5199e0f4752..8ac8d096b99b77 100644 --- a/homeassistant/util/yaml.py +++ b/homeassistant/util/yaml.py @@ -13,7 +13,7 @@ keyring = None try: - import credstash # pylint: disable=import-error + import credstash # pylint: disable=import-error, no-member except ImportError: credstash = None @@ -276,6 +276,7 @@ def _secret_yaml(loader: SafeLineLoader, global credstash # pylint: disable=invalid-name if credstash: + # pylint: disable=no-member try: pwd = credstash.getSecret(node.value, table=_SECRET_NAMESPACE) if pwd: diff --git a/pylintrc b/pylintrc index 1ed8d2af3363ec..85a44782af13ef 100644 --- a/pylintrc +++ b/pylintrc @@ -13,6 +13,7 @@ reports=no # too-many-* - are not enforced for the sake of readability # too-few-* - same as too-many-* # abstract-method - with intro of async there are always methods missing +# inconsistent-return-statements - doesn't handle raise generated-members=botocore.errorfactory @@ -23,6 +24,7 @@ disable= cyclic-import, duplicate-code, global-statement, + inconsistent-return-statements, locally-disabled, not-context-manager, redefined-variable-type, diff --git a/requirements_test.txt b/requirements_test.txt index cddf11a34b8901..d56a7085c74945 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -2,7 +2,7 @@ # make new things fail. Manually update these pins when pulling in a # new version flake8==3.5 -pylint==1.6.5 +pylint==1.8.2 mypy==0.560 pydocstyle==1.1.1 coveralls==1.2.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 1ae1b9f2e14d32..ecb478a29cc5a9 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -3,7 +3,7 @@ # make new things fail. Manually update these pins when pulling in a # new version flake8==3.5 -pylint==1.6.5 +pylint==1.8.2 mypy==0.560 pydocstyle==1.1.1 coveralls==1.2.0 diff --git a/tests/components/cover/test_zwave.py b/tests/components/cover/test_zwave.py index 4b9be9f5e00a4a..b870075d39fa60 100644 --- a/tests/components/cover/test_zwave.py +++ b/tests/components/cover/test_zwave.py @@ -118,7 +118,7 @@ def test_roller_commands(hass, mock_openzwave): device = zwave.get_device(hass=hass, node=node, values=values, node_config={}) - device.set_cover_position(25) + device.set_cover_position(position=25) assert node.set_dimmer.called value_id, brightness = node.set_dimmer.mock_calls[0][1] assert value_id == value.value_id