Pylint cleanups (#15626)

* Pylint 2 no-else-return fixes

* Remove unneeded abstract-class-not-used pylint disable
This commit is contained in:
Ville Skyttä 2018-07-23 11:16:05 +03:00 committed by Paulus Schoutsen
parent a38c0d6d15
commit b7c336a687
166 changed files with 425 additions and 490 deletions

View file

@ -83,7 +83,7 @@ class AlarmDotCom(alarm.AlarmControlPanel):
"""Return one or more digits/characters."""
if self._code is None:
return None
elif isinstance(self._code, str) and re.search('^\\d+$', self._code):
if isinstance(self._code, str) and re.search('^\\d+$', self._code):
return 'Number'
return 'Any'
@ -92,9 +92,9 @@ class AlarmDotCom(alarm.AlarmControlPanel):
"""Return the state of the device."""
if self._alarm.state.lower() == 'disarmed':
return STATE_ALARM_DISARMED
elif self._alarm.state.lower() == 'armed stay':
if self._alarm.state.lower() == 'armed stay':
return STATE_ALARM_ARMED_HOME
elif self._alarm.state.lower() == 'armed away':
if self._alarm.state.lower() == 'armed away':
return STATE_ALARM_ARMED_AWAY
return STATE_UNKNOWN

View file

@ -122,10 +122,10 @@ class ArloBaseStation(AlarmControlPanel):
"""Convert Arlo mode to Home Assistant state."""
if mode == ARMED:
return STATE_ALARM_ARMED_AWAY
elif mode == DISARMED:
if mode == DISARMED:
return STATE_ALARM_DISARMED
elif mode == self._home_mode_name:
if mode == self._home_mode_name:
return STATE_ALARM_ARMED_HOME
elif mode == self._away_mode_name:
if mode == self._away_mode_name:
return STATE_ALARM_ARMED_AWAY
return mode

View file

@ -55,9 +55,9 @@ class CanaryAlarm(AlarmControlPanel):
mode = location.mode
if mode.name == LOCATION_MODE_AWAY:
return STATE_ALARM_ARMED_AWAY
elif mode.name == LOCATION_MODE_HOME:
if mode.name == LOCATION_MODE_HOME:
return STATE_ALARM_ARMED_HOME
elif mode.name == LOCATION_MODE_NIGHT:
if mode.name == LOCATION_MODE_NIGHT:
return STATE_ALARM_ARMED_NIGHT
return None

View file

@ -66,7 +66,7 @@ class HomematicipSecurityZone(HomematicipGenericDevice, AlarmControlPanel):
active = self._home.get_security_zones_activation()
if active == (True, True):
return STATE_ALARM_ARMED_AWAY
elif active == (False, True):
if active == (False, True):
return STATE_ALARM_ARMED_HOME
return STATE_ALARM_DISARMED

View file

@ -128,7 +128,7 @@ class IFTTTAlarmPanel(alarm.AlarmControlPanel):
"""Return one or more digits/characters."""
if self._code is None:
return None
elif isinstance(self._code, str) and re.search('^\\d+$', self._code):
if isinstance(self._code, str) and re.search('^\\d+$', self._code):
return 'Number'
return 'Any'

View file

@ -205,7 +205,7 @@ class ManualAlarm(alarm.AlarmControlPanel):
"""Return one or more digits/characters."""
if self._code is None:
return None
elif isinstance(self._code, str) and re.search('^\\d+$', self._code):
if isinstance(self._code, str) and re.search('^\\d+$', self._code):
return 'Number'
return 'Any'

View file

@ -241,7 +241,7 @@ class ManualMQTTAlarm(alarm.AlarmControlPanel):
"""Return one or more digits/characters."""
if self._code is None:
return None
elif isinstance(self._code, str) and re.search('^\\d+$', self._code):
if isinstance(self._code, str) and re.search('^\\d+$', self._code):
return 'Number'
return 'Any'

View file

@ -123,7 +123,7 @@ class MqttAlarm(MqttAvailability, alarm.AlarmControlPanel):
"""Return one or more digits/characters."""
if self._code is None:
return None
elif isinstance(self._code, str) and re.search('^\\d+$', self._code):
if isinstance(self._code, str) and re.search('^\\d+$', self._code):
return 'Number'
return 'Any'

View file

@ -82,7 +82,7 @@ class SimpliSafeAlarm(AlarmControlPanel):
"""Return one or more digits/characters."""
if self._code is None:
return None
elif isinstance(self._code, str) and re.search('^\\d+$', self._code):
if isinstance(self._code, str) and re.search('^\\d+$', self._code):
return 'Number'
return 'Any'

View file

@ -315,7 +315,7 @@ class _AlexaLockController(_AlexaInterface):
if self.entity.state == STATE_LOCKED:
return 'LOCKED'
elif self.entity.state == STATE_UNLOCKED:
if self.entity.state == STATE_UNLOCKED:
return 'UNLOCKED'
return 'JAMMED'

View file

@ -123,9 +123,9 @@ def setup_august(hass, config, api, authenticator):
discovery.load_platform(hass, component, DOMAIN, {}, config)
return True
elif state == AuthenticationState.BAD_PASSWORD:
if state == AuthenticationState.BAD_PASSWORD:
return False
elif state == AuthenticationState.REQUIRES_VALIDATION:
if state == AuthenticationState.REQUIRES_VALIDATION:
request_configuration(hass, config, api, authenticator)
return True

View file

@ -264,7 +264,7 @@ class GrantTokenView(HomeAssistantView):
if grant_type == 'authorization_code':
return await self._async_handle_auth_code(hass, client_id, data)
elif grant_type == 'refresh_token':
if grant_type == 'refresh_token':
return await self._async_handle_refresh_token(
hass, client_id, data)

View file

@ -297,7 +297,7 @@ class AutomationEntity(ToggleEntity):
return
# HomeAssistant is starting up
elif self.hass.state == CoreState.not_running:
if self.hass.state == CoreState.not_running:
@asyncio.coroutine
def async_enable_automation(event):
"""Start automation on startup."""

View file

@ -44,7 +44,7 @@ def async_trigger(hass, config, action):
# Automation are enabled while hass is starting up, fire right away
# Check state because a config reload shouldn't trigger it.
elif hass.state == CoreState.starting:
if hass.state == CoreState.starting:
hass.async_run_job(action, {
'trigger': {
'platform': 'homeassistant',

View file

@ -142,7 +142,7 @@ class NetatmoBinarySensor(BinarySensorDevice):
"""Return the class of this sensor, from DEVICE_CLASSES."""
if self._cameratype == 'NACamera':
return WELCOME_SENSOR_TYPES.get(self._sensor_name)
elif self._cameratype == 'NOC':
if self._cameratype == 'NOC':
return PRESENCE_SENSOR_TYPES.get(self._sensor_name)
return TAG_SENSOR_TYPES.get(self._sensor_name)

View file

@ -111,11 +111,10 @@ class RachioControllerOnlineBinarySensor(RachioControllerBinarySensor):
if data[KEY_STATUS] == STATUS_ONLINE:
return True
elif data[KEY_STATUS] == STATUS_OFFLINE:
if data[KEY_STATUS] == STATUS_OFFLINE:
return False
else:
_LOGGER.warning('"%s" reported in unknown state "%s"', self.name,
data[KEY_STATUS])
_LOGGER.warning('"%s" reported in unknown state "%s"', self.name,
data[KEY_STATUS])
def _handle_update(self, *args, **kwargs) -> None:
"""Handle an update to the state of this sensor."""

View file

@ -67,6 +67,6 @@ class RainCloudBinarySensor(RainCloudEntity, BinarySensorDevice):
"""Return the icon of this device."""
if self._sensor_type == 'is_watering':
return 'mdi:water' if self.is_on else 'mdi:water-off'
elif self._sensor_type == 'status':
if self._sensor_type == 'status':
return 'mdi:pipe' if self.is_on else 'mdi:pipe-disconnected'
return ICON_MAP.get(self._sensor_type)

View file

@ -129,9 +129,9 @@ class ThresholdSensor(BinarySensorDevice):
if self._threshold_lower is not None and \
self._threshold_upper is not None:
return TYPE_RANGE
elif self._threshold_lower is not None:
if self._threshold_lower is not None:
return TYPE_LOWER
elif self._threshold_upper is not None:
if self._threshold_upper is not None:
return TYPE_UPPER
@property

View file

@ -28,7 +28,7 @@ class VolvoSensor(VolvoEntity, BinarySensorDevice):
val = getattr(self.vehicle, self._attribute)
if self._attribute == 'bulb_failures':
return bool(val)
elif self._attribute in ['doors', 'windows']:
if self._attribute in ['doors', 'windows']:
return any([val[key] for key in val if 'Open' in key])
return val != 'Normal'

View file

@ -135,7 +135,7 @@ class IsWorkdaySensor(BinarySensorDevice):
"""Check if given day is in the includes list."""
if day in self._workdays:
return True
elif 'holiday' in self._workdays and now in self._obj_holidays:
if 'holiday' in self._workdays and now in self._obj_holidays:
return True
return False
@ -144,7 +144,7 @@ class IsWorkdaySensor(BinarySensorDevice):
"""Check if given day is in the excludes list."""
if day in self._excludes:
return True
elif 'holiday' in self._excludes and now in self._obj_holidays:
if 'holiday' in self._excludes and now in self._obj_holidays:
return True
return False

View file

@ -124,7 +124,7 @@ class XiaomiNatgasSensor(XiaomiBinarySensor):
return False
self._state = True
return True
elif value == '0':
if value == '0':
if self._state:
self._state = False
return True
@ -184,7 +184,7 @@ class XiaomiMotionSensor(XiaomiBinarySensor):
return False
self._state = True
return True
elif value == NO_MOTION:
if value == NO_MOTION:
if not self._state:
return False
self._state = False
@ -224,7 +224,7 @@ class XiaomiDoorSensor(XiaomiBinarySensor):
return False
self._state = True
return True
elif value == 'close':
if value == 'close':
self._open_since = 0
if self._state:
self._state = False
@ -254,7 +254,7 @@ class XiaomiWaterLeakSensor(XiaomiBinarySensor):
return False
self._state = True
return True
elif value == 'no_leak':
if value == 'no_leak':
if self._state:
self._state = False
return True
@ -290,7 +290,7 @@ class XiaomiSmokeSensor(XiaomiBinarySensor):
return False
self._state = True
return True
elif value == '0':
if value == '0':
if self._state:
self._state = False
return True

View file

@ -342,7 +342,7 @@ class Camera(Entity):
"""Return the camera state."""
if self.is_recording:
return STATE_RECORDING
elif self.is_streaming:
if self.is_streaming:
return STATE_STREAMING
return STATE_IDLE

View file

@ -64,7 +64,7 @@ class AmcrestCam(Camera):
yield from super().handle_async_mjpeg_stream(request)
return
elif self._stream_source == STREAM_SOURCE_LIST['mjpeg']:
if self._stream_source == STREAM_SOURCE_LIST['mjpeg']:
# stream an MJPEG image stream directly from the camera
websession = async_get_clientsession(self.hass)
streaming_url = self._camera.mjpeg_url(typeno=self._resolution)

View file

@ -23,7 +23,7 @@ def _get_image_url(host, port, mode):
"""Set the URL to get the image."""
if mode == 'mjpeg':
return 'http://{}:{}/axis-cgi/mjpg/video.cgi'.format(host, port)
elif mode == 'single':
if mode == 'single':
return 'http://{}:{}/axis-cgi/jpg/image.cgi'.format(host, port)

View file

@ -105,6 +105,6 @@ class NetatmoCamera(Camera):
"""Return the camera model."""
if self._cameratype == "NOC":
return "Presence"
elif self._cameratype == "NACamera":
if self._cameratype == "NACamera":
return "Welcome"
return None

View file

@ -171,10 +171,9 @@ class UnifiVideoCamera(Camera):
if retry:
self._login()
return _get_image(retry=False)
else:
_LOGGER.error(
"Unable to log into camera, unable to get snapshot")
raise
_LOGGER.error(
"Unable to log into camera, unable to get snapshot")
raise
return _get_image()

View file

@ -177,7 +177,7 @@ class Thermostat(ClimateDevice):
return None
if self.current_operation == STATE_HEAT:
return self.thermostat['runtime']['desiredHeat'] / 10.0
elif self.current_operation == STATE_COOL:
if self.current_operation == STATE_COOL:
return self.thermostat['runtime']['desiredCool'] / 10.0
return None
@ -217,15 +217,15 @@ class Thermostat(ClimateDevice):
return 'away'
# A permanent hold from away climate
return AWAY_MODE
elif event['holdClimateRef'] != "":
if event['holdClimateRef'] != "":
# Any other hold based on climate
return event['holdClimateRef']
# Any hold not based on a climate is a temp hold
return TEMPERATURE_HOLD
elif event['type'].startswith('auto'):
if event['type'].startswith('auto'):
# All auto modes are treated as holds
return event['type'][4:].lower()
elif event['type'] == 'vacation':
if event['type'] == 'vacation':
self.vacation = event['name']
return VACATION_HOLD
return None
@ -317,7 +317,7 @@ class Thermostat(ClimateDevice):
if hold == hold_mode:
# no change, so no action required
return
elif hold_mode == 'None' or hold_mode is None:
if hold_mode == 'None' or hold_mode is None:
if hold == VACATION_HOLD:
self.data.ecobee.delete_vacation(
self.thermostat_index, self.vacation)

View file

@ -87,7 +87,7 @@ class HMThermostat(HMDevice, ClimateDevice):
# HM ip etrv 2 uses the set_point_mode to say if its
# auto or manual
elif not set_point_mode == -1:
if not set_point_mode == -1:
code = set_point_mode
# Other devices use the control_mode
else:

View file

@ -192,9 +192,9 @@ class MelissaClimate(ClimateDevice):
"""Translate Melissa states to hass states."""
if state == self._api.STATE_ON:
return STATE_ON
elif state == self._api.STATE_OFF:
if state == self._api.STATE_OFF:
return STATE_OFF
elif state == self._api.STATE_IDLE:
if state == self._api.STATE_IDLE:
return STATE_IDLE
return None
@ -202,11 +202,11 @@ class MelissaClimate(ClimateDevice):
"""Translate Melissa modes to hass states."""
if mode == self._api.MODE_HEAT:
return STATE_HEAT
elif mode == self._api.MODE_COOL:
if mode == self._api.MODE_COOL:
return STATE_COOL
elif mode == self._api.MODE_DRY:
if mode == self._api.MODE_DRY:
return STATE_DRY
elif mode == self._api.MODE_FAN:
if mode == self._api.MODE_FAN:
return STATE_FAN_ONLY
_LOGGER.warning(
"Operation mode %s could not be mapped to hass", mode)
@ -216,11 +216,11 @@ class MelissaClimate(ClimateDevice):
"""Translate Melissa fan modes to hass modes."""
if fan == self._api.FAN_AUTO:
return STATE_AUTO
elif fan == self._api.FAN_LOW:
if fan == self._api.FAN_LOW:
return SPEED_LOW
elif fan == self._api.FAN_MEDIUM:
if fan == self._api.FAN_MEDIUM:
return SPEED_MEDIUM
elif fan == self._api.FAN_HIGH:
if fan == self._api.FAN_HIGH:
return SPEED_HIGH
_LOGGER.warning("Fan mode %s could not be mapped to hass", fan)
return None
@ -229,24 +229,22 @@ class MelissaClimate(ClimateDevice):
"""Translate hass states to melissa modes."""
if mode == STATE_HEAT:
return self._api.MODE_HEAT
elif mode == STATE_COOL:
if mode == STATE_COOL:
return self._api.MODE_COOL
elif mode == STATE_DRY:
if mode == STATE_DRY:
return self._api.MODE_DRY
elif mode == STATE_FAN_ONLY:
if mode == STATE_FAN_ONLY:
return self._api.MODE_FAN
else:
_LOGGER.warning("Melissa have no setting for %s mode", mode)
_LOGGER.warning("Melissa have no setting for %s mode", mode)
def hass_fan_to_melissa(self, fan):
"""Translate hass fan modes to melissa modes."""
if fan == STATE_AUTO:
return self._api.FAN_AUTO
elif fan == SPEED_LOW:
if fan == SPEED_LOW:
return self._api.FAN_LOW
elif fan == SPEED_MEDIUM:
if fan == SPEED_MEDIUM:
return self._api.FAN_MEDIUM
elif fan == SPEED_HIGH:
if fan == SPEED_HIGH:
return self._api.FAN_HIGH
else:
_LOGGER.warning("Melissa have no setting for %s fan mode", fan)
_LOGGER.warning("Melissa have no setting for %s fan mode", fan)

View file

@ -147,7 +147,7 @@ class NestThermostat(ClimateDevice):
"""Return current operation ie. heat, cool, idle."""
if self._mode in [STATE_HEAT, STATE_COOL, STATE_OFF, STATE_ECO]:
return self._mode
elif self._mode == NEST_MODE_HEAT_COOL:
if self._mode == NEST_MODE_HEAT_COOL:
return STATE_AUTO
return STATE_UNKNOWN

View file

@ -99,7 +99,7 @@ class NetatmoThermostat(ClimateDevice):
state = self._data.thermostatdata.relay_cmd
if state == 0:
return STATE_IDLE
elif state == 100:
if state == 100:
return STATE_HEAT
@property

View file

@ -102,9 +102,9 @@ class ProliphixThermostat(ClimateDevice):
state = self._pdp.hvac_state
if state in (1, 2):
return STATE_IDLE
elif state == 3:
if state == 3:
return STATE_HEAT
elif state == 6:
if state == 6:
return STATE_COOL
def set_temperature(self, **kwargs):

View file

@ -87,7 +87,7 @@ class TuyaClimateDevice(TuyaDevice, ClimateDevice):
unit = self.tuya.temperature_unit()
if unit == 'CELSIUS':
return TEMP_CELSIUS
elif unit == 'FAHRENHEIT':
if unit == 'FAHRENHEIT':
return TEMP_FAHRENHEIT
return TEMP_CELSIUS

View file

@ -152,9 +152,9 @@ class VenstarThermostat(ClimateDevice):
"""Return current operation ie. heat, cool, idle."""
if self._client.mode == self._client.MODE_HEAT:
return STATE_HEAT
elif self._client.mode == self._client.MODE_COOL:
if self._client.mode == self._client.MODE_COOL:
return STATE_COOL
elif self._client.mode == self._client.MODE_AUTO:
if self._client.mode == self._client.MODE_AUTO:
return STATE_AUTO
return STATE_OFF
@ -178,7 +178,7 @@ class VenstarThermostat(ClimateDevice):
"""Return the target temperature we try to reach."""
if self._client.mode == self._client.MODE_HEAT:
return self._client.heattemp
elif self._client.mode == self._client.MODE_COOL:
if self._client.mode == self._client.MODE_COOL:
return self._client.cooltemp
return None

View file

@ -55,11 +55,11 @@ class VeraThermostat(VeraDevice, ClimateDevice):
mode = self.vera_device.get_hvac_mode()
if mode == 'HeatOn':
return OPERATION_LIST[0] # heat
elif mode == 'CoolOn':
if mode == 'CoolOn':
return OPERATION_LIST[1] # cool
elif mode == 'AutoChangeOver':
if mode == 'AutoChangeOver':
return OPERATION_LIST[2] # auto
elif mode == 'Off':
if mode == 'Off':
return OPERATION_LIST[3] # off
return 'Off'
@ -74,9 +74,9 @@ class VeraThermostat(VeraDevice, ClimateDevice):
mode = self.vera_device.get_fan_mode()
if mode == "ContinuousOn":
return FAN_OPERATION_LIST[0] # on
elif mode == "Auto":
if mode == "Auto":
return FAN_OPERATION_LIST[1] # auto
elif mode == "PeriodicOn":
if mode == "PeriodicOn":
return FAN_OPERATION_LIST[2] # cycle
return "Auto"

View file

@ -224,7 +224,7 @@ class WinkThermostat(WinkDevice, ClimateDevice):
if self.current_operation != STATE_AUTO and not self.is_away_mode_on:
if self.current_operation == STATE_COOL:
return self.wink.current_max_set_point()
elif self.current_operation == STATE_HEAT:
if self.current_operation == STATE_HEAT:
return self.wink.current_min_set_point()
return None
@ -311,7 +311,7 @@ class WinkThermostat(WinkDevice, ClimateDevice):
"""Return whether the fan is on."""
if self.wink.current_fan_mode() == 'on':
return STATE_ON
elif self.wink.current_fan_mode() == 'auto':
if self.wink.current_fan_mode() == 'auto':
return STATE_AUTO
# No Fan available so disable slider
return None
@ -483,7 +483,7 @@ class WinkAC(WinkDevice, ClimateDevice):
speed = self.wink.current_fan_speed()
if speed <= 0.33:
return SPEED_LOW
elif speed <= 0.66:
if speed <= 0.66:
return SPEED_MEDIUM
return SPEED_HIGH

View file

@ -186,7 +186,7 @@ class ZWaveClimate(ZWaveDeviceEntity, ClimateDevice):
"""Return the unit of measurement."""
if self._unit == 'C':
return TEMP_CELSIUS
elif self._unit == 'F':
if self._unit == 'F':
return TEMP_FAHRENHEIT
return self._unit

View file

@ -97,7 +97,7 @@ class DemoCover(CoverDevice):
"""Close the cover."""
if self._position == 0:
return
elif self._position is None:
if self._position is None:
self._closed = True
self.schedule_update_ha_state()
return
@ -119,7 +119,7 @@ class DemoCover(CoverDevice):
"""Open the cover."""
if self._position == 100:
return
elif self._position is None:
if self._position is None:
self._closed = False
self.schedule_update_ha_state()
return

View file

@ -27,11 +27,10 @@ def get_device(hass, values, node_config, **kwargs):
zwave.const.COMMAND_CLASS_SWITCH_MULTILEVEL
and values.primary.index == 0):
return ZwaveRollershutter(hass, values, invert_buttons)
elif (values.primary.command_class ==
zwave.const.COMMAND_CLASS_SWITCH_BINARY):
if values.primary.command_class == zwave.const.COMMAND_CLASS_SWITCH_BINARY:
return ZwaveGarageDoorSwitch(values)
elif (values.primary.command_class ==
zwave.const.COMMAND_CLASS_BARRIER_OPERATOR):
if values.primary.command_class == \
zwave.const.COMMAND_CLASS_BARRIER_OPERATOR:
return ZwaveGarageDoorBarrier(values)
return None
@ -84,7 +83,7 @@ class ZwaveRollershutter(zwave.ZWaveDeviceEntity, CoverDevice):
if self._current_position is not None:
if self._current_position <= 5:
return 0
elif self._current_position >= 95:
if self._current_position >= 95:
return 100
return self._current_position

View file

@ -57,7 +57,7 @@ class DeconzFlowHandler(data_entry_flow.FlowHandler):
if len(self.bridges) == 1:
self.deconz_config = self.bridges[0]
return await self.async_step_link()
elif len(self.bridges) > 1:
if len(self.bridges) > 1:
hosts = []
for bridge in self.bridges:
hosts.append(bridge[CONF_HOST])

View file

@ -537,7 +537,7 @@ class Device(Entity):
"""
if not self.last_seen:
return
elif self.location_name:
if self.location_name:
self._state = self.location_name
elif self.gps is not None and self.source_type == SOURCE_TYPE_GPS:
zone_state = async_active_zone(

View file

@ -94,10 +94,10 @@ class ArubaDeviceScanner(DeviceScanner):
if query == 1:
_LOGGER.error("Timeout")
return
elif query == 2:
if query == 2:
_LOGGER.error("Unexpected response from router")
return
elif query == 3:
if query == 3:
ssh.sendline('yes')
ssh.expect('password:')
elif query == 4:

View file

@ -94,8 +94,7 @@ def _get_homehub_data(url):
return
if response.status_code == 200:
return _parse_homehub_response(response.text)
else:
_LOGGER.error("Invalid response from Home Hub: %s", response)
_LOGGER.error("Invalid response from Home Hub: %s", response)
def _parse_homehub_response(data_str):

View file

@ -131,13 +131,12 @@ class DdWrtDeviceScanner(DeviceScanner):
return
if response.status_code == 200:
return _parse_ddwrt_response(response.text)
elif response.status_code == 401:
if response.status_code == 401:
# Authentication error
_LOGGER.exception(
"Failed to authenticate, check your username and password")
return
else:
_LOGGER.error("Invalid response from DD-WRT: %s", response)
_LOGGER.error("Invalid response from DD-WRT: %s", response)
def _parse_ddwrt_response(data_str):

View file

@ -70,16 +70,15 @@ class GeofencyView(HomeAssistantView):
if self._is_mobile_beacon(data):
return (yield from self._set_location(hass, data, None))
if data['entry'] == LOCATION_ENTRY:
location_name = data['name']
else:
if data['entry'] == LOCATION_ENTRY:
location_name = data['name']
else:
location_name = STATE_NOT_HOME
if ATTR_CURRENT_LATITUDE in data:
data[ATTR_LATITUDE] = data[ATTR_CURRENT_LATITUDE]
data[ATTR_LONGITUDE] = data[ATTR_CURRENT_LONGITUDE]
location_name = STATE_NOT_HOME
if ATTR_CURRENT_LATITUDE in data:
data[ATTR_LATITUDE] = data[ATTR_CURRENT_LATITUDE]
data[ATTR_LONGITUDE] = data[ATTR_CURRENT_LONGITUDE]
return (yield from self._set_location(hass, data, location_name))
return (yield from self._set_location(hass, data, location_name))
@staticmethod
def _validate_data(data):

View file

@ -84,7 +84,7 @@ class LocativeView(HomeAssistantView):
gps=gps_location))
return 'Setting location to {}'.format(location_name)
elif direction == 'exit':
if direction == 'exit':
current_state = hass.states.get(
'{}.{}'.format(DOMAIN, device))
@ -102,7 +102,7 @@ class LocativeView(HomeAssistantView):
return 'Ignoring exit from {} (already in {})'.format(
location_name, current_state)
elif direction == 'test':
if 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.'

View file

@ -74,17 +74,16 @@ class MerakiView(HomeAssistantView):
_LOGGER.error("Invalid Secret received from Meraki")
return self.json_message('Invalid secret',
HTTP_UNPROCESSABLE_ENTITY)
elif data['version'] != VERSION:
if data['version'] != VERSION:
_LOGGER.error("Invalid API version: %s", data['version'])
return self.json_message('Invalid version',
HTTP_UNPROCESSABLE_ENTITY)
else:
_LOGGER.debug('Valid Secret')
if data['type'] not in ('DevicesSeen', 'BluetoothDevicesSeen'):
_LOGGER.error("Unknown Device %s", data['type'])
return self.json_message('Invalid device type',
HTTP_UNPROCESSABLE_ENTITY)
_LOGGER.debug("Processing %s", data['type'])
_LOGGER.debug('Valid Secret')
if data['type'] not in ('DevicesSeen', 'BluetoothDevicesSeen'):
_LOGGER.error("Unknown Device %s", data['type'])
return self.json_message('Invalid device type',
HTTP_UNPROCESSABLE_ENTITY)
_LOGGER.debug("Processing %s", data['type'])
if not data["data"]["observations"]:
_LOGGER.debug("No observations found")
return

View file

@ -91,8 +91,7 @@ def _get_skyhub_data(url):
return
if response.status_code == 200:
return _parse_skyhub_response(response.text)
else:
_LOGGER.error("Invalid response from Sky Hub: %s", response)
_LOGGER.error("Invalid response from Sky Hub: %s", response)
def _parse_skyhub_response(data_str):

View file

@ -107,7 +107,7 @@ class TomatoDeviceScanner(DeviceScanner):
json.loads(value.replace("'", '"'))
return True
elif response.status_code == 401:
if response.status_code == 401:
# Authentication error
_LOGGER.exception((
"Failed to authenticate, "

View file

@ -106,9 +106,9 @@ class BrightnessTrait(_Trait):
"""Test if state is supported."""
if domain == light.DOMAIN:
return features & light.SUPPORT_BRIGHTNESS
elif domain == cover.DOMAIN:
if domain == cover.DOMAIN:
return features & cover.SUPPORT_SET_POSITION
elif domain == media_player.DOMAIN:
if domain == media_player.DOMAIN:
return features & media_player.SUPPORT_VOLUME_SET
return False

View file

@ -137,8 +137,8 @@ class GraphiteFeeder(threading.Thread):
_LOGGER.debug("Event processing thread stopped")
self._queue.task_done()
return
elif (event.event_type == EVENT_STATE_CHANGED and
event.data.get('new_state')):
if event.event_type == EVENT_STATE_CHANGED and \
event.data.get('new_state'):
_LOGGER.debug("Processing STATE_CHANGED event for %s",
event.data['entity_id'])
try:

View file

@ -140,7 +140,7 @@ def async_check_config(hass):
if not result:
return "Hass.io config check API error"
elif result['result'] == "error":
if result['result'] == "error":
return result['message']
return None

View file

@ -124,8 +124,7 @@ class Thermostat(HomeAccessory):
if hass_value == STATE_OFF:
self.hass.services.call(DOMAIN, SERVICE_TURN_OFF, params)
return
else:
self.hass.services.call(DOMAIN, SERVICE_TURN_ON, params)
self.hass.services.call(DOMAIN, SERVICE_TURN_ON, params)
params = {ATTR_ENTITY_ID: self.entity_id,
ATTR_OPERATION_MODE: hass_value}
self.hass.services.call(DOMAIN, SERVICE_SET_OPERATION_MODE, params)

View file

@ -142,10 +142,10 @@ def density_to_air_quality(density):
"""Map PM2.5 density to HomeKit AirQuality level."""
if density <= 35:
return 1
elif density <= 75:
if density <= 75:
return 2
elif density <= 115:
if density <= 115:
return 3
elif density <= 150:
if density <= 150:
return 4
return 5

View file

@ -70,8 +70,7 @@ class HomematicipCloudFlowHandler(data_entry_flow.FlowHandler):
HMIPC_NAME: self.auth.config.get(HMIPC_NAME)
})
return self.async_abort(reason='conection_aborted')
else:
errors['base'] = 'press_the_button'
errors['base'] = 'press_the_button'
return self.async_show_form(step_id='link', errors=errors)

View file

@ -109,7 +109,7 @@ async def async_validate_auth_header(request, api_password=None):
request['hass_user'] = access_token.refresh_token.user
return True
elif auth_type == 'Basic' and api_password is not None:
if auth_type == 'Basic' and api_password is not None:
decoded = base64.b64decode(auth_val).decode('utf-8')
try:
username, password = decoded.split(':', 1)
@ -123,5 +123,4 @@ async def async_validate_auth_header(request, api_password=None):
return hmac.compare_digest(api_password.encode('utf-8'),
password.encode('utf-8'))
else:
return False
return False

View file

@ -31,10 +31,9 @@ class CachingStaticResource(StaticResource):
if filepath.is_dir():
return await super()._handle(request)
elif filepath.is_file():
if filepath.is_file():
return CachingFileResponse(filepath, chunk_size=self._chunk_size)
else:
raise HTTPNotFound
raise HTTPNotFound
# pylint: disable=too-many-ancestors

View file

@ -84,7 +84,7 @@ class HueFlowHandler(data_entry_flow.FlowHandler):
reason='all_configured'
)
elif len(hosts) == 1:
if len(hosts) == 1:
self.host = hosts[0]
return await self.async_step_link()

View file

@ -172,7 +172,7 @@ class KNXModule:
"""Return the connection_config."""
if CONF_KNX_TUNNELING in self.config[DOMAIN]:
return self.connection_config_tunneling()
elif CONF_KNX_ROUTING in self.config[DOMAIN]:
if CONF_KNX_ROUTING in self.config[DOMAIN]:
return self.connection_config_routing()
return self.connection_config_auto()

View file

@ -88,7 +88,7 @@ class AbodeLight(AbodeDevice, Light):
"""Flag supported features."""
if self._device.is_dimmable and self._device.has_color:
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR
elif self._device.is_dimmable:
if self._device.is_dimmable:
return SUPPORT_BRIGHTNESS
return 0

View file

@ -245,7 +245,7 @@ class FluxLight(Light):
return
# Effect selection
elif effect in EFFECT_MAP:
if effect in EFFECT_MAP:
self._bulb.setPresetPattern(EFFECT_MAP[effect], 50)
return

View file

@ -380,16 +380,16 @@ def _entry_message_from_state(domain, state):
return 'is away'
return 'is at {}'.format(state.state)
elif domain == 'sun':
if domain == 'sun':
if state.state == sun.STATE_ABOVE_HORIZON:
return 'has risen'
return 'has set'
elif state.state == STATE_ON:
if state.state == STATE_ON:
# Future: combine groups and its entity entries ?
return "turned on"
elif state.state == STATE_OFF:
if state.state == STATE_OFF:
return "turned off"
return "changed to {}".format(state.state)

View file

@ -100,7 +100,7 @@ class AnthemAVR(MediaPlayerDevice):
if pwrstate is True:
return STATE_ON
elif pwrstate is False:
if pwrstate is False:
return STATE_OFF
return STATE_UNKNOWN

View file

@ -103,11 +103,11 @@ class AppleTvDevice(MediaPlayerDevice):
if state in (const.PLAY_STATE_IDLE, const.PLAY_STATE_NO_MEDIA,
const.PLAY_STATE_LOADING):
return STATE_IDLE
elif state == const.PLAY_STATE_PLAYING:
if state == const.PLAY_STATE_PLAYING:
return STATE_PLAYING
elif state in (const.PLAY_STATE_PAUSED,
const.PLAY_STATE_FAST_FORWARD,
const.PLAY_STATE_FAST_BACKWARD):
if state in (const.PLAY_STATE_PAUSED,
const.PLAY_STATE_FAST_FORWARD,
const.PLAY_STATE_FAST_BACKWARD):
# Catch fast forward/backward here so "play" is default action
return STATE_PAUSED
return STATE_STANDBY # Bad or unknown state?
@ -140,9 +140,9 @@ class AppleTvDevice(MediaPlayerDevice):
media_type = self._playing.media_type
if media_type == const.MEDIA_TYPE_VIDEO:
return MEDIA_TYPE_VIDEO
elif media_type == const.MEDIA_TYPE_MUSIC:
if media_type == const.MEDIA_TYPE_MUSIC:
return MEDIA_TYPE_MUSIC
elif media_type == const.MEDIA_TYPE_TV:
if media_type == const.MEDIA_TYPE_TV:
return MEDIA_TYPE_TVSHOW
@property
@ -221,7 +221,7 @@ class AppleTvDevice(MediaPlayerDevice):
state = self.state
if state == STATE_PAUSED:
return self.atv.remote_control.play()
elif state == STATE_PLAYING:
if state == STATE_PLAYING:
return self.atv.remote_control.pause()
def async_media_play(self):

View file

@ -530,7 +530,7 @@ class BluesoundPlayer(MediaPlayerDevice):
status = self._status.get('state', None)
if status in ('pause', 'stop'):
return STATE_PAUSED
elif status in ('stream', 'play'):
if status in ('stream', 'play'):
return STATE_PLAYING
return STATE_IDLE
@ -974,6 +974,5 @@ class BluesoundPlayer(MediaPlayerDevice):
if volume > 0:
self._lastvol = volume
return await self.send_bluesound_command('Volume?level=0')
else:
return await self.send_bluesound_command(
'Volume?level=' + str(float(self._lastvol) * 100))
return await self.send_bluesound_command(
'Volume?level=' + str(float(self._lastvol) * 100))

View file

@ -88,23 +88,23 @@ def setup_bravia(config, pin, hass, add_devices):
if pin is None:
request_configuration(config, hass, add_devices)
return
else:
mac = _get_mac_address(host)
if mac is not None:
mac = mac.decode('utf8')
# If we came here and configuring this host, mark as done
if host in _CONFIGURING:
request_id = _CONFIGURING.pop(host)
configurator = hass.components.configurator
configurator.request_done(request_id)
_LOGGER.info("Discovery configuration done")
# Save config
save_json(
hass.config.path(BRAVIA_CONFIG_FILE),
{host: {'pin': pin, 'host': host, 'mac': mac}})
mac = _get_mac_address(host)
if mac is not None:
mac = mac.decode('utf8')
# If we came here and configuring this host, mark as done
if host in _CONFIGURING:
request_id = _CONFIGURING.pop(host)
configurator = hass.components.configurator
configurator.request_done(request_id)
_LOGGER.info("Discovery configuration done")
add_devices([BraviaTVDevice(host, mac, name, pin)])
# Save config
save_json(
hass.config.path(BRAVIA_CONFIG_FILE),
{host: {'pin': pin, 'host': host, 'mac': mac}})
add_devices([BraviaTVDevice(host, mac, name, pin)])
def request_configuration(config, hass, add_devices):

View file

@ -499,13 +499,13 @@ class CastDevice(MediaPlayerDevice):
"""Return the state of the player."""
if self.media_status is None:
return None
elif self.media_status.player_is_playing:
if self.media_status.player_is_playing:
return STATE_PLAYING
elif self.media_status.player_is_paused:
if self.media_status.player_is_paused:
return STATE_PAUSED
elif self.media_status.player_is_idle:
if self.media_status.player_is_idle:
return STATE_IDLE
elif self._chromecast is not None and self._chromecast.is_idle:
if self._chromecast is not None and self._chromecast.is_idle:
return STATE_OFF
return None
@ -534,11 +534,11 @@ class CastDevice(MediaPlayerDevice):
"""Content type of current playing media."""
if self.media_status is None:
return None
elif self.media_status.media_is_tvshow:
if self.media_status.media_is_tvshow:
return MEDIA_TYPE_TVSHOW
elif self.media_status.media_is_movie:
if self.media_status.media_is_movie:
return MEDIA_TYPE_MOVIE
elif self.media_status.media_is_musictrack:
if self.media_status.media_is_musictrack:
return MEDIA_TYPE_MUSIC
return None

View file

@ -217,7 +217,7 @@ class ChannelsPlayer(MediaPlayerDevice):
"""Image url of current playing media."""
if self.now_playing_image_url:
return self.now_playing_image_url
elif self.channel_image_url:
if self.channel_image_url:
return self.channel_image_url
return 'https://getchannels.com/assets/img/icon-1024.png'

View file

@ -91,7 +91,7 @@ class CmusDevice(MediaPlayerDevice):
"""Return the media state."""
if self.status.get('status') == 'playing':
return STATE_PLAYING
elif self.status.get('status') == 'paused':
if self.status.get('status') == 'paused':
return STATE_PAUSED
return STATE_OFF

View file

@ -261,7 +261,7 @@ class DenonDevice(MediaPlayerDevice):
"""Title of current playing media."""
if self._current_source not in self._receiver.playing_func_list:
return self._current_source
elif self._title is not None:
if self._title is not None:
return self._title
return self._frequency

View file

@ -140,7 +140,7 @@ class DirecTvDevice(MediaPlayerDevice):
"""Return the title of current episode of TV show."""
if self._is_standby:
return None
elif 'episodeTitle' in self._current:
if 'episodeTitle' in self._current:
return self._current['episodeTitle']
return None

View file

@ -206,11 +206,11 @@ class EmbyDevice(MediaPlayerDevice):
state = self.device.state
if state == 'Paused':
return STATE_PAUSED
elif state == 'Playing':
if state == 'Playing':
return STATE_PLAYING
elif state == 'Idle':
if state == 'Idle':
return STATE_IDLE
elif state == 'Off':
if state == 'Off':
return STATE_OFF
@property
@ -230,15 +230,15 @@ class EmbyDevice(MediaPlayerDevice):
media_type = self.device.media_type
if media_type == 'Episode':
return MEDIA_TYPE_TVSHOW
elif media_type == 'Movie':
if media_type == 'Movie':
return MEDIA_TYPE_MOVIE
elif media_type == 'Trailer':
if media_type == 'Trailer':
return MEDIA_TYPE_TRAILER
elif media_type == 'Music':
if media_type == 'Music':
return MEDIA_TYPE_MUSIC
elif media_type == 'Video':
if media_type == 'Video':
return MEDIA_TYPE_GENERIC_VIDEO
elif media_type == 'Audio':
if media_type == 'Audio':
return MEDIA_TYPE_MUSIC
return None

View file

@ -749,7 +749,7 @@ class KodiDevice(MediaPlayerDevice):
if media_type == "CHANNEL":
return self.server.Player.Open(
{"item": {"channelid": int(media_id)}})
elif media_type == "PLAYLIST":
if media_type == "PLAYLIST":
return self.server.Player.Open(
{"item": {"playlistid": int(media_id)}})

View file

@ -202,7 +202,7 @@ class LiveboxPlayTvDevice(MediaPlayerDevice):
state = self._client.media_state
if state == 'PLAY':
return STATE_PLAYING
elif state == 'PAUSE':
if state == 'PAUSE':
return STATE_PAUSED
return STATE_ON if self._client.is_on else STATE_OFF

View file

@ -93,7 +93,7 @@ class MpcHcDevice(MediaPlayerDevice):
return STATE_OFF
if state == 'playing':
return STATE_PLAYING
elif state == 'paused':
if state == 'paused':
return STATE_PAUSED
return STATE_IDLE

View file

@ -141,11 +141,11 @@ class MpdDevice(MediaPlayerDevice):
"""Return the media state."""
if self._status is None:
return STATE_OFF
elif self._status['state'] == 'play':
if self._status['state'] == 'play':
return STATE_PLAYING
elif self._status['state'] == 'pause':
if self._status['state'] == 'pause':
return STATE_PAUSED
elif self._status['state'] == 'stop':
if self._status['state'] == 'stop':
return STATE_OFF
return STATE_OFF
@ -182,9 +182,9 @@ class MpdDevice(MediaPlayerDevice):
if file_name is None:
return "None"
return os.path.basename(file_name)
elif name is None:
if name is None:
return title
elif title is None:
if title is None:
return name
return '{}: {}'.format(name, title)

View file

@ -573,11 +573,11 @@ class PlexClient(MediaPlayerDevice):
_LOGGER.debug("Clip content type detected, "
"compatibility may vary: %s", self.entity_id)
return MEDIA_TYPE_TVSHOW
elif self._session_type == 'episode':
if self._session_type == 'episode':
return MEDIA_TYPE_TVSHOW
elif self._session_type == 'movie':
if self._session_type == 'movie':
return MEDIA_TYPE_MOVIE
elif self._session_type == 'track':
if self._session_type == 'track':
return MEDIA_TYPE_MUSIC
return None
@ -654,7 +654,7 @@ class PlexClient(MediaPlayerDevice):
if not self._make:
return None
# no mute support
elif self.make.lower() == "shield android tv":
if self.make.lower() == "shield android tv":
_LOGGER.debug(
"Shield Android TV client detected, disabling mute "
"controls: %s", self.entity_id)
@ -663,7 +663,7 @@ class PlexClient(MediaPlayerDevice):
SUPPORT_VOLUME_SET | SUPPORT_PLAY |
SUPPORT_TURN_OFF)
# Only supports play,pause,stop (and off which really is stop)
elif self.make.lower().startswith("tivo"):
if self.make.lower().startswith("tivo"):
_LOGGER.debug(
"Tivo client detected, only enabling pause, play, "
"stop, and off controls: %s", self.entity_id)
@ -671,7 +671,7 @@ class PlexClient(MediaPlayerDevice):
SUPPORT_TURN_OFF)
# Not all devices support playback functionality
# Playback includes volume, stop/play/pause, etc.
elif self.device and 'playback' in self._device_protocol_capabilities:
if self.device and 'playback' in self._device_protocol_capabilities:
return (SUPPORT_PAUSE | SUPPORT_PREVIOUS_TRACK |
SUPPORT_NEXT_TRACK | SUPPORT_STOP |
SUPPORT_VOLUME_SET | SUPPORT_PLAY |

View file

@ -134,9 +134,9 @@ class RokuDevice(MediaPlayerDevice):
if (self.current_app.name == "Power Saver" or
self.current_app.is_screensaver):
return STATE_IDLE
elif self.current_app.name == "Roku":
if self.current_app.name == "Roku":
return STATE_HOME
elif self.current_app.name is not None:
if self.current_app.name is not None:
return STATE_PLAYING
return STATE_UNKNOWN
@ -156,9 +156,9 @@ class RokuDevice(MediaPlayerDevice):
"""Content type of current playing media."""
if self.current_app is None:
return None
elif self.current_app.name == "Power Saver":
if self.current_app.name == "Power Saver":
return None
elif self.current_app.name == "Roku":
if self.current_app.name == "Roku":
return None
return MEDIA_TYPE_MOVIE
@ -167,11 +167,11 @@ class RokuDevice(MediaPlayerDevice):
"""Image url of current playing media."""
if self.current_app is None:
return None
elif self.current_app.name == "Roku":
if self.current_app.name == "Roku":
return None
elif self.current_app.name == "Power Saver":
if self.current_app.name == "Power Saver":
return None
elif self.current_app.id is None:
if self.current_app.id is None:
return None
return 'http://{0}:{1}/query/icon/{2}'.format(

View file

@ -100,8 +100,7 @@ class RussoundZoneDevice(MediaPlayerDevice):
if value in (None, "", "------"):
return None
return value
else:
return None
return None
def _zone_callback_handler(self, zone_id, *args):
if zone_id == self._zone_id:
@ -134,7 +133,7 @@ class RussoundZoneDevice(MediaPlayerDevice):
status = self._zone_var('status', "OFF")
if status == 'ON':
return STATE_ON
elif status == 'OFF':
if status == 'OFF':
return STATE_OFF
@property

View file

@ -269,7 +269,7 @@ class SoundTouchDevice(MediaPlayerDevice):
"""Title of current playing media."""
if self._status.station_name is not None:
return self._status.station_name
elif self._status.artist is not None:
if self._status.artist is not None:
return self._status.artist + " - " + self._status.track
return None

View file

@ -95,7 +95,7 @@ class VizioDevice(MediaPlayerDevice):
if is_on is None:
self._state = STATE_UNKNOWN
return
elif is_on is False:
if is_on is False:
self._state = STATE_OFF
else:
self._state = STATE_ON

View file

@ -142,7 +142,7 @@ class Volumio(MediaPlayerDevice):
status = self._state.get('status', None)
if status == 'pause':
return STATE_PAUSED
elif status == 'play':
if status == 'play':
return STATE_PLAYING
return STATE_IDLE

View file

@ -52,9 +52,8 @@ def is_persistence_file(value):
"""Validate that persistence file path ends in either .pickle or .json."""
if value.endswith(('.json', '.pickle')):
return value
else:
raise vol.Invalid(
'{} does not end in either `.json` or `.pickle`'.format(value))
raise vol.Invalid(
'{} does not end in either `.json` or `.pickle`'.format(value))
def deprecated(key):

View file

@ -38,10 +38,8 @@ def is_serial_port(value):
ports = ('COM{}'.format(idx + 1) for idx in range(256))
if value in ports:
return value
else:
raise vol.Invalid('{} is not a serial port'.format(value))
else:
return cv.isdevice(value)
raise vol.Invalid('{} is not a serial port'.format(value))
return cv.isdevice(value)
def is_socket_address(value):

View file

@ -65,14 +65,14 @@ class NestFlowHandler(data_entry_flow.FlowHandler):
if self.hass.config_entries.async_entries(DOMAIN):
return self.async_abort(reason='already_setup')
elif not flows:
if not flows:
return self.async_abort(reason='no_flows')
elif len(flows) == 1:
if len(flows) == 1:
self.flow_impl = list(flows)[0]
return await self.async_step_link()
elif user_input is not None:
if user_input is not None:
self.flow_impl = user_input['flow_impl']
return await self.async_step_link()

View file

@ -61,7 +61,7 @@ class LTEData:
"""Get the requested or the only modem_data value."""
if CONF_HOST in config:
return self.modem_data.get(config[CONF_HOST])
elif len(self.modem_data) == 1:
if len(self.modem_data) == 1:
return next(iter(self.modem_data.values()))
return None

View file

@ -280,7 +280,7 @@ class HTML5PushCallbackView(HomeAssistantView):
return self.json_message('Authorization header must '
'start with Bearer',
status_code=HTTP_UNAUTHORIZED)
elif len(parts) != 2:
if len(parts) != 2:
return self.json_message('Authorization header must '
'be Bearer token',
status_code=HTTP_UNAUTHORIZED)

View file

@ -95,7 +95,7 @@ class RestNotificationService(BaseNotificationService):
"""Recursive template creator helper function."""
if isinstance(value, list):
return [_data_template_creator(item) for item in value]
elif isinstance(value, dict):
if isinstance(value, dict):
return {key: _data_template_creator(item)
for key, item in value.items()}
value.hass = self._hass

View file

@ -73,7 +73,7 @@ class TelegramNotificationService(BaseNotificationService):
self.hass.services.call(
DOMAIN, 'send_photo', service_data=service_data)
return
elif data is not None and ATTR_VIDEO in data:
if data is not None and ATTR_VIDEO in data:
videos = data.get(ATTR_VIDEO, None)
videos = videos if isinstance(videos, list) else [videos]
for video_data in videos:
@ -81,11 +81,11 @@ class TelegramNotificationService(BaseNotificationService):
self.hass.services.call(
DOMAIN, 'send_video', service_data=service_data)
return
elif data is not None and ATTR_LOCATION in data:
if data is not None and ATTR_LOCATION in data:
service_data.update(data.get(ATTR_LOCATION))
return self.hass.services.call(
DOMAIN, 'send_location', service_data=service_data)
elif data is not None and ATTR_DOCUMENT in data:
if data is not None and ATTR_DOCUMENT in data:
service_data.update(data.get(ATTR_DOCUMENT))
return self.hass.services.call(
DOMAIN, 'send_document', service_data=service_data)

View file

@ -194,9 +194,9 @@ class TwitterNotificationService(BaseNotificationService):
if media_type.startswith('image/gif'):
return 'tweet_gif'
elif media_type.startswith('video/'):
if media_type.startswith('video/'):
return 'tweet_video'
elif media_type.startswith('image/'):
if media_type.startswith('image/'):
return 'tweet_image'
return None

View file

@ -154,7 +154,7 @@ def get_value_from_json(json_dict, sensor_type, group, tool):
return 0
return json_dict[group][sensor_type]
elif tool is not None:
if tool is not None:
if sensor_type in json_dict[group][tool]:
return json_dict[group][tool][sensor_type]

View file

@ -122,8 +122,7 @@ def setup(hass, config) -> bool:
_LOGGER.error("No Rachio devices found in account %s",
person.username)
return False
else:
_LOGGER.info("%d Rachio device(s) found", len(person.controllers))
_LOGGER.info("%d Rachio device(s) found", len(person.controllers))
# Enable component
hass.data[DOMAIN] = person

View file

@ -284,7 +284,7 @@ class Recorder(threading.Thread):
self._close_connection()
self.queue.task_done()
return
elif isinstance(event, PurgeTask):
if isinstance(event, PurgeTask):
purge.purge_old_data(self, event.keep_days, event.repack)
self.queue.task_done()
continue

View file

@ -168,7 +168,7 @@ def _process_timestamp(ts):
"""Process a timestamp into datetime object."""
if ts is None:
return None
elif ts.tzinfo is None:
if ts.tzinfo is None:
return dt_util.UTC.localize(ts)
return dt_util.as_utc(ts)

View file

@ -100,7 +100,7 @@ def identify_event_type(event):
"""
if EVENT_KEY_COMMAND in event:
return EVENT_KEY_COMMAND
elif EVENT_KEY_SENSOR in event:
if EVENT_KEY_SENSOR in event:
return EVENT_KEY_SENSOR
return 'unknown'

View file

@ -58,7 +58,7 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
devices.append(LifxCloudScene(hass, headers, timeout, scene))
async_add_devices(devices)
return True
elif status == 401:
if status == 401:
_LOGGER.error("Unauthorized (bad token?) on %s", url)
return False

View file

@ -67,9 +67,9 @@ class AbodeSensor(AbodeDevice):
"""Return the state of the sensor."""
if self._sensor_type == 'temp':
return self._device.temp
elif self._sensor_type == 'humidity':
if self._sensor_type == 'humidity':
return self._device.humidity
elif self._sensor_type == 'lux':
if self._sensor_type == 'lux':
return self._device.lux
@property
@ -77,7 +77,7 @@ class AbodeSensor(AbodeDevice):
"""Return the units of measurement."""
if self._sensor_type == 'temp':
return self._device.temp_unit
elif self._sensor_type == 'humidity':
if self._sensor_type == 'humidity':
return self._device.humidity_unit
elif self._sensor_type == 'lux':
if self._sensor_type == 'lux':
return self._device.lux_unit

View file

@ -38,9 +38,9 @@ class StreamHandler(logging.Handler):
else:
if not record.msg.startswith('WS'):
return
elif len(record.args) < 2:
if len(record.args) < 2:
return
elif record.args[1] == 'Connected':
if record.args[1] == 'Connected':
self.entity.count += 1
elif record.args[1] == 'Closed connection':
self.entity.count -= 1

View file

@ -123,7 +123,7 @@ class ArloSensor(Entity):
"""Return the device class of the sensor."""
if self._sensor_type == 'temperature':
return DEVICE_CLASS_TEMPERATURE
elif self._sensor_type == 'humidity':
if self._sensor_type == 'humidity':
return DEVICE_CLASS_HUMIDITY
return None

View file

@ -262,13 +262,13 @@ class BrSensor(Entity):
self._entity_picture = img
return True
return False
else:
try:
self._state = data.get(FORECAST)[fcday].get(self.type[:-3])
return True
except IndexError:
_LOGGER.warning("No forecast for fcday=%s...", fcday)
return False
try:
self._state = data.get(FORECAST)[fcday].get(self.type[:-3])
return True
except IndexError:
_LOGGER.warning("No forecast for fcday=%s...", fcday)
return False
if self.type == SYMBOL or self.type.startswith(CONDITION):
# update weather symbol & status text

Some files were not shown because too many files have changed in this diff Show more