diff --git a/homeassistant/components/alarm_control_panel/alarmdotcom.py b/homeassistant/components/alarm_control_panel/alarmdotcom.py index 75d3bc9922d..d5c15d82396 100644 --- a/homeassistant/components/alarm_control_panel/alarmdotcom.py +++ b/homeassistant/components/alarm_control_panel/alarmdotcom.py @@ -92,8 +92,7 @@ class AlarmDotCom(alarm.AlarmControlPanel): return STATE_ALARM_ARMED_HOME elif self._alarm.state.lower() == 'armed away': return STATE_ALARM_ARMED_AWAY - else: - return STATE_UNKNOWN + return STATE_UNKNOWN @asyncio.coroutine def async_alarm_disarm(self, code=None): diff --git a/homeassistant/components/alarm_control_panel/envisalink.py b/homeassistant/components/alarm_control_panel/envisalink.py index 6029816ba76..f6d388a6c5b 100644 --- a/homeassistant/components/alarm_control_panel/envisalink.py +++ b/homeassistant/components/alarm_control_panel/envisalink.py @@ -113,8 +113,7 @@ class EnvisalinkAlarm(EnvisalinkDevice, alarm.AlarmControlPanel): """Regex for code format or None if no code is required.""" if self._code: return None - else: - return '^\\d{4,6}$' + return '^\\d{4,6}$' @property def state(self): diff --git a/homeassistant/components/alarm_control_panel/manual.py b/homeassistant/components/alarm_control_panel/manual.py index ba932a1c372..c87aea862d5 100644 --- a/homeassistant/components/alarm_control_panel/manual.py +++ b/homeassistant/components/alarm_control_panel/manual.py @@ -99,8 +99,7 @@ class ManualAlarm(alarm.AlarmControlPanel): self._trigger_time) < dt_util.utcnow(): if self._disarm_after_trigger: return STATE_ALARM_DISARMED - else: - return self._pre_trigger_state + return self._pre_trigger_state return self._state diff --git a/homeassistant/components/alarm_control_panel/simplisafe.py b/homeassistant/components/alarm_control_panel/simplisafe.py index 985d219865d..fadfbc41a6f 100644 --- a/homeassistant/components/alarm_control_panel/simplisafe.py +++ b/homeassistant/components/alarm_control_panel/simplisafe.py @@ -80,8 +80,7 @@ class SimpliSafeAlarm(alarm.AlarmControlPanel): """Return the name of the device.""" if self._name is not None: return self._name - else: - return 'Alarm {}'.format(self.simplisafe.location_id()) + return 'Alarm {}'.format(self.simplisafe.location_id()) @property def code_format(self): diff --git a/homeassistant/components/binary_sensor/flic.py b/homeassistant/components/binary_sensor/flic.py index f78ee75ae25..51fffae5cc0 100644 --- a/homeassistant/components/binary_sensor/flic.py +++ b/homeassistant/components/binary_sensor/flic.py @@ -199,11 +199,10 @@ class FlicButton(BinarySensorDevice): "Queued %s dropped for %s. Time in queue was %s", click_type, self.address, time_string) return True - else: - _LOGGER.info( - "Queued %s allowed for %s. Time in queue was %s", - click_type, self.address, time_string) - return False + _LOGGER.info( + "Queued %s allowed for %s. Time in queue was %s", + click_type, self.address, time_string) + return False def _on_up_down(self, channel, click_type, was_queued, time_diff): """Update device state, if event was not queued.""" diff --git a/homeassistant/components/binary_sensor/homematic.py b/homeassistant/components/binary_sensor/homematic.py index 29ad5847b32..a82431a5ab8 100644 --- a/homeassistant/components/binary_sensor/homematic.py +++ b/homeassistant/components/binary_sensor/homematic.py @@ -34,8 +34,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): return devices = [] - for config in discovery_info[ATTR_DISCOVER_DEVICES]: - new_device = HMBinarySensor(hass, config) + for conf in discovery_info[ATTR_DISCOVER_DEVICES]: + new_device = HMBinarySensor(hass, conf) new_device.link_homematic() devices.append(new_device) diff --git a/homeassistant/components/binary_sensor/netatmo.py b/homeassistant/components/binary_sensor/netatmo.py index 70887e9391d..ac479ef4277 100644 --- a/homeassistant/components/binary_sensor/netatmo.py +++ b/homeassistant/components/binary_sensor/netatmo.py @@ -156,8 +156,7 @@ class NetatmoBinarySensor(BinarySensorDevice): return WELCOME_SENSOR_TYPES.get(self._sensor_name) elif self._cameratype == 'NOC': return PRESENCE_SENSOR_TYPES.get(self._sensor_name) - else: - return TAG_SENSOR_TYPES.get(self._sensor_name) + return TAG_SENSOR_TYPES.get(self._sensor_name) @property def is_on(self): diff --git a/homeassistant/components/binary_sensor/ping.py b/homeassistant/components/binary_sensor/ping.py index 4a23b2e42ca..cb5bc4333a2 100644 --- a/homeassistant/components/binary_sensor/ping.py +++ b/homeassistant/components/binary_sensor/ping.py @@ -126,14 +126,14 @@ class PingData(object): 'avg': rtt_avg, 'max': rtt_max, 'mdev': ''} - else: - match = PING_MATCHER.search(str(out).split('\n')[-1]) - rtt_min, rtt_avg, rtt_max, rtt_mdev = match.groups() - return { - 'min': rtt_min, - 'avg': rtt_avg, - 'max': rtt_max, - 'mdev': rtt_mdev} + + match = PING_MATCHER.search(str(out).split('\n')[-1]) + rtt_min, rtt_avg, rtt_max, rtt_mdev = match.groups() + return { + 'min': rtt_min, + 'avg': rtt_avg, + 'max': rtt_max, + 'mdev': rtt_mdev} except (subprocess.CalledProcessError, AttributeError): return False diff --git a/homeassistant/components/binary_sensor/volvooncall.py b/homeassistant/components/binary_sensor/volvooncall.py index 2c7c398d91a..471b3917054 100644 --- a/homeassistant/components/binary_sensor/volvooncall.py +++ b/homeassistant/components/binary_sensor/volvooncall.py @@ -30,8 +30,7 @@ class VolvoSensor(VolvoEntity, BinarySensorDevice): return bool(val) elif self._attribute in ['doors', 'windows']: return any([val[key] for key in val if 'Open' in key]) - else: - return val != 'Normal' + return val != 'Normal' @property def device_class(self): diff --git a/homeassistant/components/calendar/__init__.py b/homeassistant/components/calendar/__init__.py index 2ccd591db2c..4e088c8a640 100644 --- a/homeassistant/components/calendar/__init__.py +++ b/homeassistant/components/calendar/__init__.py @@ -148,8 +148,7 @@ class CalendarEventDevice(Entity): if 'date' in date: return dt.start_of_local_day(dt.dt.datetime.combine( dt.parse_date(date['date']), dt.dt.time.min)) - else: - return dt.as_local(dt.parse_datetime(date['dateTime'])) + return dt.as_local(dt.parse_datetime(date['dateTime'])) start = _get_date(self.data.event['start']) end = _get_date(self.data.event['end']) diff --git a/homeassistant/components/camera/__init__.py b/homeassistant/components/camera/__init__.py index c84421f50ea..5b97e102d8d 100644 --- a/homeassistant/components/camera/__init__.py +++ b/homeassistant/components/camera/__init__.py @@ -266,8 +266,7 @@ class Camera(Entity): return STATE_RECORDING elif self.is_streaming: return STATE_STREAMING - else: - return STATE_IDLE + return STATE_IDLE def enable_motion_detection(self): """Enable motion detection in the camera.""" diff --git a/homeassistant/components/camera/netatmo.py b/homeassistant/components/camera/netatmo.py index e5f22cced16..c1ec2db0a08 100644 --- a/homeassistant/components/camera/netatmo.py +++ b/homeassistant/components/camera/netatmo.py @@ -113,8 +113,7 @@ class NetatmoCamera(Camera): return "Presence" elif self._cameratype == "NACamera": return "Welcome" - else: - return None + return None @property def unique_id(self): diff --git a/homeassistant/components/climate/__init__.py b/homeassistant/components/climate/__init__.py index d00d30c3b19..5b6c025b3e3 100644 --- a/homeassistant/components/climate/__init__.py +++ b/homeassistant/components/climate/__init__.py @@ -398,16 +398,14 @@ class ClimateDevice(Entity): """Return the current state.""" if self.current_operation: return self.current_operation - else: - return STATE_UNKNOWN + return STATE_UNKNOWN @property def precision(self): """Return the precision of the system.""" if self.unit_of_measurement == TEMP_CELSIUS: return PRECISION_TENTHS - else: - return PRECISION_WHOLE + return PRECISION_WHOLE @property def state_attributes(self): @@ -709,6 +707,5 @@ class ClimateDevice(Entity): return round(temp * 2) / 2.0 elif self.precision == PRECISION_TENTHS: return round(temp, 1) - else: - # PRECISION_WHOLE as a fall back - return round(temp) + # PRECISION_WHOLE as a fall back + return round(temp) diff --git a/homeassistant/components/climate/ecobee.py b/homeassistant/components/climate/ecobee.py index 9e04013d53f..6780d3745f0 100644 --- a/homeassistant/components/climate/ecobee.py +++ b/homeassistant/components/climate/ecobee.py @@ -151,16 +151,14 @@ class Thermostat(ClimateDevice): """Return the lower bound temperature we try to reach.""" if self.current_operation == STATE_AUTO: return int(self.thermostat['runtime']['desiredHeat'] / 10) - else: - return None + return None @property def target_temperature_high(self): """Return the upper bound temperature we try to reach.""" if self.current_operation == STATE_AUTO: return int(self.thermostat['runtime']['desiredCool'] / 10) - else: - return None + return None @property def target_temperature(self): @@ -171,8 +169,7 @@ class Thermostat(ClimateDevice): return int(self.thermostat['runtime']['desiredHeat'] / 10) elif self.current_operation == STATE_COOL: return int(self.thermostat['runtime']['desiredCool'] / 10) - else: - return None + return None @property def desired_fan_mode(self): @@ -184,8 +181,7 @@ class Thermostat(ClimateDevice): """Return the current fan state.""" if 'fan' in self.thermostat['equipmentStatus']: return STATE_ON - else: - return STATE_OFF + return STATE_OFF @property def current_hold_mode(self): @@ -199,15 +195,13 @@ class Thermostat(ClimateDevice): int(event['startDate'][0:4]) <= 1: # A temporary hold from away climate is a hold return 'away' - else: - # A permanent hold from away climate is away_mode - return None + # A permanent hold from away climate is away_mode + return None elif event['holdClimateRef'] != "": # Any other hold based on climate return event['holdClimateRef'] - else: - # Any hold not based on a climate is a temp hold - return TEMPERATURE_HOLD + # Any hold not based on a climate is a temp hold + return TEMPERATURE_HOLD elif event['type'].startswith('auto'): # All auto modes are treated as holds return event['type'][4:].lower() @@ -222,8 +216,7 @@ class Thermostat(ClimateDevice): if self.operation_mode == 'auxHeatOnly' or \ self.operation_mode == 'heatPump': return STATE_HEAT - else: - return self.operation_mode + return self.operation_mode @property def operation_list(self): @@ -384,8 +377,7 @@ class Thermostat(ClimateDevice): # add further conditions if other hold durations should be # supported; note that this should not include 'indefinite' # as an indefinite away hold is interpreted as away_mode - else: - return 'nextTransition' + return 'nextTransition' @property def climate_list(self): diff --git a/homeassistant/components/climate/generic_thermostat.py b/homeassistant/components/climate/generic_thermostat.py index 11400466c4f..6e7ba3cffed 100644 --- a/homeassistant/components/climate/generic_thermostat.py +++ b/homeassistant/components/climate/generic_thermostat.py @@ -134,9 +134,9 @@ class GenericThermostat(ClimateDevice): if self.ac_mode: cooling = self._active and self._is_device_active return STATE_COOL if cooling else STATE_IDLE - else: - heating = self._active and self._is_device_active - return STATE_HEAT if heating else STATE_IDLE + + heating = self._active and self._is_device_active + return STATE_HEAT if heating else STATE_IDLE @property def target_temperature(self): @@ -159,9 +159,9 @@ class GenericThermostat(ClimateDevice): # pylint: disable=no-member if self._min_temp: return self._min_temp - else: - # get default temp from super class - return ClimateDevice.min_temp.fget(self) + + # get default temp from super class + return ClimateDevice.min_temp.fget(self) @property def max_temp(self): @@ -169,9 +169,9 @@ class GenericThermostat(ClimateDevice): # pylint: disable=no-member if self._max_temp: return self._max_temp - else: - # Get default temp from super class - return ClimateDevice.max_temp.fget(self) + + # Get default temp from super class + return ClimateDevice.max_temp.fget(self) @asyncio.coroutine def _async_sensor_changed(self, entity_id, old_state, new_state): diff --git a/homeassistant/components/climate/honeywell.py b/homeassistant/components/climate/honeywell.py index 94c48258bf5..65e30e3cb26 100644 --- a/homeassistant/components/climate/honeywell.py +++ b/homeassistant/components/climate/honeywell.py @@ -60,8 +60,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): if region == 'us': return _setup_us(username, password, config, add_devices) - else: - return _setup_round(username, password, config, add_devices) + + return _setup_round(username, password, config, add_devices) def _setup_round(username, password, config, add_devices): @@ -251,8 +251,7 @@ class HoneywellUSThermostat(ClimateDevice): """Return the temperature we try to reach.""" if self._device.system_mode == 'cool': return self._device.setpoint_cool - else: - return self._device.setpoint_heat + return self._device.setpoint_heat @property def current_operation(self: ClimateDevice) -> str: diff --git a/homeassistant/components/climate/nest.py b/homeassistant/components/climate/nest.py index 522a1bebb16..ac4f64f4ec8 100644 --- a/homeassistant/components/climate/nest.py +++ b/homeassistant/components/climate/nest.py @@ -109,16 +109,14 @@ class NestThermostat(ClimateDevice): return self._mode elif self._mode == STATE_HEAT_COOL: return STATE_AUTO - else: - return STATE_UNKNOWN + return STATE_UNKNOWN @property def target_temperature(self): """Return the temperature we try to reach.""" if self._mode != STATE_HEAT_COOL and not self.is_away_mode_on: return self._target_temperature - else: - return None + return None @property def target_temperature_low(self): @@ -129,8 +127,7 @@ class NestThermostat(ClimateDevice): return self._eco_temperature[0] if self._mode == STATE_HEAT_COOL: return self._target_temperature[0] - else: - return None + return None @property def target_temperature_high(self): @@ -141,8 +138,7 @@ class NestThermostat(ClimateDevice): return self._eco_temperature[1] if self._mode == STATE_HEAT_COOL: return self._target_temperature[1] - else: - return None + return None @property def is_away_mode_on(self): @@ -188,9 +184,8 @@ class NestThermostat(ClimateDevice): if self._has_fan: # Return whether the fan is on return STATE_ON if self._fan else STATE_AUTO - else: - # No Fan available so disable slider - return None + # No Fan available so disable slider + return None @property def fan_list(self): diff --git a/homeassistant/components/climate/oem.py b/homeassistant/components/climate/oem.py index fd43ff799db..5909f26eb4f 100644 --- a/homeassistant/components/climate/oem.py +++ b/homeassistant/components/climate/oem.py @@ -92,8 +92,7 @@ class ThermostatDevice(ClimateDevice): """Return current operation i.e. heat, cool, idle.""" if self._state: return STATE_HEAT - else: - return STATE_IDLE + return STATE_IDLE @property def current_temperature(self): diff --git a/homeassistant/components/climate/sensibo.py b/homeassistant/components/climate/sensibo.py index 501a346d8c5..c55b4c9ce0d 100644 --- a/homeassistant/components/climate/sensibo.py +++ b/homeassistant/components/climate/sensibo.py @@ -117,9 +117,8 @@ class SensiboClimate(ClimateDevice): # We are working in same units as the a/c unit. Use whole degrees # like the API supports. return 1 - else: - # Unit conversion is going on. No point to stick to specific steps. - return None + # Unit conversion is going on. No point to stick to specific steps. + return None @property def current_operation(self): diff --git a/homeassistant/components/climate/tado.py b/homeassistant/components/climate/tado.py index 832bca6f9b6..8a2e6621af3 100644 --- a/homeassistant/components/climate/tado.py +++ b/homeassistant/components/climate/tado.py @@ -52,7 +52,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): zones = tado.get_zones() except RuntimeError: _LOGGER.error("Unable to get zone info from mytado") - return False + return climate_devices = [] for zone in zones: @@ -61,9 +61,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): if climate_devices: add_devices(climate_devices, True) - return True - else: - return False def create_climate_device(tado, hass, zone, name, zone_id): @@ -150,8 +147,7 @@ class TadoClimate(ClimateDevice): """Return current readable operation mode.""" if self._cooling: return "Cooling" - else: - return OPERATION_LIST.get(self._current_operation) + return OPERATION_LIST.get(self._current_operation) @property def operation_list(self): @@ -163,16 +159,14 @@ class TadoClimate(ClimateDevice): """Return the fan setting.""" if self.ac_mode: return FAN_MODES_LIST.get(self._current_fan) - else: - return None + return None @property def fan_list(self): """List of available fan modes.""" if self.ac_mode: return list(FAN_MODES_LIST.values()) - else: - return None + return None @property def temperature_unit(self): @@ -218,18 +212,16 @@ class TadoClimate(ClimateDevice): """Return the minimum temperature.""" if self._min_temp: return self._min_temp - else: - # get default temp from super class - return super().min_temp + # get default temp from super class + return super().min_temp @property def max_temp(self): """Return the maximum temperature.""" if self._max_temp: return self._max_temp - else: - # Get default temp from super class - return super().max_temp + # Get default temp from super class + return super().max_temp def update(self): """Update the state of this climate device.""" diff --git a/homeassistant/components/climate/wink.py b/homeassistant/components/climate/wink.py index e3439bdfc74..f52340dc627 100644 --- a/homeassistant/components/climate/wink.py +++ b/homeassistant/components/climate/wink.py @@ -111,8 +111,8 @@ class WinkThermostat(WinkDevice, ClimateDevice): # This will address both possibilities if self.wink.current_humidity() < 1: return self.wink.current_humidity() * 100 - else: - return self.wink.current_humidity() + return self.wink.current_humidity() + return None @property def external_temperature(self): @@ -175,10 +175,7 @@ class WinkThermostat(WinkDevice, ClimateDevice): return self.wink.current_max_set_point() elif self.current_operation == STATE_HEAT: return self.wink.current_min_set_point() - else: - return None - else: - return None + return None @property def target_temperature_low(self): @@ -206,8 +203,7 @@ class WinkThermostat(WinkDevice, ClimateDevice): return True elif self.wink.current_hvac_mode() == 'aux' and not self.wink.is_on(): return False - else: - return None + return None def set_temperature(self, **kwargs): """Set new target temperature.""" @@ -270,9 +266,8 @@ class WinkThermostat(WinkDevice, ClimateDevice): return STATE_ON elif self.wink.current_fan_mode() == 'auto': return STATE_AUTO - else: - # No Fan available so disable slider - return None + # No Fan available so disable slider + return None @property def fan_list(self): @@ -451,8 +446,7 @@ class WinkAC(WinkDevice, ClimateDevice): return SPEED_MEDIUM elif speed <= 1.0 and speed > 0.8: return SPEED_HIGH - else: - return STATE_UNKNOWN + return STATE_UNKNOWN @property def fan_list(self): diff --git a/homeassistant/components/climate/zwave.py b/homeassistant/components/climate/zwave.py index 949bd10e0c2..497916a3e4d 100755 --- a/homeassistant/components/climate/zwave.py +++ b/homeassistant/components/climate/zwave.py @@ -154,8 +154,7 @@ class ZWaveClimate(ZWaveDeviceEntity, ClimateDevice): return TEMP_CELSIUS elif self._unit == 'F': return TEMP_FAHRENHEIT - else: - return self._unit + return self._unit @property def current_temperature(self): diff --git a/homeassistant/components/cover/command_line.py b/homeassistant/components/cover/command_line.py index cd48238cae9..6d43b1d2166 100644 --- a/homeassistant/components/cover/command_line.py +++ b/homeassistant/components/cover/command_line.py @@ -112,10 +112,7 @@ class CommandCover(CoverDevice): def is_closed(self): """Return if the cover is closed.""" if self.current_cover_position is not None: - if self.current_cover_position > 0: - return False - else: - return True + return self.current_cover_position == 0 @property def current_cover_position(self): diff --git a/homeassistant/components/cover/demo.py b/homeassistant/components/cover/demo.py index 35574150596..ed060659746 100644 --- a/homeassistant/components/cover/demo.py +++ b/homeassistant/components/cover/demo.py @@ -79,8 +79,7 @@ class DemoCover(CoverDevice): """Flag supported features.""" if self._supported_features is not None: return self._supported_features - else: - return super().supported_features + return super().supported_features def close_cover(self, **kwargs): """Close the cover.""" diff --git a/homeassistant/components/cover/garadget.py b/homeassistant/components/cover/garadget.py index 457312c8a4a..02e970a0d0b 100644 --- a/homeassistant/components/cover/garadget.py +++ b/homeassistant/components/cover/garadget.py @@ -159,8 +159,7 @@ class GaradgetCover(CoverDevice): """Return if the cover is closed.""" if self._state == STATE_UNKNOWN: return None - else: - return self._state == STATE_CLOSED + return self._state == STATE_CLOSED @property def device_class(self): diff --git a/homeassistant/components/cover/homematic.py b/homeassistant/components/cover/homematic.py index 8fb003c6649..e8372b84ce4 100644 --- a/homeassistant/components/cover/homematic.py +++ b/homeassistant/components/cover/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 = HMCover(hass, config) + for conf in discovery_info[ATTR_DISCOVER_DEVICES]: + new_device = HMCover(hass, conf) new_device.link_homematic() devices.append(new_device) @@ -52,10 +52,7 @@ class HMCover(HMDevice, CoverDevice): def is_closed(self): """Return if the cover is closed.""" if self.current_cover_position is not None: - if self.current_cover_position > 0: - return False - else: - return True + return self.current_cover_position == 0 def open_cover(self, **kwargs): """Open the cover.""" diff --git a/homeassistant/components/cover/mqtt.py b/homeassistant/components/cover/mqtt.py index a53e659c448..eab64fd7abb 100644 --- a/homeassistant/components/cover/mqtt.py +++ b/homeassistant/components/cover/mqtt.py @@ -361,8 +361,7 @@ class MqttCover(CoverDevice): position_percentage = float(offset_position) / tilt_range * 100.0 if self._tilt_invert: return 100 - position_percentage - else: - return position_percentage + return position_percentage def find_in_range_from_percent(self, percentage): """ diff --git a/homeassistant/components/cover/mysensors.py b/homeassistant/components/cover/mysensors.py index 43942dacd05..f48a2110eca 100644 --- a/homeassistant/components/cover/mysensors.py +++ b/homeassistant/components/cover/mysensors.py @@ -53,8 +53,7 @@ class MySensorsCover(mysensors.MySensorsDeviceEntity, CoverDevice): set_req = self.gateway.const.SetReq if set_req.V_DIMMER in self._values: return self._values.get(set_req.V_DIMMER) == 0 - else: - return self._values.get(set_req.V_LIGHT) == STATE_OFF + return self._values.get(set_req.V_LIGHT) == STATE_OFF @property def current_cover_position(self): diff --git a/homeassistant/components/cover/opengarage.py b/homeassistant/components/cover/opengarage.py index d22e8f9104c..d98c71e25fb 100644 --- a/homeassistant/components/cover/opengarage.py +++ b/homeassistant/components/cover/opengarage.py @@ -117,8 +117,7 @@ class OpenGarageCover(CoverDevice): """Return if the cover is closed.""" if self._state == STATE_UNKNOWN: return None - else: - return self._state in [STATE_CLOSED, STATE_OPENING] + return self._state in [STATE_CLOSED, STATE_OPENING] def close_cover(self): """Close the cover.""" diff --git a/homeassistant/components/cover/vera.py b/homeassistant/components/cover/vera.py index bcccf17da8a..05be125ec6f 100644 --- a/homeassistant/components/cover/vera.py +++ b/homeassistant/components/cover/vera.py @@ -53,10 +53,7 @@ class VeraCover(VeraDevice, CoverDevice): def is_closed(self): """Return if the cover is closed.""" if self.current_cover_position is not None: - if self.current_cover_position > 0: - return False - else: - return True + return self.current_cover_position == 0 def open_cover(self, **kwargs): """Open the cover.""" diff --git a/homeassistant/components/cover/zwave.py b/homeassistant/components/cover/zwave.py index b682bee3e20..6ec70d9a85a 100644 --- a/homeassistant/components/cover/zwave.py +++ b/homeassistant/components/cover/zwave.py @@ -73,8 +73,7 @@ class ZwaveRollershutter(zwave.ZWaveDeviceEntity, CoverDevice): return None if self.current_cover_position > 0: return False - else: - return True + return True @property def current_cover_position(self): @@ -86,8 +85,7 @@ class ZwaveRollershutter(zwave.ZWaveDeviceEntity, CoverDevice): return 0 elif self._current_position >= 95: return 100 - else: - return self._current_position + return self._current_position def open_cover(self, **kwargs): """Move the roller shutter up.""" diff --git a/homeassistant/components/device_tracker/bbox.py b/homeassistant/components/device_tracker/bbox.py index 0d0cdd7b1d5..23a94d093e2 100644 --- a/homeassistant/components/device_tracker/bbox.py +++ b/homeassistant/components/device_tracker/bbox.py @@ -52,8 +52,7 @@ class BboxDeviceScanner(DeviceScanner): if filter_named: return filter_named[0] - else: - return None + return None @Throttle(MIN_TIME_BETWEEN_SCANS) def _update_info(self): diff --git a/homeassistant/components/device_tracker/locative.py b/homeassistant/components/device_tracker/locative.py index ced24edde48..aee584aa953 100644 --- a/homeassistant/components/device_tracker/locative.py +++ b/homeassistant/components/device_tracker/locative.py @@ -94,21 +94,20 @@ class LocativeView(HomeAssistantView): partial(self.see, dev_id=device, location_name=location_name, gps=gps_location)) return 'Setting location to not home' - else: - # Ignore the message if it is telling us to exit a zone that we - # aren't currently in. This occurs when a zone is entered - # before the previous zone was exited. The enter message will - # be sent first, then the exit message will be sent second. - return 'Ignoring exit from {} (already in {})'.format( - location_name, current_state) + + # Ignore the message if it is telling us to exit a zone that we + # aren't currently in. This occurs when a zone is entered + # before the previous zone was exited. The enter message will + # be sent first, then the exit message will be sent second. + return 'Ignoring exit from {} (already in {})'.format( + location_name, current_state) elif direction == 'test': # In the app, a test message can be sent. Just return something to # the user to let them know that it works. return 'Received test message.' - else: - _LOGGER.error('Received unidentified message from Locative: %s', - direction) - return ('Received unidentified message: {}'.format(direction), - HTTP_UNPROCESSABLE_ENTITY) + _LOGGER.error('Received unidentified message from Locative: %s', + direction) + return ('Received unidentified message: {}'.format(direction), + HTTP_UNPROCESSABLE_ENTITY) diff --git a/homeassistant/components/device_tracker/nmap_tracker.py b/homeassistant/components/device_tracker/nmap_tracker.py index 99dfc3829d7..8a845adf0b8 100644 --- a/homeassistant/components/device_tracker/nmap_tracker.py +++ b/homeassistant/components/device_tracker/nmap_tracker.py @@ -95,8 +95,7 @@ class NmapDeviceScanner(DeviceScanner): if filter_named: return filter_named[0] - else: - return None + return None @Throttle(MIN_TIME_BETWEEN_SCANS) def _update_info(self): diff --git a/homeassistant/components/device_tracker/owntracks.py b/homeassistant/components/device_tracker/owntracks.py index 6aa44c17c9a..f88fda03cf7 100644 --- a/homeassistant/components/device_tracker/owntracks.py +++ b/homeassistant/components/device_tracker/owntracks.py @@ -131,8 +131,7 @@ def async_setup_scanner(hass, config, async_see, discovery_info=None): plaintext_payload = decrypt_payload(topic, data['data']) if plaintext_payload is None: return None - else: - return validate_payload(topic, plaintext_payload, data_type) + return validate_payload(topic, plaintext_payload, data_type) if not isinstance(data, dict) or data.get('_type') != data_type: _LOGGER.debug("Skipping %s update for following data " diff --git a/homeassistant/components/device_tracker/tado.py b/homeassistant/components/device_tracker/tado.py index 46096e62fbb..fca4998f7b5 100644 --- a/homeassistant/components/device_tracker/tado.py +++ b/homeassistant/components/device_tracker/tado.py @@ -90,8 +90,7 @@ class TadoDeviceScanner(DeviceScanner): if filter_named: return filter_named[0] - else: - return None + return None @Throttle(MIN_TIME_BETWEEN_SCANS) def _update_info(self): diff --git a/homeassistant/components/device_tracker/tomato.py b/homeassistant/components/device_tracker/tomato.py index 51394ae64fe..0b330c933d8 100644 --- a/homeassistant/components/device_tracker/tomato.py +++ b/homeassistant/components/device_tracker/tomato.py @@ -73,8 +73,8 @@ class TomatoDeviceScanner(DeviceScanner): if not filter_named or not filter_named[0]: return None - else: - return filter_named[0] + + return filter_named[0] @Throttle(MIN_TIME_BETWEEN_SCANS) def _update_tomato_info(self): diff --git a/homeassistant/components/device_tracker/tplink.py b/homeassistant/components/device_tracker/tplink.py index b34f16ebb5a..76744d56fcc 100755 --- a/homeassistant/components/device_tracker/tplink.py +++ b/homeassistant/components/device_tracker/tplink.py @@ -234,10 +234,9 @@ class Tplink3DeviceScanner(TplinkDeviceScanner): self.stok = '' self.sysauth = '' return False - else: - _LOGGER.error( - "An unknown error happened while fetching data") - return False + _LOGGER.error( + "An unknown error happened while fetching data") + return False except ValueError: _LOGGER.error("Router didn't respond with JSON. " "Check if credentials are correct") diff --git a/homeassistant/components/device_tracker/xiaomi.py b/homeassistant/components/device_tracker/xiaomi.py index e87cae3d50b..a7b0a1ad326 100644 --- a/homeassistant/components/device_tracker/xiaomi.py +++ b/homeassistant/components/device_tracker/xiaomi.py @@ -101,10 +101,10 @@ class XiaomiDeviceScanner(DeviceScanner): result = _retrieve_list(self.host, self.token) if result: return result - else: - _LOGGER.info("Refreshing token and retrying device list refresh") - self.token = _get_token(self.host, self.username, self.password) - return _retrieve_list(self.host, self.token) + + _LOGGER.info("Refreshing token and retrying device list refresh") + self.token = _get_token(self.host, self.username, self.password) + return _retrieve_list(self.host, self.token) def _store_result(self, result): """Extract and store the device list in self.last_results.""" diff --git a/homeassistant/components/fan/dyson.py b/homeassistant/components/fan/dyson.py index b8f330fd1f4..a2fb2b95ec4 100644 --- a/homeassistant/components/fan/dyson.py +++ b/homeassistant/components/fan/dyson.py @@ -157,8 +157,7 @@ class DysonPureCoolLinkDevice(FanEntity): from libpurecoollink.const import FanSpeed if self._device.state.speed == FanSpeed.FAN_SPEED_AUTO.value: return self._device.state.speed - else: - return int(self._device.state.speed) + return int(self._device.state.speed) return None @property diff --git a/homeassistant/components/fan/wink.py b/homeassistant/components/fan/wink.py index 13f755bcdf3..c649009b230 100644 --- a/homeassistant/components/fan/wink.py +++ b/homeassistant/components/fan/wink.py @@ -33,10 +33,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class WinkFanDevice(WinkDevice, FanEntity): """Representation of a Wink fan.""" - def __init__(self, wink, hass): - """Initialize the fan.""" - super().__init__(wink, hass) - @asyncio.coroutine def async_added_to_hass(self): """Callback when entity is added to hass.""" diff --git a/homeassistant/components/image_processing/dlib_face_identify.py b/homeassistant/components/image_processing/dlib_face_identify.py index 0930e42ba7d..8df6de91da4 100644 --- a/homeassistant/components/image_processing/dlib_face_identify.py +++ b/homeassistant/components/image_processing/dlib_face_identify.py @@ -57,9 +57,9 @@ class DlibFaceIdentifyEntity(ImageProcessingFaceEntity): split_entity_id(camera_entity)[1]) self._faces = {} - for name, face_file in faces.items(): + for face_name, face_file in faces.items(): image = face_recognition.load_image_file(face_file) - self._faces[name] = face_recognition.face_encodings(image)[0] + self._faces[face_name] = face_recognition.face_encodings(image)[0] @property def camera_entity(self): diff --git a/homeassistant/components/light/tellstick.py b/homeassistant/components/light/tellstick.py index d2a6dadd9da..98af61ffb7d 100644 --- a/homeassistant/components/light/tellstick.py +++ b/homeassistant/components/light/tellstick.py @@ -60,8 +60,7 @@ class TellstickLight(TellstickDevice, Light): if tellcore_data is not None: brightness = int(tellcore_data) return brightness - else: - return None + return None def _update_model(self, new_state, data): """Update the device entity state to match the arguments.""" diff --git a/homeassistant/components/light/vera.py b/homeassistant/components/light/vera.py index 3d19c3fcea2..b3be93d82e2 100644 --- a/homeassistant/components/light/vera.py +++ b/homeassistant/components/light/vera.py @@ -50,8 +50,7 @@ class VeraLight(VeraDevice, Light): """Flag supported features.""" if self._color: return SUPPORT_BRIGHTNESS | SUPPORT_RGB_COLOR - else: - return SUPPORT_BRIGHTNESS + return SUPPORT_BRIGHTNESS def turn_on(self, **kwargs): """Turn the light on.""" diff --git a/homeassistant/components/light/wink.py b/homeassistant/components/light/wink.py index b936e9addd6..93b23a9d7ba 100644 --- a/homeassistant/components/light/wink.py +++ b/homeassistant/components/light/wink.py @@ -33,10 +33,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class WinkLight(WinkDevice, Light): """Representation of a Wink light.""" - 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.""" @@ -52,8 +48,7 @@ class WinkLight(WinkDevice, Light): """Return the brightness of the light.""" if self.wink.brightness() is not None: return int(self.wink.brightness() * 255) - else: - return None + return None @property def rgb_color(self): diff --git a/homeassistant/components/light/zwave.py b/homeassistant/components/light/zwave.py index 752928f71a4..64c6530dd2b 100644 --- a/homeassistant/components/light/zwave.py +++ b/homeassistant/components/light/zwave.py @@ -55,16 +55,14 @@ def get_device(node, values, node_config, **kwargs): if node.has_command_class(zwave.const.COMMAND_CLASS_SWITCH_COLOR): return ZwaveColorLight(values, refresh, delay) - else: - return ZwaveDimmer(values, refresh, delay) + return ZwaveDimmer(values, refresh, delay) def brightness_state(value): """Return the brightness and state.""" if value.data > 0: return round((value.data / 99) * 255, 0), STATE_ON - else: - return 0, STATE_OFF + return 0, STATE_OFF def ct_to_rgb(temp): diff --git a/homeassistant/components/lock/lockitron.py b/homeassistant/components/lock/lockitron.py index eb301eeb013..ea79848f60c 100644 --- a/homeassistant/components/lock/lockitron.py +++ b/homeassistant/components/lock/lockitron.py @@ -86,7 +86,7 @@ class Lockitron(LockDevice): self.device_id, self.access_token, requested_state), timeout=5) if response.status_code == 200: return response.json()['state'] - else: - _LOGGER.error("Error setting lock state: %s\n%s", - requested_state, response.text) - return self._state + + _LOGGER.error("Error setting lock state: %s\n%s", + requested_state, response.text) + return self._state diff --git a/homeassistant/components/lock/wink.py b/homeassistant/components/lock/wink.py index 6fbf9edf954..020fc00ab9a 100644 --- a/homeassistant/components/lock/wink.py +++ b/homeassistant/components/lock/wink.py @@ -119,10 +119,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): class WinkLockDevice(WinkDevice, LockDevice): """Representation of a Wink lock.""" - def __init__(self, wink, hass): - """Initialize the lock.""" - super().__init__(wink, hass) - @asyncio.coroutine def async_added_to_hass(self): """Callback when entity is added to hass.""" diff --git a/homeassistant/components/media_player/anthemav.py b/homeassistant/components/media_player/anthemav.py index 64b8e826cfb..293c6e51d52 100644 --- a/homeassistant/components/media_player/anthemav.py +++ b/homeassistant/components/media_player/anthemav.py @@ -102,8 +102,7 @@ class AnthemAVR(MediaPlayerDevice): return STATE_ON elif pwrstate is False: return STATE_OFF - else: - return STATE_UNKNOWN + return STATE_UNKNOWN @property def is_volume_muted(self): diff --git a/homeassistant/components/media_player/apple_tv.py b/homeassistant/components/media_player/apple_tv.py index a7017f73fc4..3ecb1c0922e 100644 --- a/homeassistant/components/media_player/apple_tv.py +++ b/homeassistant/components/media_player/apple_tv.py @@ -106,8 +106,7 @@ class AppleTvDevice(MediaPlayerDevice): state == const.PLAY_STATE_FAST_BACKWARD: # Catch fast forward/backward here so "play" is default action return STATE_PAUSED - else: - return STATE_STANDBY # Bad or unknown state? + return STATE_STANDBY # Bad or unknown state? @callback def playstatus_update(self, updater, playing): diff --git a/homeassistant/components/media_player/braviatv.py b/homeassistant/components/media_player/braviatv.py index 1c8419ba144..93071b9840f 100644 --- a/homeassistant/components/media_player/braviatv.py +++ b/homeassistant/components/media_player/braviatv.py @@ -59,8 +59,7 @@ def _get_mac_address(ip_address): pid_component) if match is not None: return match.groups()[0] - else: - return None + return None def _config_from_file(filename, config=None): @@ -307,8 +306,7 @@ class BraviaTVDevice(MediaPlayerDevice): """Volume level of the media player (0..1).""" if self._volume is not None: return self._volume / 100 - else: - return None + return None @property def is_volume_muted(self): diff --git a/homeassistant/components/media_player/cmus.py b/homeassistant/components/media_player/cmus.py index aefe5bced18..949965200aa 100644 --- a/homeassistant/components/media_player/cmus.py +++ b/homeassistant/components/media_player/cmus.py @@ -94,8 +94,7 @@ class CmusDevice(MediaPlayerDevice): return STATE_PLAYING elif self.status.get('status') == 'paused': return STATE_PAUSED - else: - return STATE_OFF + return STATE_OFF @property def media_content_id(self): diff --git a/homeassistant/components/media_player/denon.py b/homeassistant/components/media_player/denon.py index 08e08dd1650..68fb629e5ea 100755 --- a/homeassistant/components/media_player/denon.py +++ b/homeassistant/components/media_player/denon.py @@ -55,9 +55,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): if denon.update(): add_devices([denon]) - return True - else: - return False class DenonDevice(MediaPlayerDevice): @@ -197,8 +194,7 @@ class DenonDevice(MediaPlayerDevice): """Flag media player features that are supported.""" if self._mediasource in MEDIA_MODES.values(): return SUPPORT_DENON | SUPPORT_MEDIA_MODES - else: - return SUPPORT_DENON + return SUPPORT_DENON @property def source(self): diff --git a/homeassistant/components/media_player/directv.py b/homeassistant/components/media_player/directv.py index 75a828696d9..b46e256bab3 100644 --- a/homeassistant/components/media_player/directv.py +++ b/homeassistant/components/media_player/directv.py @@ -144,10 +144,9 @@ class DirecTvDevice(MediaPlayerDevice): """Return the channel current playing media.""" if self._is_standby: return None - else: - chan = "{} ({})".format( - self._current['callsign'], self._current['major']) - return chan + + return "{} ({})".format( + self._current['callsign'], self._current['major']) def turn_on(self): """Turn on the receiver.""" diff --git a/homeassistant/components/media_player/emby.py b/homeassistant/components/media_player/emby.py index af7bbeed201..8df6bc4fd1b 100644 --- a/homeassistant/components/media_player/emby.py +++ b/homeassistant/components/media_player/emby.py @@ -306,8 +306,7 @@ class EmbyDevice(MediaPlayerDevice): """Flag media player features that are supported.""" if self.supports_remote_control: return SUPPORT_EMBY - else: - return None + return None def async_media_play(self): """Play media. diff --git a/homeassistant/components/media_player/itunes.py b/homeassistant/components/media_player/itunes.py index 514bf24a21a..575ea414fa3 100644 --- a/homeassistant/components/media_player/itunes.py +++ b/homeassistant/components/media_player/itunes.py @@ -60,8 +60,8 @@ class Itunes(object): if self.port: return '{}{}:{}'.format(uri_scheme, self.host, self.port) - else: - return '{}{}'.format(uri_scheme, self.host) + + return '{}{}'.format(uri_scheme, self.host) def _request(self, method, path, params=None): """Make the actual request and return the parsed response.""" @@ -225,8 +225,8 @@ class ItunesDevice(MediaPlayerDevice): if self.player_state == 'paused': return STATE_PAUSED - else: - return STATE_PLAYING + + return STATE_PLAYING def update(self): """Retrieve latest state.""" @@ -281,9 +281,9 @@ class ItunesDevice(MediaPlayerDevice): if self.player_state in (STATE_PLAYING, STATE_IDLE, STATE_PAUSED) and \ self.current_title is not None: return self.client.artwork_url() - else: - return 'https://cloud.githubusercontent.com/assets/260/9829355' \ - '/33fab972-58cf-11e5-8ea2-2ca74bdaae40.png' + + return 'https://cloud.githubusercontent.com/assets/260/9829355' \ + '/33fab972-58cf-11e5-8ea2-2ca74bdaae40.png' @property def media_title(self): @@ -400,16 +400,16 @@ class AirPlayDevice(MediaPlayerDevice): """Return the icon to use in the frontend, if any.""" if self.selected is True: return 'mdi:volume-high' - else: - return 'mdi:volume-off' + + return 'mdi:volume-off' @property def state(self): """Return the state of the device.""" if self.selected is True: return STATE_ON - else: - return STATE_OFF + + return STATE_OFF def update(self): """Retrieve latest state.""" diff --git a/homeassistant/components/media_player/kodi.py b/homeassistant/components/media_player/kodi.py index 18860acb9a6..f484c04a058 100644 --- a/homeassistant/components/media_player/kodi.py +++ b/homeassistant/components/media_player/kodi.py @@ -334,8 +334,8 @@ class KodiDevice(MediaPlayerDevice): if self._properties['speed'] == 0 and not self._properties['live']: return STATE_PAUSED - else: - return STATE_PLAYING + + return STATE_PLAYING @asyncio.coroutine def async_ws_connect(self): @@ -407,8 +407,8 @@ class KodiDevice(MediaPlayerDevice): """Active server for json-rpc requests.""" if self._enable_websocket and self._ws_server.connected: return self._ws_server - else: - return self._http_server + + return self._http_server @property def name(self): @@ -503,8 +503,8 @@ class KodiDevice(MediaPlayerDevice): artists = self._item.get('artist', []) if artists: return artists[0] - else: - return None + + return None @property def media_album_artist(self): @@ -512,8 +512,8 @@ class KodiDevice(MediaPlayerDevice): artists = self._item.get('albumartist', []) if artists: return artists[0] - else: - return None + + return None @property def supported_features(self): @@ -678,9 +678,9 @@ class KodiDevice(MediaPlayerDevice): elif media_type == "PLAYLIST": return self.server.Player.Open( {"item": {"playlistid": int(media_id)}}) - else: - return self.server.Player.Open( - {"item": {"file": str(media_id)}}) + + return self.server.Player.Open( + {"item": {"file": str(media_id)}}) @asyncio.coroutine def async_set_shuffle(self, shuffle): @@ -794,9 +794,9 @@ class KodiDevice(MediaPlayerDevice): """Get albums list.""" if artist_id is None: return (yield from self.server.AudioLibrary.GetAlbums()) - else: - return (yield from self.server.AudioLibrary.GetAlbums( - {"filter": {"artistid": int(artist_id)}})) + + return (yield from self.server.AudioLibrary.GetAlbums( + {"filter": {"artistid": int(artist_id)}})) @asyncio.coroutine def async_find_artist(self, artist_name): @@ -815,9 +815,9 @@ class KodiDevice(MediaPlayerDevice): """Get songs list.""" if artist_id is None: return (yield from self.server.AudioLibrary.GetSongs()) - else: - return (yield from self.server.AudioLibrary.GetSongs( - {"filter": {"artistid": int(artist_id)}})) + + return (yield from self.server.AudioLibrary.GetSongs( + {"filter": {"artistid": int(artist_id)}})) @asyncio.coroutine def async_find_song(self, song_name, artist_name=''): diff --git a/homeassistant/components/media_player/liveboxplaytv.py b/homeassistant/components/media_player/liveboxplaytv.py index eef5a890e8e..43678d90829 100644 --- a/homeassistant/components/media_player/liveboxplaytv.py +++ b/homeassistant/components/media_player/liveboxplaytv.py @@ -159,9 +159,8 @@ class LiveboxPlayTvDevice(MediaPlayerDevice): return STATE_PLAYING elif state == 'PAUSE': return STATE_PAUSED - else: - return STATE_ON if self._client.is_on else STATE_OFF - return STATE_UNKNOWN + + return STATE_ON if self._client.is_on else STATE_OFF def turn_off(self): """Turn off media player.""" diff --git a/homeassistant/components/media_player/mpchc.py b/homeassistant/components/media_player/mpchc.py index 964c2b5d009..3f7ab5a6e5e 100644 --- a/homeassistant/components/media_player/mpchc.py +++ b/homeassistant/components/media_player/mpchc.py @@ -97,8 +97,8 @@ class MpcHcDevice(MediaPlayerDevice): return STATE_PLAYING elif state == 'paused': return STATE_PAUSED - else: - return STATE_IDLE + + return STATE_IDLE @property def media_title(self): diff --git a/homeassistant/components/media_player/mpd.py b/homeassistant/components/media_player/mpd.py index f4dad2d001b..d8dafc2be10 100644 --- a/homeassistant/components/media_player/mpd.py +++ b/homeassistant/components/media_player/mpd.py @@ -133,8 +133,8 @@ class MpdDevice(MediaPlayerDevice): return STATE_PLAYING elif self.status['state'] == 'pause': return STATE_PAUSED - else: - return STATE_OFF + + return STATE_OFF @property def media_content_id(self): @@ -164,8 +164,8 @@ class MpdDevice(MediaPlayerDevice): return title elif title is None: return name - else: - return '{}: {}'.format(name, title) + + return '{}: {}'.format(name, title) @property def media_artist(self): diff --git a/homeassistant/components/media_player/pandora.py b/homeassistant/components/media_player/pandora.py index 4e36fdab5a2..d66811eed66 100644 --- a/homeassistant/components/media_player/pandora.py +++ b/homeassistant/components/media_player/pandora.py @@ -358,9 +358,9 @@ def _pianobar_exists(): pianobar_exe = shutil.which('pianobar') if pianobar_exe: return True - else: - _LOGGER.warning( - "The Pandora component depends on the Pianobar client, which " - "cannot be found. Please install using instructions at " - "https://home-assistant.io/components/media_player.pandora/") - return False + + _LOGGER.warning( + "The Pandora component depends on the Pianobar client, which " + "cannot be found. Please install using instructions at " + "https://home-assistant.io/components/media_player.pandora/") + return False diff --git a/homeassistant/components/media_player/pioneer.py b/homeassistant/components/media_player/pioneer.py index eb346502d95..ba08003b9bf 100644 --- a/homeassistant/components/media_player/pioneer.py +++ b/homeassistant/components/media_player/pioneer.py @@ -47,9 +47,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): if pioneer.update(): add_devices([pioneer]) - return True - else: - return False class PioneerDevice(MediaPlayerDevice): diff --git a/homeassistant/components/media_player/plex.py b/homeassistant/components/media_player/plex.py index d54b8f2ca77..2bfa97e7e79 100644 --- a/homeassistant/components/media_player/plex.py +++ b/homeassistant/components/media_player/plex.py @@ -531,16 +531,16 @@ class PlexClient(MediaPlayerDevice): # type so that lower layers don't think it's a URL and choke on it if value is self.na_type: return None - else: - return value + + return value @property def _active_media_plexapi_type(self): """Get the active media type required by PlexAPI commands.""" if self.media_content_type is MEDIA_TYPE_MUSIC: return 'music' - else: - return 'video' + + return 'video' @property def media_content_id(self): @@ -560,8 +560,8 @@ class PlexClient(MediaPlayerDevice): return MEDIA_TYPE_VIDEO elif self._session_type == 'track': return MEDIA_TYPE_MUSIC - else: - return None + + return None @property def media_artist(self): @@ -657,8 +657,8 @@ class PlexClient(MediaPlayerDevice): SUPPORT_NEXT_TRACK | SUPPORT_STOP | SUPPORT_VOLUME_SET | SUPPORT_PLAY | SUPPORT_TURN_OFF | SUPPORT_VOLUME_MUTE) - else: - return None + + return None def _local_client_control_fix(self): """Detect if local client and adjust url to allow control.""" diff --git a/homeassistant/components/media_player/sonos.py b/homeassistant/components/media_player/sonos.py index b26f0f48a77..33decf35f89 100644 --- a/homeassistant/components/media_player/sonos.py +++ b/homeassistant/components/media_player/sonos.py @@ -220,9 +220,9 @@ def _parse_timespan(timespan): """Parse a time-span into number of seconds.""" if timespan in ('', 'NOT_IMPLEMENTED', None): return None - else: - return sum(60 ** x[0] * int(x[1]) for x in enumerate( - reversed(timespan.split(':')))) + + return sum(60 ** x[0] * int(x[1]) for x in enumerate( + reversed(timespan.split(':')))) class _ProcessSonosEventQueue(): @@ -765,8 +765,8 @@ class SonosDevice(MediaPlayerDevice): """Content ID of current playing media.""" if self._coordinator: return self._coordinator.media_content_id - else: - return self._media_content_id + + return self._media_content_id @property def media_content_type(self): @@ -778,16 +778,16 @@ class SonosDevice(MediaPlayerDevice): """Duration of current playing media in seconds.""" if self._coordinator: return self._coordinator.media_duration - else: - return self._media_duration + + return self._media_duration @property def media_position(self): """Position of current playing media in seconds.""" if self._coordinator: return self._coordinator.media_position - else: - return self._media_position + + return self._media_position @property def media_position_updated_at(self): @@ -797,40 +797,40 @@ class SonosDevice(MediaPlayerDevice): """ if self._coordinator: return self._coordinator.media_position_updated_at - else: - return self._media_position_updated_at + + return self._media_position_updated_at @property def media_image_url(self): """Image url of current playing media.""" if self._coordinator: return self._coordinator.media_image_url - else: - return self._media_image_url + + return self._media_image_url @property def media_artist(self): """Artist of current playing media, music track only.""" if self._coordinator: return self._coordinator.media_artist - else: - return self._media_artist + + return self._media_artist @property def media_album_name(self): """Album name of current playing media, music track only.""" if self._coordinator: return self._coordinator.media_album_name - else: - return self._media_album_name + + return self._media_album_name @property def media_title(self): """Title of current playing media.""" if self._coordinator: return self._coordinator.media_title - else: - return self._media_title + + return self._media_title @property def supported_features(self): @@ -919,8 +919,8 @@ class SonosDevice(MediaPlayerDevice): """Name of the current input source.""" if self._coordinator: return self._coordinator.source - else: - return self._source_name + + return self._source_name @soco_error def turn_off(self): diff --git a/homeassistant/components/media_player/soundtouch.py b/homeassistant/components/media_player/soundtouch.py index 3890e52bd73..236208eb332 100644 --- a/homeassistant/components/media_player/soundtouch.py +++ b/homeassistant/components/media_player/soundtouch.py @@ -200,8 +200,8 @@ class SoundTouchDevice(MediaPlayerDevice): """Return the state of the device.""" if self._status.source == 'STANDBY': return STATE_OFF - else: - return MAP_STATUS.get(self._status.play_status, STATE_UNAVAILABLE) + + return MAP_STATUS.get(self._status.play_status, STATE_UNAVAILABLE) @property def is_volume_muted(self): @@ -280,8 +280,8 @@ class SoundTouchDevice(MediaPlayerDevice): return self._status.station_name elif self._status.artist is not None: return self._status.artist + " - " + self._status.track - else: - return None + + return None @property def media_duration(self): diff --git a/homeassistant/components/media_player/universal.py b/homeassistant/components/media_player/universal.py index 68c2a06cf23..daf874a31dd 100644 --- a/homeassistant/components/media_player/universal.py +++ b/homeassistant/components/media_player/universal.py @@ -215,8 +215,8 @@ class UniversalMediaPlayer(MediaPlayerDevice): master_state = self._entity_lkp( self._attrs[CONF_STATE][0], self._attrs[CONF_STATE][1]) return master_state if master_state else STATE_OFF - else: - return None + + return None @property def name(self): diff --git a/homeassistant/components/media_player/volumio.py b/homeassistant/components/media_player/volumio.py index ade49b8116e..eda0bc2b326 100755 --- a/homeassistant/components/media_player/volumio.py +++ b/homeassistant/components/media_player/volumio.py @@ -113,8 +113,8 @@ class Volumio(MediaPlayerDevice): return STATE_PAUSED elif status == 'play': return STATE_PLAYING - else: - return STATE_IDLE + + return STATE_IDLE @property def media_title(self): @@ -207,6 +207,6 @@ class Volumio(MediaPlayerDevice): self._lastvol = self._state['volume'] return self.send_volumio_msg( 'commands', params={'cmd': 'volume', 'volume': mutecmd}) - else: - return self.send_volumio_msg( - 'commands', params={'cmd': 'volume', 'volume': self._lastvol}) + + return self.send_volumio_msg( + 'commands', params={'cmd': 'volume', 'volume': self._lastvol}) diff --git a/homeassistant/components/media_player/yamaha.py b/homeassistant/components/media_player/yamaha.py index de19ab238b5..4d10c722800 100644 --- a/homeassistant/components/media_player/yamaha.py +++ b/homeassistant/components/media_player/yamaha.py @@ -289,5 +289,5 @@ class YamahaDevice(MediaPlayerDevice): # just the one we have. if song and station: return '{}: {}'.format(station, song) - else: - return song or station + + return song or station diff --git a/homeassistant/components/notify/mailgun.py b/homeassistant/components/notify/mailgun.py index 59c6a50ffc9..1aa403f0ba8 100644 --- a/homeassistant/components/notify/mailgun.py +++ b/homeassistant/components/notify/mailgun.py @@ -42,8 +42,8 @@ def get_service(hass, config, discovery_info=None): config.get(CONF_RECIPIENT)) if mailgun_service.connection_is_valid(): return mailgun_service - else: - return None + + return None class MailgunNotificationService(BaseNotificationService): diff --git a/homeassistant/components/notify/smtp.py b/homeassistant/components/notify/smtp.py index aaf1a729f2d..fc38647a065 100644 --- a/homeassistant/components/notify/smtp.py +++ b/homeassistant/components/notify/smtp.py @@ -74,8 +74,8 @@ def get_service(hass, config, discovery_info=None): if mail_service.connection_is_valid(): return mail_service - else: - return None + + return None class MailNotificationService(BaseNotificationService): diff --git a/homeassistant/components/recorder/models.py b/homeassistant/components/recorder/models.py index 65c7dc6abb6..a87eabc44e6 100644 --- a/homeassistant/components/recorder/models.py +++ b/homeassistant/components/recorder/models.py @@ -173,5 +173,5 @@ def _process_timestamp(ts): return None elif ts.tzinfo is None: return dt_util.UTC.localize(ts) - else: - return dt_util.as_utc(ts) + + return dt_util.as_utc(ts) diff --git a/homeassistant/components/scene/lifx_cloud.py b/homeassistant/components/scene/lifx_cloud.py index b96a56ca2bd..e6f5be71a80 100644 --- a/homeassistant/components/scene/lifx_cloud.py +++ b/homeassistant/components/scene/lifx_cloud.py @@ -62,9 +62,9 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None): elif status == 401: _LOGGER.error("Unauthorized (bad token?) on %s", url) return False - else: - _LOGGER.error("HTTP error %d on %s", scenes_resp.status, url) - return False + + _LOGGER.error("HTTP error %d on %s", scenes_resp.status, url) + return False class LifxCloudScene(Scene): diff --git a/homeassistant/components/sensor/arwn.py b/homeassistant/components/sensor/arwn.py index a63451771d6..d49afb8b71a 100644 --- a/homeassistant/components/sensor/arwn.py +++ b/homeassistant/components/sensor/arwn.py @@ -146,7 +146,4 @@ class ArwnSensor(Entity): @property def icon(self): """Return the icon of device based on its type.""" - if self._icon: - return self._icon - else: - return super().icon + return self._icon diff --git a/homeassistant/components/sensor/bom.py b/homeassistant/components/sensor/bom.py index 4033211e461..545bef12d83 100644 --- a/homeassistant/components/sensor/bom.py +++ b/homeassistant/components/sensor/bom.py @@ -139,17 +139,17 @@ class BOMCurrentSensor(Entity): """Return the name of the sensor.""" if self.stationname is None: return 'BOM {}'.format(SENSOR_TYPES[self._condition][0]) - else: - return 'BOM {} {}'.format( - self.stationname, SENSOR_TYPES[self._condition][0]) + + return 'BOM {} {}'.format( + self.stationname, SENSOR_TYPES[self._condition][0]) @property def state(self): """Return the state of the sensor.""" if self.rest.data and self._condition in self.rest.data: return self.rest.data[self._condition] - else: - return STATE_UNKNOWN + + return STATE_UNKNOWN @property def device_state_attributes(self): diff --git a/homeassistant/components/sensor/buienradar.py b/homeassistant/components/sensor/buienradar.py index 2d1e716fd1b..e65353daadb 100755 --- a/homeassistant/components/sensor/buienradar.py +++ b/homeassistant/components/sensor/buienradar.py @@ -167,8 +167,8 @@ class BrSensor(Entity): if self.type != SYMBOL: return None - else: - return self._entity_picture + + return self._entity_picture @property def device_state_attributes(self): diff --git a/homeassistant/components/sensor/darksky.py b/homeassistant/components/sensor/darksky.py index eaf0c474994..a10a276bf0f 100644 --- a/homeassistant/components/sensor/darksky.py +++ b/homeassistant/components/sensor/darksky.py @@ -187,9 +187,9 @@ class DarkSkySensor(Entity): """Return the name of the sensor.""" if self.forecast_day == 0: return '{} {}'.format(self.client_name, self._name) - else: - return '{} {} {}'.format( - self.client_name, self._name, self.forecast_day) + + return '{} {} {}'.format( + self.client_name, self._name, self.forecast_day) @property def state(self): @@ -214,8 +214,8 @@ class DarkSkySensor(Entity): if self._icon in CONDITION_PICTURES: return CONDITION_PICTURES[self._icon] - else: - return None + + return None def update_unit_of_measurement(self): """Update units based on unit system.""" diff --git a/homeassistant/components/sensor/dsmr.py b/homeassistant/components/sensor/dsmr.py index 23324fe7360..76fde35410d 100644 --- a/homeassistant/components/sensor/dsmr.py +++ b/homeassistant/components/sensor/dsmr.py @@ -207,11 +207,11 @@ class DSMREntity(Entity): if self._obis == obis.ELECTRICITY_ACTIVE_TARIFF: return self.translate_tariff(value) - else: - if value is not None: - return value - else: - return STATE_UNKNOWN + + if value is not None: + return value + + return STATE_UNKNOWN @property def unit_of_measurement(self): @@ -227,8 +227,8 @@ class DSMREntity(Entity): return 'normal' elif value == '0001': return 'low' - else: - return STATE_UNKNOWN + + return STATE_UNKNOWN class DerivativeDSMREntity(DSMREntity): diff --git a/homeassistant/components/sensor/dyson.py b/homeassistant/components/sensor/dyson.py index 2f324519566..e68909a1d6c 100644 --- a/homeassistant/components/sensor/dyson.py +++ b/homeassistant/components/sensor/dyson.py @@ -59,8 +59,7 @@ class DysonFilterLifeSensor(Entity): """Return filter life in hours..""" if self._device.state: return self._device.state.filter_life - else: - return STATE_UNKNOWN + return STATE_UNKNOWN @property def name(self): diff --git a/homeassistant/components/sensor/eddystone_temperature.py b/homeassistant/components/sensor/eddystone_temperature.py index 7fd5f14e1af..fe05da3ccdd 100644 --- a/homeassistant/components/sensor/eddystone_temperature.py +++ b/homeassistant/components/sensor/eddystone_temperature.py @@ -86,8 +86,7 @@ def get_from_conf(config, config_key, length): _LOGGER.error("Error in config parameter %s: Must be exactly %d " "bytes. Device will not be added", config_key, length/2) return None - else: - return string + return string class EddystoneTemp(Entity): diff --git a/homeassistant/components/sensor/eight_sleep.py b/homeassistant/components/sensor/eight_sleep.py index e3b2f92d4e1..f7d42a9f5bd 100644 --- a/homeassistant/components/sensor/eight_sleep.py +++ b/homeassistant/components/sensor/eight_sleep.py @@ -155,8 +155,8 @@ class EightUserSensor(EightSleepUserEntity): elif 'bed_temp' in self._sensor: if self._units == 'si': return '°C' - else: - return '°F' + return '°F' + return None @property def icon(self): @@ -264,8 +264,7 @@ class EightRoomSensor(EightSleepUserEntity): """Return the unit the value is expressed in.""" if self._units == 'si': return '°C' - else: - return '°F' + return '°F' @property def icon(self): diff --git a/homeassistant/components/sensor/fritzbox_callmonitor.py b/homeassistant/components/sensor/fritzbox_callmonitor.py index ea2fcd026b3..a780d999b7e 100644 --- a/homeassistant/components/sensor/fritzbox_callmonitor.py +++ b/homeassistant/components/sensor/fritzbox_callmonitor.py @@ -91,10 +91,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): _stop_listener ) - if monitor.sock is None: - return False - else: - return True + return monitor.sock is not None class FritzBoxCallSensor(Entity): @@ -118,10 +115,7 @@ class FritzBoxCallSensor(Entity): @property def should_poll(self): """Only poll to update phonebook, if defined.""" - if self.phonebook is None: - return False - else: - return True + return self.phonebook is not None @property def state(self): @@ -142,8 +136,7 @@ class FritzBoxCallSensor(Entity): """Return a name for a given phone number.""" if self.phonebook is None: return 'unknown' - else: - return self.phonebook.get_name(number) + return self.phonebook.get_name(number) def update(self): """Update the phonebook if it is defined.""" diff --git a/homeassistant/components/sensor/glances.py b/homeassistant/components/sensor/glances.py index 09738454bcb..58ac363b98e 100644 --- a/homeassistant/components/sensor/glances.py +++ b/homeassistant/components/sensor/glances.py @@ -89,8 +89,7 @@ class GlancesSensor(Entity): """Return the name of the sensor.""" if self._name is None: return SENSOR_TYPES[self.type][0] - else: - return '{} {}'.format(self._name, SENSOR_TYPES[self.type][0]) + return '{} {}'.format(self._name, SENSOR_TYPES[self.type][0]) @property def unit_of_measurement(self): diff --git a/homeassistant/components/sensor/gpsd.py b/homeassistant/components/sensor/gpsd.py index 9027802c295..472dd1d70f6 100644 --- a/homeassistant/components/sensor/gpsd.py +++ b/homeassistant/components/sensor/gpsd.py @@ -94,8 +94,7 @@ class GpsdSensor(Entity): return "3D Fix" elif self.agps_thread.data_stream.mode == 2: return "2D Fix" - else: - return STATE_UNKNOWN + return STATE_UNKNOWN @property def device_state_attributes(self): diff --git a/homeassistant/components/sensor/hddtemp.py b/homeassistant/components/sensor/hddtemp.py index 87647f4d16c..cd84bd8f9a8 100644 --- a/homeassistant/components/sensor/hddtemp.py +++ b/homeassistant/components/sensor/hddtemp.py @@ -77,8 +77,7 @@ class HddTempSensor(Entity): """Return the unit the value is expressed in.""" if self._details[4] == 'C': return TEMP_CELSIUS - else: - return TEMP_FAHRENHEIT + return TEMP_FAHRENHEIT @property def device_state_attributes(self): diff --git a/homeassistant/components/sensor/history_stats.py b/homeassistant/components/sensor/history_stats.py index fa000a75875..175bdafd4a9 100644 --- a/homeassistant/components/sensor/history_stats.py +++ b/homeassistant/components/sensor/history_stats.py @@ -296,8 +296,7 @@ class HistoryStatsHelper: return '%dd %dh %dm' % (days, hours, minutes) elif hours > 0: return '%dh %dm' % (hours, minutes) - else: - return '%dm' % minutes + return '%dm' % minutes @staticmethod def pretty_ratio(value, period): diff --git a/homeassistant/components/sensor/ios.py b/homeassistant/components/sensor/ios.py index c3bcbf60828..7bfe2dbd62a 100644 --- a/homeassistant/components/sensor/ios.py +++ b/homeassistant/components/sensor/ios.py @@ -121,8 +121,7 @@ class IOSSensor(Entity): if self.type == "state": return returning_icon_state - else: - return returning_icon_level + return returning_icon_level def update(self): """Get the latest state of the sensor.""" diff --git a/homeassistant/components/sensor/isy994.py b/homeassistant/components/sensor/isy994.py index 2f6d7346283..57995a831f3 100644 --- a/homeassistant/components/sensor/isy994.py +++ b/homeassistant/components/sensor/isy994.py @@ -310,8 +310,7 @@ class ISYSensorDevice(isy.ISYDevice): raw_units = self.raw_unit_of_measurement if raw_units in (TEMP_FAHRENHEIT, TEMP_CELSIUS): return self.hass.config.units.temperature_unit - else: - return raw_units + return raw_units class ISYWeatherDevice(isy.ISYDevice): diff --git a/homeassistant/components/sensor/kwb.py b/homeassistant/components/sensor/kwb.py index 0641917145b..f307b0f6102 100644 --- a/homeassistant/components/sensor/kwb.py +++ b/homeassistant/components/sensor/kwb.py @@ -105,8 +105,7 @@ class KWBSensor(Entity): """Return the state of value.""" if self._sensor.value is not None and self._sensor.available: return self._sensor.value - else: - return STATE_UNKNOWN + return STATE_UNKNOWN @property def unit_of_measurement(self): diff --git a/homeassistant/components/sensor/metoffice.py b/homeassistant/components/sensor/metoffice.py index 961b4692e93..a20ec8fdd5a 100644 --- a/homeassistant/components/sensor/metoffice.py +++ b/homeassistant/components/sensor/metoffice.py @@ -124,10 +124,8 @@ class MetOfficeCurrentSensor(Entity): if self._condition == "weather": return [k for k, v in CONDITION_CLASSES.items() if self.data.data.weather.value in v][0] - else: - return variable.value - else: - return STATE_UNKNOWN + return variable.value + return STATE_UNKNOWN @property def unit_of_measurement(self): diff --git a/homeassistant/components/sensor/moon.py b/homeassistant/components/sensor/moon.py index 9d844292e18..75b8a1f72bd 100644 --- a/homeassistant/components/sensor/moon.py +++ b/homeassistant/components/sensor/moon.py @@ -64,8 +64,7 @@ class MoonSensor(Entity): return 'Waning gibbous' elif self._state == 21: return 'Last quarter' - else: - return 'Waning crescent' + return 'Waning crescent' @property def icon(self): diff --git a/homeassistant/components/sensor/mvglive.py b/homeassistant/components/sensor/mvglive.py index d1f101fc02f..46d79c1121b 100644 --- a/homeassistant/components/sensor/mvglive.py +++ b/homeassistant/components/sensor/mvglive.py @@ -91,8 +91,7 @@ class MVGLiveSensor(Entity): """Return the name of the sensor.""" if self._name: return self._name - else: - return self._station + return self._station @property def state(self): diff --git a/homeassistant/components/sensor/neato.py b/homeassistant/components/sensor/neato.py index 39d77e736c5..eb1524e1748 100644 --- a/homeassistant/components/sensor/neato.py +++ b/homeassistant/components/sensor/neato.py @@ -136,10 +136,7 @@ class NeatoConnectedSensor(Entity): @property def available(self): """Return True if sensor data is available.""" - if not self._state: - return False - else: - return True + return self._state @property def state(self): diff --git a/homeassistant/components/sensor/netdata.py b/homeassistant/components/sensor/netdata.py index ad7426eb1d3..6cb6ef9a14d 100644 --- a/homeassistant/components/sensor/netdata.py +++ b/homeassistant/components/sensor/netdata.py @@ -14,7 +14,7 @@ import voluptuous as vol import homeassistant.helpers.config_validation as cv from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.const import ( - CONF_HOST, CONF_PORT, STATE_UNKNOWN, CONF_NAME, CONF_RESOURCES) + CONF_HOST, CONF_PORT, CONF_NAME, CONF_RESOURCES) from homeassistant.helpers.entity import Entity _LOGGER = logging.getLogger(__name__) @@ -110,8 +110,7 @@ class NetdataSensor(Entity): netdata_id = SENSOR_TYPES[self.type][3] if netdata_id in value: return "{0:.{1}f}".format(value[netdata_id], self._precision) - else: - return STATE_UNKNOWN + return None @property def available(self): diff --git a/homeassistant/components/sensor/ohmconnect.py b/homeassistant/components/sensor/ohmconnect.py index 9808e6ecef7..cb1a1d3d260 100644 --- a/homeassistant/components/sensor/ohmconnect.py +++ b/homeassistant/components/sensor/ohmconnect.py @@ -60,8 +60,7 @@ class OhmconnectSensor(Entity): """Return the state of the sensor.""" if self._data.get("active") == "True": return "Active" - else: - return "Inactive" + return "Inactive" @property def device_state_attributes(self): diff --git a/homeassistant/components/sensor/pvoutput.py b/homeassistant/components/sensor/pvoutput.py index cb3d2d1427a..baad452b629 100644 --- a/homeassistant/components/sensor/pvoutput.py +++ b/homeassistant/components/sensor/pvoutput.py @@ -15,8 +15,7 @@ from homeassistant.helpers.entity import Entity from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor.rest import RestData from homeassistant.const import ( - ATTR_TEMPERATURE, CONF_API_KEY, CONF_NAME, STATE_UNKNOWN, ATTR_DATE, - ATTR_TIME) + ATTR_TEMPERATURE, CONF_API_KEY, CONF_NAME, ATTR_DATE, ATTR_TIME) _LOGGER = logging.getLogger(__name__) _ENDPOINT = 'http://pvoutput.org/service/r2/getstatus.jsp' @@ -90,8 +89,7 @@ class PvoutputSensor(Entity): """Return the state of the device.""" if self.pvcoutput is not None: return self.pvcoutput.energy_generation - else: - return STATE_UNKNOWN + return None @property def device_state_attributes(self): diff --git a/homeassistant/components/sensor/qnap.py b/homeassistant/components/sensor/qnap.py index c72d2d65c6d..42f68a1967a 100644 --- a/homeassistant/components/sensor/qnap.py +++ b/homeassistant/components/sensor/qnap.py @@ -232,8 +232,7 @@ class QNAPSensor(Entity): if self.monitor_device is not None: return "{} {} ({})".format( server_name, self.var_name, self.monitor_device) - else: - return "{} {}".format(server_name, self.var_name) + return "{} {}".format(server_name, self.var_name) @property def icon(self): diff --git a/homeassistant/components/sensor/swiss_hydrological_data.py b/homeassistant/components/sensor/swiss_hydrological_data.py index 0df63956f2e..3e2f228423b 100644 --- a/homeassistant/components/sensor/swiss_hydrological_data.py +++ b/homeassistant/components/sensor/swiss_hydrological_data.py @@ -90,8 +90,7 @@ class SwissHydrologicalDataSensor(Entity): """Return the unit of measurement of this entity, if any.""" if self._state is not STATE_UNKNOWN: return self._unit_of_measurement - else: - return None + return None @property def state(self): diff --git a/homeassistant/components/sensor/synologydsm.py b/homeassistant/components/sensor/synologydsm.py index eb31381ccef..b52d01a0112 100644 --- a/homeassistant/components/sensor/synologydsm.py +++ b/homeassistant/components/sensor/synologydsm.py @@ -177,8 +177,7 @@ class SynoNasSensor(Entity): """Return the name of the sensor, if any.""" if self.monitor_device is not None: return "{} ({})".format(self.var_name, self.monitor_device) - else: - return self.var_name + return self.var_name @property def icon(self): @@ -191,8 +190,7 @@ class SynoNasSensor(Entity): if self.var_id in ['volume_disk_temp_avg', 'volume_disk_temp_max', 'disk_temp']: return self._api.temp_unit - else: - return self.var_units + return self.var_units def update(self): """Get the latest data for the states.""" @@ -238,8 +236,8 @@ class SynoNasStorageSensor(SynoNasSensor): if self._api.temp_unit == TEMP_CELSIUS: return attr - else: - return round(attr * 1.8 + 32.0, 1) - else: - return getattr(self._api.storage, - self.var_id)(self.monitor_device) + + return round(attr * 1.8 + 32.0, 1) + + return getattr(self._api.storage, + self.var_id)(self.monitor_device) diff --git a/homeassistant/components/sensor/tado.py b/homeassistant/components/sensor/tado.py index b654a4444c4..1d40e4ceb50 100644 --- a/homeassistant/components/sensor/tado.py +++ b/homeassistant/components/sensor/tado.py @@ -30,7 +30,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): zones = tado.get_zones() except RuntimeError: _LOGGER.error("Unable to get zone info from mytado") - return False + return sensor_items = [] for zone in zones: @@ -47,9 +47,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None): if sensor_items: add_devices(sensor_items, True) - return True - else: - return False def create_zone_sensor(tado, zone, name, zone_id, variable): diff --git a/homeassistant/components/sensor/tellduslive.py b/homeassistant/components/sensor/tellduslive.py index 68d0bb6535f..c14b20e1099 100644 --- a/homeassistant/components/sensor/tellduslive.py +++ b/homeassistant/components/sensor/tellduslive.py @@ -92,8 +92,7 @@ class TelldusLiveSensor(TelldusLiveEntity): return self._value_as_humidity elif self._type == SENSOR_TYPE_LUMINANCE: return self._value_as_luminance - else: - return self._value + return self._value @property def quantity_name(self): diff --git a/homeassistant/components/sensor/time_date.py b/homeassistant/components/sensor/time_date.py index c1c4d62dbcb..a59ee01bac2 100644 --- a/homeassistant/components/sensor/time_date.py +++ b/homeassistant/components/sensor/time_date.py @@ -83,8 +83,7 @@ class TimeDateSensor(Entity): return 'mdi:calendar-clock' elif 'date' in self.type: return 'mdi:calendar' - else: - return 'mdi:clock' + return 'mdi:clock' def get_next_interval(self, now=None): """Compute next time an update should occur.""" diff --git a/homeassistant/components/sensor/volvooncall.py b/homeassistant/components/sensor/volvooncall.py index 703315c478c..622261941d6 100644 --- a/homeassistant/components/sensor/volvooncall.py +++ b/homeassistant/components/sensor/volvooncall.py @@ -28,8 +28,7 @@ class VolvoSensor(VolvoEntity): val = getattr(self.vehicle, self._attribute) if self._attribute == 'odometer': return round(val / 1000) # km - else: - return val + return val @property def unit_of_measurement(self): diff --git a/homeassistant/components/sensor/waqi.py b/homeassistant/components/sensor/waqi.py index 01bdab24af9..f762caf58ae 100644 --- a/homeassistant/components/sensor/waqi.py +++ b/homeassistant/components/sensor/waqi.py @@ -11,7 +11,7 @@ import voluptuous as vol import homeassistant.helpers.config_validation as cv from homeassistant.const import ( - ATTR_ATTRIBUTION, ATTR_TIME, ATTR_TEMPERATURE, STATE_UNKNOWN, CONF_TOKEN) + ATTR_ATTRIBUTION, ATTR_TIME, ATTR_TEMPERATURE, CONF_TOKEN) from homeassistant.helpers.config_validation import PLATFORM_SCHEMA from homeassistant.helpers.entity import Entity @@ -101,8 +101,7 @@ class WaqiSensor(Entity): """Return the state of the device.""" if self._details is not None: return self._details.get('aqi') - else: - return STATE_UNKNOWN + return None @property def unit_of_measurement(self): diff --git a/homeassistant/components/sensor/wunderground.py b/homeassistant/components/sensor/wunderground.py index 84f6d2d2ac0..3a72432610c 100644 --- a/homeassistant/components/sensor/wunderground.py +++ b/homeassistant/components/sensor/wunderground.py @@ -254,8 +254,7 @@ class WUAlertsSensorConfig(WUSensorConfig): feature="alerts", value=lambda wu: len(wu.data['alerts']), icon=lambda wu: "mdi:alert-circle-outline" - if len(wu.data['alerts']) > 0 - else "mdi:check-circle-outline", + if wu.data['alerts'] else "mdi:check-circle-outline", device_state_attributes=self._get_attributes ) diff --git a/homeassistant/components/sensor/zwave.py b/homeassistant/components/sensor/zwave.py index e9ea0e7512d..fe295d84d49 100644 --- a/homeassistant/components/sensor/zwave.py +++ b/homeassistant/components/sensor/zwave.py @@ -78,8 +78,7 @@ class ZWaveMultilevelSensor(ZWaveSensor): return TEMP_CELSIUS elif self._units == 'F': return TEMP_FAHRENHEIT - else: - return self._units + return self._units class ZWaveAlarmSensor(ZWaveSensor): diff --git a/homeassistant/components/switch/neato.py b/homeassistant/components/switch/neato.py index e61a46f78a6..739e4e03fed 100644 --- a/homeassistant/components/switch/neato.py +++ b/homeassistant/components/switch/neato.py @@ -89,10 +89,7 @@ class NeatoConnectedSwitch(ToggleEntity): @property def available(self): """Return True if entity is available.""" - if not self._state: - return False - else: - return True + return self._state @property def is_on(self): diff --git a/homeassistant/components/switch/rachio.py b/homeassistant/components/switch/rachio.py index b86523ad959..b60aafdf483 100644 --- a/homeassistant/components/switch/rachio.py +++ b/homeassistant/components/switch/rachio.py @@ -137,9 +137,9 @@ class RachioIro(object): if include_disabled: return self._zones - else: - self.update(no_throttle=True) - return [z for z in self._zones if z.is_enabled] + + self.update(no_throttle=True) + return [z for z in self._zones if z.is_enabled] @util.Throttle(MIN_UPDATE_INTERVAL, MIN_FORCED_UPDATE_INTERVAL) def update(self, **kwargs): diff --git a/homeassistant/components/switch/wemo.py b/homeassistant/components/switch/wemo.py index 972eb2d523e..7b97ece337b 100644 --- a/homeassistant/components/switch/wemo.py +++ b/homeassistant/components/switch/wemo.py @@ -162,8 +162,7 @@ class WemoSwitch(SwitchDevice): return STATE_OFF elif standby_state == WEMO_STANDBY: return STATE_STANDBY - else: - return STATE_UNKNOWN + return STATE_UNKNOWN @property def is_on(self): @@ -186,8 +185,7 @@ class WemoSwitch(SwitchDevice): """Return the icon of device based on its type.""" if self._model_name == 'CoffeeMaker': return 'mdi:coffee' - else: - return super().icon + return None def turn_on(self, **kwargs): """Turn the switch on.""" diff --git a/homeassistant/components/telegram_bot/webhooks.py b/homeassistant/components/telegram_bot/webhooks.py index 488fbdfec2b..30d81930b44 100644 --- a/homeassistant/components/telegram_bot/webhooks.py +++ b/homeassistant/components/telegram_bot/webhooks.py @@ -114,5 +114,4 @@ class BotPushReceiver(HomeAssistantView, BaseTelegramBotEntity): if not self.process_message(data): return self.json_message('Invalid message', HTTP_BAD_REQUEST) - else: - return self.json({}) + return self.json({}) diff --git a/homeassistant/components/tts/google.py b/homeassistant/components/tts/google.py index 9b12507de36..3ddcc5c716a 100644 --- a/homeassistant/components/tts/google.py +++ b/homeassistant/components/tts/google.py @@ -129,8 +129,7 @@ class GoogleProvider(Provider): if len(fullstring) > MESSAGE_SIZE: idx = fullstring.rfind(' ', 0, MESSAGE_SIZE) return [fullstring[:idx]] + split_by_space(fullstring[idx:]) - else: - return [fullstring] + return [fullstring] msg_parts = [] for part in parts: diff --git a/homeassistant/remote.py b/homeassistant/remote.py index 9d026eddeff..c8fe62f64d9 100644 --- a/homeassistant/remote.py +++ b/homeassistant/remote.py @@ -116,29 +116,29 @@ class JSONEncoder(json.JSONEncoder): """JSONEncoder that supports Home Assistant objects.""" # pylint: disable=method-hidden - def default(self, obj): + def default(self, o): """Convert Home Assistant objects. Hand other objects to the original method. """ - if isinstance(obj, datetime): - return obj.isoformat() - elif isinstance(obj, set): - return list(obj) - elif hasattr(obj, 'as_dict'): - return obj.as_dict() + if isinstance(o, datetime): + return o.isoformat() + elif isinstance(o, set): + return list(o) + elif hasattr(o, 'as_dict'): + return o.as_dict() try: - return json.JSONEncoder.default(self, obj) + return json.JSONEncoder.default(self, o) except TypeError: # If the JSON serializer couldn't serialize it # it might be a generator, convert it to a list try: return [self.default(child_obj) - for child_obj in obj] + for child_obj in o] except TypeError: # Ok, we're lost, cause the original error - return json.JSONEncoder.default(self, obj) + return json.JSONEncoder.default(self, o) def validate_api(api):