diff --git a/homeassistant/__main__.py b/homeassistant/__main__.py index 75aaeaa1fd1..2ce574ca15e 100644 --- a/homeassistant/__main__.py +++ b/homeassistant/__main__.py @@ -229,8 +229,8 @@ def cmdline() -> List[str]: os.environ['PYTHONPATH'] = os.path.dirname(modulepath) return [sys.executable] + [arg for arg in sys.argv if arg != '--daemon'] - else: - return [arg for arg in sys.argv if arg != '--daemon'] + + return [arg for arg in sys.argv if arg != '--daemon'] def setup_and_run_hass(config_dir: str, diff --git a/homeassistant/components/__init__.py b/homeassistant/components/__init__.py index c372004e310..ecbb8036464 100644 --- a/homeassistant/components/__init__.py +++ b/homeassistant/components/__init__.py @@ -39,19 +39,19 @@ def is_on(hass, entity_id=None): else: entity_ids = hass.states.entity_ids() - for entity_id in entity_ids: - domain = ha.split_entity_id(entity_id)[0] + for ent_id in entity_ids: + domain = ha.split_entity_id(ent_id)[0] module = get_component(domain) try: - if module.is_on(hass, entity_id): + if module.is_on(hass, ent_id): return True except AttributeError: # module is None or method is_on does not exist _LOGGER.exception("Failed to call %s.is_on for %s", - module, entity_id) + module, ent_id) return False diff --git a/homeassistant/components/alarm_control_panel/wink.py b/homeassistant/components/alarm_control_panel/wink.py index a8cad115883..8bc2539f772 100644 --- a/homeassistant/components/alarm_control_panel/wink.py +++ b/homeassistant/components/alarm_control_panel/wink.py @@ -39,10 +39,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class WinkCameraDevice(WinkDevice, alarm.AlarmControlPanel): """Representation a Wink camera alarm.""" - def __init__(self, wink, hass): - """Initialize the Wink alarm.""" - super().__init__(wink, hass) - @asyncio.coroutine def async_added_to_hass(self): """Callback when entity is added to hass.""" diff --git a/homeassistant/components/alert.py b/homeassistant/components/alert.py index b4de3c4a0f5..6356f429bed 100644 --- a/homeassistant/components/alert.py +++ b/homeassistant/components/alert.py @@ -271,14 +271,14 @@ class Alert(ToggleEntity): 'notify', target, {'message': self._done_message}) @asyncio.coroutine - def async_turn_on(self): + def async_turn_on(self, **kwargs): """Async Unacknowledge alert.""" _LOGGER.debug("Reset Alert: %s", self._name) self._ack = False yield from self.async_update_ha_state() @asyncio.coroutine - def async_turn_off(self): + def async_turn_off(self, **kwargs): """Async Acknowledge alert.""" _LOGGER.debug("Acknowledged Alert: %s", self._name) self._ack = True diff --git a/homeassistant/components/api.py b/homeassistant/components/api.py index 8205029bd21..c22683970bf 100644 --- a/homeassistant/components/api.py +++ b/homeassistant/components/api.py @@ -198,8 +198,7 @@ class APIEntityStateView(HomeAssistantView): state = request.app['hass'].states.get(entity_id) if state: return self.json(state) - else: - return self.json_message('Entity not found', HTTP_NOT_FOUND) + return self.json_message('Entity not found', HTTP_NOT_FOUND) @asyncio.coroutine def post(self, request, entity_id): @@ -237,8 +236,7 @@ class APIEntityStateView(HomeAssistantView): """Remove entity.""" if request.app['hass'].states.async_remove(entity_id): return self.json_message('Entity removed') - else: - return self.json_message('Entity not found', HTTP_NOT_FOUND) + return self.json_message('Entity not found', HTTP_NOT_FOUND) class APIEventListenersView(HomeAssistantView): diff --git a/homeassistant/components/automation/sun.py b/homeassistant/components/automation/sun.py index dfed411745f..497b8453267 100644 --- a/homeassistant/components/automation/sun.py +++ b/homeassistant/components/automation/sun.py @@ -42,8 +42,6 @@ def async_trigger(hass, config, action): }, }) - # Do something to call action if event == SUN_EVENT_SUNRISE: return async_track_sunrise(hass, call_action, offset) - else: - return async_track_sunset(hass, call_action, offset) + return async_track_sunset(hass, call_action, offset) diff --git a/homeassistant/components/binary_sensor/arest.py b/homeassistant/components/binary_sensor/arest.py index 972d9ca835c..5b58a6cbf6a 100644 --- a/homeassistant/components/binary_sensor/arest.py +++ b/homeassistant/components/binary_sensor/arest.py @@ -68,7 +68,7 @@ class ArestBinarySensor(BinarySensorDevice): if self._pin is not None: request = requests.get( '{}/mode/{}/i'.format(self._resource, self._pin), timeout=10) - if request.status_code is not 200: + if request.status_code != 200: _LOGGER.error("Can't set mode of %s", self._resource) @property diff --git a/homeassistant/components/binary_sensor/wink.py b/homeassistant/components/binary_sensor/wink.py index c16c62a5f81..b4910687da7 100644 --- a/homeassistant/components/binary_sensor/wink.py +++ b/homeassistant/components/binary_sensor/wink.py @@ -121,10 +121,6 @@ class WinkBinarySensorDevice(WinkDevice, BinarySensorDevice, Entity): class WinkSmokeDetector(WinkBinarySensorDevice): """Representation of a Wink Smoke detector.""" - def __init__(self, wink, hass): - """Initialize the Wink binary sensor.""" - super().__init__(wink, hass) - @property def device_state_attributes(self): """Return the state attributes.""" @@ -136,10 +132,6 @@ class WinkSmokeDetector(WinkBinarySensorDevice): class WinkHub(WinkBinarySensorDevice): """Representation of a Wink Hub.""" - def __init__(self, wink, hass): - """Initialize the Wink binary sensor.""" - super().__init__(wink, hass) - @property def device_state_attributes(self): """Return the state attributes.""" @@ -152,10 +144,6 @@ class WinkHub(WinkBinarySensorDevice): class WinkRemote(WinkBinarySensorDevice): """Representation of a Wink Lutron Connected bulb remote.""" - def __init__(self, wink, hass): - """Initialize the Wink binary sensor.""" - super().__init__(wink, hass) - @property def device_state_attributes(self): """Return the state attributes.""" @@ -175,10 +163,6 @@ class WinkRemote(WinkBinarySensorDevice): class WinkButton(WinkBinarySensorDevice): """Representation of a Wink Relay button.""" - def __init__(self, wink, hass): - """Initialize the Wink binary sensor.""" - super().__init__(wink, hass) - @property def device_state_attributes(self): """Return the state attributes.""" @@ -191,10 +175,6 @@ class WinkButton(WinkBinarySensorDevice): class WinkGang(WinkBinarySensorDevice): """Representation of a Wink Relay gang.""" - def __init__(self, wink, hass): - """Initialize the Wink binary sensor.""" - super().__init__(wink, hass) - @property def is_on(self): """Return true if the gang is connected.""" diff --git a/homeassistant/components/camera/uvc.py b/homeassistant/components/camera/uvc.py index c0a8039ee64..3203a10b391 100644 --- a/homeassistant/components/camera/uvc.py +++ b/homeassistant/components/camera/uvc.py @@ -54,7 +54,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): _LOGGER.error("Unable to connect to NVR: %s", str(ex)) return False - identifier = nvrconn.server_version >= (3, 2, 0) and 'id' or 'uuid' + identifier = 'id' if nvrconn.server_version >= (3, 2, 0) else 'uuid' # Filter out airCam models, which are not supported in the latest # version of UnifiVideo and which are EOL by Ubiquiti cameras = [ diff --git a/homeassistant/components/climate/homematic.py b/homeassistant/components/climate/homematic.py index 1f9ca7c1abf..60cda24eef9 100644 --- a/homeassistant/components/climate/homematic.py +++ b/homeassistant/components/climate/homematic.py @@ -46,8 +46,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): return devices = [] - for config in discovery_info[ATTR_DISCOVER_DEVICES]: - new_device = HMThermostat(hass, config) + for conf in discovery_info[ATTR_DISCOVER_DEVICES]: + new_device = HMThermostat(hass, conf) new_device.link_homematic() devices.append(new_device) diff --git a/homeassistant/components/climate/netatmo.py b/homeassistant/components/climate/netatmo.py index cea1a41ec9f..3706a24bb52 100755 --- a/homeassistant/components/climate/netatmo.py +++ b/homeassistant/components/climate/netatmo.py @@ -119,14 +119,14 @@ class NetatmoThermostat(ClimateDevice): self._data.thermostatdata.setthermpoint(mode, temp, endTimeOffset=None) self._away = False - def set_temperature(self, endTimeOffset=DEFAULT_TIME_OFFSET, **kwargs): + def set_temperature(self, **kwargs): """Set new target temperature for 2 hours.""" temperature = kwargs.get(ATTR_TEMPERATURE) if temperature is None: return mode = "manual" self._data.thermostatdata.setthermpoint( - mode, temperature, endTimeOffset) + mode, temperature, DEFAULT_TIME_OFFSET) self._target_temperature = temperature self._away = False diff --git a/homeassistant/components/cover/wink.py b/homeassistant/components/cover/wink.py index d5908c35ca2..ce96b4d75e0 100644 --- a/homeassistant/components/cover/wink.py +++ b/homeassistant/components/cover/wink.py @@ -29,20 +29,16 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class WinkCoverDevice(WinkDevice, CoverDevice): """Representation of a Wink cover device.""" - def __init__(self, wink, hass): - """Initialize the cover.""" - super().__init__(wink, hass) - @asyncio.coroutine def async_added_to_hass(self): """Callback when entity is added to hass.""" self.hass.data[DOMAIN]['entities']['cover'].append(self) - def close_cover(self): + def close_cover(self, **kwargs): """Close the shade.""" self.wink.set_state(0) - def open_cover(self): + def open_cover(self, **kwargs): """Open the shade.""" self.wink.set_state(1) diff --git a/homeassistant/components/device_tracker/cisco_ios.py b/homeassistant/components/device_tracker/cisco_ios.py index 35ffa754348..99ed06de486 100644 --- a/homeassistant/components/device_tracker/cisco_ios.py +++ b/homeassistant/components/device_tracker/cisco_ios.py @@ -87,21 +87,20 @@ class CiscoDeviceScanner(DeviceScanner): lines_result = lines_result[2:] for line in lines_result: - if len(line.split()) is 6: - parts = line.split() - if len(parts) != 6: - continue + parts = line.split() + if len(parts) != 6: + continue - # ['Internet', '10.10.11.1', '-', '0027.d32d.0123', 'ARPA', - # 'GigabitEthernet0'] - age = parts[2] - hw_addr = parts[3] + # ['Internet', '10.10.11.1', '-', '0027.d32d.0123', 'ARPA', + # 'GigabitEthernet0'] + age = parts[2] + hw_addr = parts[3] - if age != "-": - mac = _parse_cisco_mac_address(hw_addr) - age = int(age) - if age < 1: - last_results.append(mac) + if age != "-": + mac = _parse_cisco_mac_address(hw_addr) + age = int(age) + if age < 1: + last_results.append(mac) self.last_results = last_results return True diff --git a/homeassistant/components/fan/insteon_local.py b/homeassistant/components/fan/insteon_local.py index 24039f94c00..a18c173ecca 100644 --- a/homeassistant/components/fan/insteon_local.py +++ b/homeassistant/components/fan/insteon_local.py @@ -35,7 +35,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): insteonhub = hass.data['insteon_local'] conf_fans = config_from_file(hass.config.path(INSTEON_LOCAL_FANS_CONF)) - if len(conf_fans): + if conf_fans: for device_id in conf_fans: setup_fan(device_id, conf_fans[device_id], insteonhub, hass, add_devices) diff --git a/homeassistant/components/history.py b/homeassistant/components/history.py index 8faf8f30b1d..9800a15c16b 100644 --- a/homeassistant/components/history.py +++ b/homeassistant/components/history.py @@ -161,8 +161,8 @@ def states_to_json(hass, states, start_time, entity_id, filters=None): result[state.entity_id].append(state) # Append all changes to it - for entity_id, group in groupby(states, lambda state: state.entity_id): - result[entity_id].extend(group) + for ent_id, group in groupby(states, lambda state: state.entity_id): + result[ent_id].extend(group) return result diff --git a/homeassistant/components/insteon_local.py b/homeassistant/components/insteon_local.py index 90e146d0e4f..711dafb6b73 100644 --- a/homeassistant/components/insteon_local.py +++ b/homeassistant/components/insteon_local.py @@ -67,10 +67,9 @@ def setup(hass, config): except requests.exceptions.RequestException: if insteonhub.http_code == 401: _LOGGER.error("Bad user/pass for insteon_local hub") - return False else: _LOGGER.error("Error on insteon_local hub check", exc_info=True) - return False + return False hass.data['insteon_local'] = insteonhub diff --git a/homeassistant/components/knx.py b/homeassistant/components/knx.py index 2cb8562ad9c..3a4b7c54400 100644 --- a/homeassistant/components/knx.py +++ b/homeassistant/components/knx.py @@ -43,7 +43,7 @@ def setup(hass, config): host = config[DOMAIN].get(CONF_HOST) port = config[DOMAIN].get(CONF_PORT) - if host is '0.0.0.0': + if host == '0.0.0.0': _LOGGER.debug("Will try to auto-detect KNX/IP gateway") KNXTUNNEL = KNXIPTunnel(host, port) diff --git a/homeassistant/components/light/homematic.py b/homeassistant/components/light/homematic.py index 11bba4260d5..60865dd223e 100644 --- a/homeassistant/components/light/homematic.py +++ b/homeassistant/components/light/homematic.py @@ -23,8 +23,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): return devices = [] - for config in discovery_info[ATTR_DISCOVER_DEVICES]: - new_device = HMLight(hass, config) + for conf in discovery_info[ATTR_DISCOVER_DEVICES]: + new_device = HMLight(hass, conf) new_device.link_homematic() devices.append(new_device) @@ -38,10 +38,9 @@ class HMLight(HMDevice, Light): def brightness(self): """Return the brightness of this light between 0..255.""" # Is dimmer? - if self._state is "LEVEL": + if self._state == "LEVEL": return int(self._hm_get_state() * 255) - else: - return None + return None @property def is_on(self): @@ -58,7 +57,7 @@ class HMLight(HMDevice, Light): def turn_on(self, **kwargs): """Turn the light on.""" - if ATTR_BRIGHTNESS in kwargs and self._state is "LEVEL": + if ATTR_BRIGHTNESS in kwargs and self._state == "LEVEL": percent_bright = float(kwargs[ATTR_BRIGHTNESS]) / 255 self._hmdevice.set_level(percent_bright, self._channel) else: diff --git a/homeassistant/components/light/hue.py b/homeassistant/components/light/hue.py index 0f00519ab91..73d19d21272 100644 --- a/homeassistant/components/light/hue.py +++ b/homeassistant/components/light/hue.py @@ -330,36 +330,31 @@ class HueLight(Light): """Return the brightness of this light between 0..255.""" if self.is_group: return self.info['action'].get('bri') - else: - return self.info['state'].get('bri') + return self.info['state'].get('bri') @property def xy_color(self): """Return the XY color value.""" if self.is_group: return self.info['action'].get('xy') - else: - return self.info['state'].get('xy') + return self.info['state'].get('xy') @property def color_temp(self): """Return the CT color value.""" if self.is_group: return self.info['action'].get('ct') - else: - return self.info['state'].get('ct') + return self.info['state'].get('ct') @property def is_on(self): """Return true if device is on.""" if self.is_group: return self.info['state']['any_on'] - else: - if self.allow_unreachable: - return self.info['state']['on'] - else: - return self.info['state']['reachable'] and \ - self.info['state']['on'] + elif self.allow_unreachable: + return self.info['state']['on'] + return self.info['state']['reachable'] and \ + self.info['state']['on'] @property def supported_features(self): diff --git a/homeassistant/components/lock/zwave.py b/homeassistant/components/lock/zwave.py index e9199290e30..009d4cf1069 100644 --- a/homeassistant/components/lock/zwave.py +++ b/homeassistant/components/lock/zwave.py @@ -251,7 +251,7 @@ class ZwaveLock(zwave.ZWaveDeviceEntity, LockDevice): if not alarm_type: return - if alarm_type is 21: + if alarm_type == 21: self._lock_status = '{}{}'.format( LOCK_ALARM_TYPE.get(str(alarm_type)), MANUAL_LOCK_ALARM_LEVEL.get(str(alarm_level))) @@ -260,7 +260,7 @@ class ZwaveLock(zwave.ZWaveDeviceEntity, LockDevice): self._lock_status = '{}{}'.format( LOCK_ALARM_TYPE.get(str(alarm_type)), str(alarm_level)) return - if alarm_type is 161: + if alarm_type == 161: self._lock_status = '{}{}'.format( LOCK_ALARM_TYPE.get(str(alarm_type)), TAMPER_ALARM_LEVEL.get(str(alarm_level))) diff --git a/homeassistant/components/logbook.py b/homeassistant/components/logbook.py index 29c69409774..4facf1334c6 100644 --- a/homeassistant/components/logbook.py +++ b/homeassistant/components/logbook.py @@ -367,14 +367,12 @@ def _entry_message_from_state(domain, state): if domain == 'device_tracker': if state.state == STATE_NOT_HOME: return 'is away' - else: - return 'is at {}'.format(state.state) + return 'is at {}'.format(state.state) elif domain == 'sun': if state.state == sun.STATE_ABOVE_HORIZON: return 'has risen' - else: - return 'has set' + return 'has set' elif state.state == STATE_ON: # Future: combine groups and its entity entries ? diff --git a/homeassistant/components/media_player/__init__.py b/homeassistant/components/media_player/__init__.py index e17935814cc..35981d89d6d 100644 --- a/homeassistant/components/media_player/__init__.py +++ b/homeassistant/components/media_player/__init__.py @@ -801,8 +801,7 @@ class MediaPlayerDevice(Entity): if self.state in [STATE_OFF, STATE_IDLE]: return self.async_turn_on() - else: - return self.async_turn_off() + return self.async_turn_off() @asyncio.coroutine def async_volume_up(self): @@ -845,8 +844,7 @@ class MediaPlayerDevice(Entity): if self.state == STATE_PLAYING: return self.async_media_pause() - else: - return self.async_media_play() + return self.async_media_play() @property def entity_picture(self): diff --git a/homeassistant/components/media_player/cast.py b/homeassistant/components/media_player/cast.py index e4ecd1bd37d..418d3576750 100644 --- a/homeassistant/components/media_player/cast.py +++ b/homeassistant/components/media_player/cast.py @@ -131,8 +131,7 @@ class CastDevice(MediaPlayerDevice): return STATE_IDLE elif self.cast.is_idle: return STATE_OFF - else: - return STATE_UNKNOWN + return STATE_UNKNOWN @property def volume_level(self): diff --git a/homeassistant/components/media_player/denonavr.py b/homeassistant/components/media_player/denonavr.py index 5f3b88ccf52..2bdc03c20ab 100644 --- a/homeassistant/components/media_player/denonavr.py +++ b/homeassistant/components/media_player/denonavr.py @@ -197,8 +197,7 @@ class DenonDevice(MediaPlayerDevice): """Flag media player features that are supported.""" if self._current_source in self._receiver.netaudio_func_list: return SUPPORT_DENON | SUPPORT_MEDIA_MODES - else: - return SUPPORT_DENON + return SUPPORT_DENON @property def media_content_id(self): @@ -210,8 +209,7 @@ class DenonDevice(MediaPlayerDevice): """Content type of current playing media.""" if self._state == STATE_PLAYING or self._state == STATE_PAUSED: return MEDIA_TYPE_MUSIC - else: - return MEDIA_TYPE_CHANNEL + return MEDIA_TYPE_CHANNEL @property def media_duration(self): @@ -223,8 +221,7 @@ class DenonDevice(MediaPlayerDevice): """Image url of current playing media.""" if self._current_source in self._receiver.playing_func_list: return self._media_image_url - else: - return None + return None @property def media_title(self): @@ -233,24 +230,21 @@ class DenonDevice(MediaPlayerDevice): return self._current_source elif self._title is not None: return self._title - else: - return self._frequency + return self._frequency @property def media_artist(self): """Artist of current playing media, music track only.""" if self._artist is not None: return self._artist - else: - return self._band + return self._band @property def media_album_name(self): """Album name of current playing media, music track only.""" if self._album is not None: return self._album - else: - return self._station + return self._station @property def media_album_artist(self): @@ -297,17 +291,11 @@ class DenonDevice(MediaPlayerDevice): """Turn on media player.""" if self._receiver.power_on(): self._state = STATE_ON - return True - else: - return False def turn_off(self): """Turn off media player.""" if self._receiver.power_off(): self._state = STATE_OFF - return True - else: - return False def volume_up(self): """Volume up the media player.""" @@ -327,11 +315,8 @@ class DenonDevice(MediaPlayerDevice): try: if self._receiver.set_volume(volume_denon): self._volume = volume_denon - return True - else: - return False except ValueError: - return False + pass def mute_volume(self, mute): """Send mute command.""" diff --git a/homeassistant/components/media_player/directv.py b/homeassistant/components/media_player/directv.py index c1b690bc370..75a828696d9 100644 --- a/homeassistant/components/media_player/directv.py +++ b/homeassistant/components/media_player/directv.py @@ -95,43 +95,37 @@ class DirecTvDevice(MediaPlayerDevice): if self._is_standby: return STATE_OFF # Haven't determined a way to see if the content is paused - else: - return STATE_PLAYING + return STATE_PLAYING @property def media_content_id(self): """Return the content ID of current playing media.""" if self._is_standby: return None - else: - return self._current['programId'] + return self._current['programId'] @property def media_duration(self): """Return the duration of current playing media in seconds.""" if self._is_standby: return None - else: - return self._current['duration'] + return self._current['duration'] @property def media_title(self): """Return the title of current playing media.""" if self._is_standby: return None - else: - return self._current['title'] + return self._current['title'] @property def media_series_title(self): """Return the title of current episode of TV show.""" if self._is_standby: return None - else: - if 'episodeTitle' in self._current: - return self._current['episodeTitle'] - else: - return None + elif 'episodeTitle' in self._current: + return self._current['episodeTitle'] + return None @property def supported_features(self): @@ -143,8 +137,7 @@ class DirecTvDevice(MediaPlayerDevice): """Return the content type of current playing media.""" if 'episodeTitle' in self._current: return MEDIA_TYPE_TVSHOW - else: - return MEDIA_TYPE_VIDEO + return MEDIA_TYPE_VIDEO @property def media_channel(self): diff --git a/homeassistant/components/media_player/philips_js.py b/homeassistant/components/media_player/philips_js.py index b79f3eeeb89..da572896ee0 100644 --- a/homeassistant/components/media_player/philips_js.py +++ b/homeassistant/components/media_player/philips_js.py @@ -90,8 +90,7 @@ class PhilipsTV(MediaPlayerDevice): """Flag media player features that are supported.""" if self._watching_tv: return SUPPORT_PHILIPS_JS_TV - else: - return SUPPORT_PHILIPS_JS + return SUPPORT_PHILIPS_JS @property def state(self): @@ -162,13 +161,9 @@ class PhilipsTV(MediaPlayerDevice): @property def media_title(self): """Title of current playing media.""" - if self._watching_tv: - if self._channel_name: - return '{} - {}'.format(self._source, self._channel_name) - else: - return self._source - else: - return self._source + if self._watching_tv and self._channel_name: + return '{} - {}'.format(self._source, self._channel_name) + return self._source @Throttle(MIN_TIME_BETWEEN_UPDATES) def update(self): diff --git a/homeassistant/components/media_player/spotify.py b/homeassistant/components/media_player/spotify.py index b3405707877..e6604297fa1 100644 --- a/homeassistant/components/media_player/spotify.py +++ b/homeassistant/components/media_player/spotify.py @@ -171,7 +171,7 @@ class SpotifyMediaPlayer(MediaPlayerDevice): for device in devices} device_diff = {name: id for name, id in self._devices.items() if old_devices.get(name, None) is None} - if len(device_diff) > 0: + if device_diff: _LOGGER.info("New Devices: %s", str(device_diff)) # Current playback state current = self._player.current_playback() @@ -312,5 +312,4 @@ class SpotifyMediaPlayer(MediaPlayerDevice): """Return the media player features that are supported.""" if self._user is not None and self._user['product'] == 'premium': return SUPPORT_SPOTIFY - else: - return None + return None diff --git a/homeassistant/components/notify/sendgrid.py b/homeassistant/components/notify/sendgrid.py index a3d42f2be7d..6258f6272c0 100644 --- a/homeassistant/components/notify/sendgrid.py +++ b/homeassistant/components/notify/sendgrid.py @@ -74,5 +74,5 @@ class SendgridNotificationService(BaseNotificationService): } response = self._sg.client.mail.send.post(request_body=data) - if response.status_code is not 202: + if response.status_code != 202: _LOGGER.error("Unable to send notification") diff --git a/homeassistant/components/octoprint.py b/homeassistant/components/octoprint.py index b06b15c7973..0a099fc7349 100644 --- a/homeassistant/components/octoprint.py +++ b/homeassistant/components/octoprint.py @@ -100,12 +100,14 @@ class OctoPrintAPI(object): # pylint: disable=unused-variable def get_value_from_json(json_dict, sensor_type, group, tool): """Return the value for sensor_type from the JSON.""" - if group in json_dict: - if sensor_type in json_dict[group]: - if sensor_type == "target" and json_dict[sensor_type] is None: - return 0 - else: - return json_dict[group][sensor_type] - elif tool is not None: - if sensor_type in json_dict[group][tool]: - return json_dict[group][tool][sensor_type] + if group not in json_dict: + return None + + if sensor_type in json_dict[group]: + if sensor_type == "target" and json_dict[sensor_type] is None: + return 0 + return json_dict[group][sensor_type] + + elif tool is not None: + if sensor_type in json_dict[group][tool]: + return json_dict[group][tool][sensor_type] diff --git a/homeassistant/components/plant.py b/homeassistant/components/plant.py index cd43fbf715c..9b9e11e0fbb 100644 --- a/homeassistant/components/plant.py +++ b/homeassistant/components/plant.py @@ -204,13 +204,13 @@ class Plant(Entity): result.append('{} high'.format(sensor_name)) self._icon = params['icon'] - if len(result) == 0: + if result: + self._state = STATE_PROBLEM + self._problems = ','.join(result) + else: self._state = STATE_OK self._icon = 'mdi:thumb-up' self._problems = PROBLEM_NONE - else: - self._state = STATE_PROBLEM - self._problems = ','.join(result) _LOGGER.debug("New data processed") self.hass.async_add_job(self.async_update_ha_state()) diff --git a/homeassistant/components/qwikswitch.py b/homeassistant/components/qwikswitch.py index dd8ceefb169..d5d6f657bc6 100644 --- a/homeassistant/components/qwikswitch.py +++ b/homeassistant/components/qwikswitch.py @@ -183,10 +183,10 @@ def setup(hass, config): qsreply = qsusb.devices() if qsreply is False: return - for item in qsreply: - if item[QS_ID] in QSUSB: - QSUSB[item[QS_ID]].update_value( - round(min(item[PQS_VALUE], 100) * 2.55)) + for itm in qsreply: + if itm[QS_ID] in QSUSB: + QSUSB[itm[QS_ID]].update_value( + round(min(itm[PQS_VALUE], 100) * 2.55)) def _start(event): """Start listening.""" diff --git a/homeassistant/components/rflink.py b/homeassistant/components/rflink.py index 74772943691..6de5788b1dc 100644 --- a/homeassistant/components/rflink.py +++ b/homeassistant/components/rflink.py @@ -85,8 +85,7 @@ def identify_event_type(event): return EVENT_KEY_COMMAND elif EVENT_KEY_SENSOR in event: return EVENT_KEY_SENSOR - else: - return 'unknown' + return 'unknown' @asyncio.coroutine diff --git a/homeassistant/components/sensor/arest.py b/homeassistant/components/sensor/arest.py index b7e224a7447..19860ba84fd 100644 --- a/homeassistant/components/sensor/arest.py +++ b/homeassistant/components/sensor/arest.py @@ -123,7 +123,7 @@ class ArestSensor(Entity): if self._pin is not None: request = requests.get( '{}/mode/{}/i'.format(self._resource, self._pin), timeout=10) - if request.status_code is not 200: + if request.status_code != 200: _LOGGER.error("Can't set mode of %s", self._resource) @property diff --git a/homeassistant/components/sensor/dublin_bus_transport.py b/homeassistant/components/sensor/dublin_bus_transport.py index f1dda41c05f..f6d791f9fd6 100644 --- a/homeassistant/components/sensor/dublin_bus_transport.py +++ b/homeassistant/components/sensor/dublin_bus_transport.py @@ -141,7 +141,7 @@ class PublicTransportData(object): params = {} params['stopid'] = self.stop - if len(self.route) > 0: + if self.route: params['routeid'] = self.route params['maxresults'] = 2 diff --git a/homeassistant/components/sensor/homematic.py b/homeassistant/components/sensor/homematic.py index 30db91bc8b0..771b4a94bd4 100644 --- a/homeassistant/components/sensor/homematic.py +++ b/homeassistant/components/sensor/homematic.py @@ -56,8 +56,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): return devices = [] - for config in discovery_info[ATTR_DISCOVER_DEVICES]: - new_device = HMSensor(hass, config) + for conf in discovery_info[ATTR_DISCOVER_DEVICES]: + new_device = HMSensor(hass, conf) new_device.link_homematic() devices.append(new_device) diff --git a/homeassistant/components/sensor/mfi.py b/homeassistant/components/sensor/mfi.py index 9d78ffd3f1a..ecea0815e79 100644 --- a/homeassistant/components/sensor/mfi.py +++ b/homeassistant/components/sensor/mfi.py @@ -56,7 +56,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): password = config.get(CONF_PASSWORD) use_tls = config.get(CONF_SSL) verify_tls = config.get(CONF_VERIFY_SSL) - default_port = use_tls and 6443 or 6080 + default_port = 6443 if use_tls else 6080 port = int(config.get(CONF_PORT, default_port)) from mficlient.client import FailedToLogin, MFiClient @@ -97,10 +97,9 @@ class MfiSensor(Entity): if tag is None: return STATE_OFF elif self._port.model == 'Input Digital': - return self._port.value > 0 and STATE_ON or STATE_OFF - else: - digits = DIGITS.get(self._port.tag, 0) - return round(self._port.value, digits) + return STATE_ON if self._port.value > 0 else STATE_OFF + digits = DIGITS.get(self._port.tag, 0) + return round(self._port.value, digits) @property def unit_of_measurement(self): diff --git a/homeassistant/components/sensor/mold_indicator.py b/homeassistant/components/sensor/mold_indicator.py index 4b1b740093e..ccebd93dbec 100644 --- a/homeassistant/components/sensor/mold_indicator.py +++ b/homeassistant/components/sensor/mold_indicator.py @@ -242,10 +242,9 @@ class MoldIndicator(Entity): ATTR_DEWPOINT: self._dewpoint, ATTR_CRITICAL_TEMP: self._crit_temp, } - else: - return { - ATTR_DEWPOINT: - util.temperature.celsius_to_fahrenheit(self._dewpoint), - ATTR_CRITICAL_TEMP: - util.temperature.celsius_to_fahrenheit(self._crit_temp), - } + return { + ATTR_DEWPOINT: + util.temperature.celsius_to_fahrenheit(self._dewpoint), + ATTR_CRITICAL_TEMP: + util.temperature.celsius_to_fahrenheit(self._crit_temp), + } diff --git a/homeassistant/components/sensor/openhardwaremonitor.py b/homeassistant/components/sensor/openhardwaremonitor.py index 1d805916d97..54ce5dbd6da 100644 --- a/homeassistant/components/sensor/openhardwaremonitor.py +++ b/homeassistant/components/sensor/openhardwaremonitor.py @@ -147,13 +147,13 @@ class OpenHardwareMonitorData(object): """Recursively loop through child objects, finding the values.""" result = devices.copy() - if len(json[OHM_CHILDREN]) > 0: + if json[OHM_CHILDREN]: for child_index in range(0, len(json[OHM_CHILDREN])): child_path = path.copy() child_path.append(child_index) child_names = names.copy() - if len(path) > 0: + if path: child_names.append(json[OHM_NAME]) obj = json[OHM_CHILDREN][child_index] diff --git a/homeassistant/components/sensor/uber.py b/homeassistant/components/sensor/uber.py index 2830b8c98e9..42d6cad43f2 100644 --- a/homeassistant/components/sensor/uber.py +++ b/homeassistant/components/sensor/uber.py @@ -58,7 +58,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): continue dev.append(UberSensor('time', timeandpriceest, product_id, product)) if (product.get('price_details') is not None) and \ - product['price_details']['estimate'] is not 'Metered': + product['price_details']['estimate'] != 'Metered': dev.append(UberSensor( 'price', timeandpriceest, product_id, product)) add_devices(dev) diff --git a/homeassistant/components/sensor/zha.py b/homeassistant/components/sensor/zha.py index 78627674c55..7ac76a35b79 100644 --- a/homeassistant/components/sensor/zha.py +++ b/homeassistant/components/sensor/zha.py @@ -57,10 +57,6 @@ class Sensor(zha.Entity): value_attribute = 0 min_reportable_change = 1 - def __init__(self, **kwargs): - """Initialize ZHA sensor.""" - super().__init__(**kwargs) - @property def state(self) -> str: """Return the state of the entity.""" diff --git a/homeassistant/components/switch/arest.py b/homeassistant/components/switch/arest.py index eba05c64555..6e31694fd2d 100644 --- a/homeassistant/components/switch/arest.py +++ b/homeassistant/components/switch/arest.py @@ -102,7 +102,7 @@ class ArestSwitchFunction(ArestSwitchBase): request = requests.get( '{}/{}'.format(self._resource, self._func), timeout=10) - if request.status_code is not 200: + if request.status_code != 200: _LOGGER.error("Can't find function") return @@ -159,7 +159,7 @@ class ArestSwitchPin(ArestSwitchBase): request = requests.get( '{}/mode/{}/o'.format(self._resource, self._pin), timeout=10) - if request.status_code is not 200: + if request.status_code != 200: _LOGGER.error("Can't set mode") self._available = False diff --git a/homeassistant/components/switch/bbb_gpio.py b/homeassistant/components/switch/bbb_gpio.py index ce2d91273f9..6dc5df4ffe3 100644 --- a/homeassistant/components/switch/bbb_gpio.py +++ b/homeassistant/components/switch/bbb_gpio.py @@ -77,13 +77,13 @@ class BBBGPIOSwitch(ToggleEntity): """Return true if device is on.""" return self._state - def turn_on(self): + def turn_on(self, **kwargs): """Turn the device on.""" bbb_gpio.write_output(self._pin, 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.""" bbb_gpio.write_output(self._pin, 1 if self._invert_logic else 0) self._state = False diff --git a/homeassistant/components/switch/broadlink.py b/homeassistant/components/switch/broadlink.py index ffa4aaea615..191718a31b3 100644 --- a/homeassistant/components/switch/broadlink.py +++ b/homeassistant/components/switch/broadlink.py @@ -244,10 +244,6 @@ class BroadlinkSP1Switch(BroadlinkRMSwitch): class BroadlinkSP2Switch(BroadlinkSP1Switch): """Representation of an Broadlink switch.""" - def __init__(self, friendly_name, device): - """Initialize the switch.""" - super().__init__(friendly_name, device) - @property def assumed_state(self): """Return true if unable to access real state of entity.""" diff --git a/homeassistant/components/switch/homematic.py b/homeassistant/components/switch/homematic.py index e67f293525c..566eff99828 100644 --- a/homeassistant/components/switch/homematic.py +++ b/homeassistant/components/switch/homematic.py @@ -20,8 +20,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): return devices = [] - for config in discovery_info[ATTR_DISCOVER_DEVICES]: - new_device = HMSwitch(hass, config) + for conf in discovery_info[ATTR_DISCOVER_DEVICES]: + new_device = HMSwitch(hass, conf) new_device.link_homematic() devices.append(new_device) diff --git a/homeassistant/components/switch/hook.py b/homeassistant/components/switch/hook.py index 00fb7fdd909..07425840b9a 100644 --- a/homeassistant/components/switch/hook.py +++ b/homeassistant/components/switch/hook.py @@ -122,7 +122,7 @@ class HookSmartHome(SwitchDevice): return data['return_value'] == '1' @asyncio.coroutine - def async_turn_on(self): + def async_turn_on(self, **kwargs): """Turn the device on asynchronously.""" _LOGGER.debug("Turning on: %s", self._name) url = '{}{}{}{}'.format( @@ -131,7 +131,7 @@ class HookSmartHome(SwitchDevice): self._state = success @asyncio.coroutine - def async_turn_off(self): + def async_turn_off(self, **kwargs): """Turn the device off asynchronously.""" _LOGGER.debug("Turning off: %s", self._name) url = '{}{}{}{}'.format( diff --git a/homeassistant/components/switch/mfi.py b/homeassistant/components/switch/mfi.py index 6f5dd655ba4..c0dc72440d3 100644 --- a/homeassistant/components/switch/mfi.py +++ b/homeassistant/components/switch/mfi.py @@ -47,7 +47,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): password = config.get(CONF_PASSWORD) use_tls = config.get(CONF_SSL) verify_tls = config.get(CONF_VERIFY_SSL) - default_port = use_tls and 6443 or 6080 + default_port = 6443 if use_tls else 6080 port = int(config.get(CONF_PORT, default_port)) from mficlient.client import FailedToLogin, MFiClient @@ -100,12 +100,12 @@ class MfiSwitch(SwitchDevice): self._port.data['output'] = float(self._target_state) self._target_state = None - def turn_on(self): + def turn_on(self, **kwargs): """Turn the switch on.""" self._port.control(True) self._target_state = True - def turn_off(self): + def turn_off(self, **kwargs): """Turn the switch off.""" self._port.control(False) self._target_state = False diff --git a/homeassistant/components/switch/mysensors.py b/homeassistant/components/switch/mysensors.py index c72ea1e4cfe..38f67ee3ee9 100644 --- a/homeassistant/components/switch/mysensors.py +++ b/homeassistant/components/switch/mysensors.py @@ -135,7 +135,7 @@ class MySensorsSwitch(mysensors.MySensorsDeviceEntity, SwitchDevice): return self._values[self.value_type] == STATE_ON return False - def turn_on(self): + def turn_on(self, **kwargs): """Turn the switch on.""" self.gateway.set_child_value( self.node_id, self.child_id, self.value_type, 1) @@ -144,7 +144,7 @@ class MySensorsSwitch(mysensors.MySensorsDeviceEntity, SwitchDevice): self._values[self.value_type] = STATE_ON self.schedule_update_ha_state() - def turn_off(self): + def turn_off(self, **kwargs): """Turn the switch off.""" self.gateway.set_child_value( self.node_id, self.child_id, self.value_type, 0) @@ -191,7 +191,7 @@ class MySensorsIRSwitch(MySensorsSwitch): # turn off switch after switch was turned on self.turn_off() - def turn_off(self): + def turn_off(self, **kwargs): """Turn the IR switch off.""" set_req = self.gateway.const.SetReq if set_req.V_LIGHT not in self._values: diff --git a/homeassistant/components/switch/pulseaudio_loopback.py b/homeassistant/components/switch/pulseaudio_loopback.py index 69b932ecf71..03f9e84b3c8 100644 --- a/homeassistant/components/switch/pulseaudio_loopback.py +++ b/homeassistant/components/switch/pulseaudio_loopback.py @@ -137,8 +137,7 @@ class PAServer(): self._current_module_state) if result and result.group(1).isdigit(): return int(result.group(1)) - else: - return -1 + return -1 class PALoopbackSwitch(SwitchDevice): diff --git a/homeassistant/components/switch/rachio.py b/homeassistant/components/switch/rachio.py index 63809fd4456..b86523ad959 100644 --- a/homeassistant/components/switch/rachio.py +++ b/homeassistant/components/switch/rachio.py @@ -52,18 +52,18 @@ def setup_platform(hass, config, add_devices, discovery_info=None): # Get and persist devices devices = _list_devices(rachio, manual_run_mins) - if len(devices) == 0: + if not devices: _LOGGER.error("No Rachio devices found in account " + person['username']) return False - else: - hass.data[DATA_RACHIO] = devices[0] - if len(devices) > 1: - _LOGGER.warning("Multiple Rachio devices found in account, " - "using " + hass.data[DATA_RACHIO].device_id) - else: - _LOGGER.info("Found Rachio device") + hass.data[DATA_RACHIO] = devices[0] + + if len(devices) > 1: + _LOGGER.warning("Multiple Rachio devices found in account, " + "using " + hass.data[DATA_RACHIO].device_id) + else: + _LOGGER.info("Found Rachio device") hass.data[DATA_RACHIO].update() add_devices(hass.data[DATA_RACHIO].list_zones()) diff --git a/homeassistant/components/switch/rpi_gpio.py b/homeassistant/components/switch/rpi_gpio.py index 18d05db2f28..ac38da1c6a7 100644 --- a/homeassistant/components/switch/rpi_gpio.py +++ b/homeassistant/components/switch/rpi_gpio.py @@ -73,13 +73,13 @@ class RPiGPIOSwitch(ToggleEntity): """Return true if device is on.""" return self._state - def turn_on(self): + def turn_on(self, **kwargs): """Turn the device on.""" rpi_gpio.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_gpio.write_output(self._port, 1 if self._invert_logic else 0) self._state = False diff --git a/homeassistant/components/switch/wemo.py b/homeassistant/components/switch/wemo.py index 1c6ad76ceba..972eb2d523e 100644 --- a/homeassistant/components/switch/wemo.py +++ b/homeassistant/components/switch/wemo.py @@ -195,7 +195,7 @@ class WemoSwitch(SwitchDevice): self.wemo.on() self.schedule_update_ha_state() - def turn_off(self): + def turn_off(self, **kwargs): """Turn the switch off.""" self._state = WEMO_OFF self.wemo.off() diff --git a/homeassistant/components/switch/wink.py b/homeassistant/components/switch/wink.py index b5feac5fc43..0076355665c 100644 --- a/homeassistant/components/switch/wink.py +++ b/homeassistant/components/switch/wink.py @@ -37,10 +37,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class WinkToggleDevice(WinkDevice, ToggleEntity): """Representation of a Wink toggle device.""" - def __init__(self, wink, hass): - """Initialize the Wink device.""" - super().__init__(wink, hass) - @asyncio.coroutine def async_added_to_hass(self): """Callback when entity is added to hass.""" diff --git a/homeassistant/components/tellduslive.py b/homeassistant/components/tellduslive.py index f923e09323c..01ccb981cfa 100644 --- a/homeassistant/components/tellduslive.py +++ b/homeassistant/components/tellduslive.py @@ -116,10 +116,9 @@ class TelldusLiveClient(object): return 'cover' elif device.methods & TURNON: return 'switch' - else: - _LOGGER.warning( - "Unidentified device type (methods: %d)", device.methods) - return 'switch' + _LOGGER.warning( + "Unidentified device type (methods: %d)", device.methods) + return 'switch' def discover(device_id, component): """Discover the component.""" diff --git a/homeassistant/components/vera.py b/homeassistant/components/vera.py index cef185bc21f..a156d87187c 100644 --- a/homeassistant/components/vera.py +++ b/homeassistant/components/vera.py @@ -122,8 +122,7 @@ def map_vera_device(vera_device, remap): if isinstance(vera_device, veraApi.VeraSwitch): if vera_device.device_id in remap: return 'light' - else: - return 'switch' + return 'switch' return None diff --git a/homeassistant/components/weather/__init__.py b/homeassistant/components/weather/__init__.py index 17a47fbc522..9e927da893e 100644 --- a/homeassistant/components/weather/__init__.py +++ b/homeassistant/components/weather/__init__.py @@ -165,6 +165,5 @@ class WeatherEntity(Entity): if hass_unit == TEMP_CELSIUS: return round(value, 1) - else: - # Users of fahrenheit generally expect integer units. - return round(value) + # Users of fahrenheit generally expect integer units. + return round(value) diff --git a/homeassistant/components/websocket_api.py b/homeassistant/components/websocket_api.py index 6566a20814b..e9f567c04d3 100644 --- a/homeassistant/components/websocket_api.py +++ b/homeassistant/components/websocket_api.py @@ -29,7 +29,7 @@ from homeassistant.components.http.ban import process_wrong_login DOMAIN = 'websocket_api' URL = '/api/websocket' -DEPENDENCIES = 'http', +DEPENDENCIES = ('http',) MAX_PENDING_MSG = 512 diff --git a/homeassistant/components/wink.py b/homeassistant/components/wink.py index c33e3b14502..1c0410a4aa0 100644 --- a/homeassistant/components/wink.py +++ b/homeassistant/components/wink.py @@ -277,5 +277,4 @@ class WinkDevice(Entity): """Return the devices tamper status.""" if hasattr(self.wink, 'tamper_detected'): return self.wink.tamper_detected() - else: - return None + return None diff --git a/homeassistant/components/zwave/__init__.py b/homeassistant/components/zwave/__init__.py index ba970f94e95..8670ae7b9e7 100755 --- a/homeassistant/components/zwave/__init__.py +++ b/homeassistant/components/zwave/__init__.py @@ -450,12 +450,11 @@ def setup(hass, config): "with selection %s", param, node_id, selection) return - else: - value.data = int(selection) - _LOGGER.info("Setting config parameter %s on Node %s " - "with selection %s", param, node_id, - selection) - return + value.data = int(selection) + _LOGGER.info("Setting config parameter %s on Node %s " + "with selection %s", param, node_id, + selection) + return node.set_config_param(param, selection, size) _LOGGER.info("Setting unknown config parameter %s on Node %s " "with selection %s", param, node_id, diff --git a/homeassistant/core.py b/homeassistant/core.py index c65566b42fa..d1779fe420d 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -335,9 +335,9 @@ class Event(object): return "".format( self.event_type, str(self.origin)[0], util.repr_helper(self.data)) - else: - return "".format(self.event_type, - str(self.origin)[0]) + + return "".format(self.event_type, + str(self.origin)[0]) def __eq__(self, other): """Return the comparison.""" @@ -783,8 +783,8 @@ class ServiceCall(object): if self.data: return "".format( self.domain, self.service, util.repr_helper(self.data)) - else: - return "".format(self.domain, self.service) + + return "".format(self.domain, self.service) class ServiceRegistry(object): diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index dc6c29ce735..da177bc4331 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -172,6 +172,7 @@ class Entity(object): if async_update is None: return + # pylint: disable=not-callable run_coroutine_threadsafe(async_update(), self.hass.loop).result() # DO NOT OVERWRITE @@ -391,5 +392,4 @@ class ToggleEntity(Entity): """ if self.is_on: return self.async_turn_off() - else: - return self.async_turn_on() + return self.async_turn_on() diff --git a/homeassistant/helpers/event.py b/homeassistant/helpers/event.py index d3ad93d3646..9b64c08af18 100644 --- a/homeassistant/helpers/event.py +++ b/homeassistant/helpers/event.py @@ -312,8 +312,7 @@ def _process_state_match(parameter): return MATCH_ALL elif isinstance(parameter, str) or not hasattr(parameter, '__iter__'): return (parameter,) - else: - return tuple(parameter) + return tuple(parameter) def _process_time_match(parameter): @@ -324,8 +323,7 @@ def _process_time_match(parameter): return parameter elif isinstance(parameter, str) or not hasattr(parameter, '__iter__'): return (parameter,) - else: - return tuple(parameter) + return tuple(parameter) def _matcher(subject, pattern): diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index 77d0819e10d..6c74c49424e 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -47,7 +47,7 @@ def extract_entities(template): return MATCH_ALL extraction = _RE_GET_ENTITIES.findall(template) - if len(extraction) > 0: + if extraction: return list(set(extraction)) return MATCH_ALL diff --git a/homeassistant/remote.py b/homeassistant/remote.py index b65b3f3de22..9d026eddeff 100644 --- a/homeassistant/remote.py +++ b/homeassistant/remote.py @@ -92,10 +92,10 @@ class API(object): if method == METHOD_GET: return requests.get( url, params=data, timeout=timeout, headers=self._headers) - else: - return requests.request( - method, url, data=data, timeout=timeout, - headers=self._headers) + + return requests.request( + method, url, data=data, timeout=timeout, + headers=self._headers) except requests.exceptions.ConnectionError: _LOGGER.exception("Error connecting to server") @@ -152,8 +152,7 @@ def validate_api(api): elif req.status_code == 401: return APIStatus.INVALID_PASSWORD - else: - return APIStatus.UNKNOWN + return APIStatus.UNKNOWN except HomeAssistantError: return APIStatus.CANNOT_CONNECT @@ -259,8 +258,8 @@ def set_state(api, entity_id, new_state, attributes=None, force_update=False): _LOGGER.error("Error changing state: %d - %s", req.status_code, req.text) return False - else: - return True + + return True except HomeAssistantError: _LOGGER.exception("Error setting state") diff --git a/homeassistant/scripts/check_config.py b/homeassistant/scripts/check_config.py index 1e06f96b3e4..05cf4d646f6 100644 --- a/homeassistant/scripts/check_config.py +++ b/homeassistant/scripts/check_config.py @@ -288,7 +288,7 @@ def dump_dict(layer, indent_count=3, listi=False, **kwargs): indent_str = indent_str[:-1] + '-' if isinstance(layer, Dict): for key, value in sorted(layer.items(), key=sort_dict_key): - if isinstance(value, dict) or isinstance(value, list): + if isinstance(value, (dict, list)): print(indent_str, key + ':', line_info(value, **kwargs)) dump_dict(value, indent_count + 2) else: diff --git a/homeassistant/util/__init__.py b/homeassistant/util/__init__.py index 616b9100815..fc9116dda52 100644 --- a/homeassistant/util/__init__.py +++ b/homeassistant/util/__init__.py @@ -56,8 +56,8 @@ def repr_helper(inp: Any) -> str: in inp.items()) elif isinstance(inp, datetime): return as_local(inp).isoformat() - else: - return str(inp) + + return str(inp) def convert(value: T, to_type: Callable[[T], U], @@ -303,8 +303,8 @@ class Throttle(object): result = method(*args, **kwargs) throttle[1] = utcnow() return result - else: - return None + + return None finally: throttle[0].release() diff --git a/homeassistant/util/temperature.py b/homeassistant/util/temperature.py index adaa8afcb57..b7e2412f293 100644 --- a/homeassistant/util/temperature.py +++ b/homeassistant/util/temperature.py @@ -26,5 +26,4 @@ def convert(temperature: float, from_unit: str, to_unit: str) -> float: return temperature elif from_unit == TEMP_CELSIUS: return celsius_to_fahrenheit(temperature) - else: - return fahrenheit_to_celsius(temperature) + return fahrenheit_to_celsius(temperature)