Skip to content

Commit

Permalink
Removes unnecessary else/elif blocks (#26884)
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck authored and balloob committed Sep 24, 2019
1 parent 18873d2 commit b1118cb
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 42 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/eddystone_temperature/sensor.py
Expand Up @@ -60,8 +60,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
if instance is None or namespace is None:
_LOGGER.error("Skipping %s", dev_name)
continue
else:
devices.append(EddystoneTemp(name, namespace, instance))

devices.append(EddystoneTemp(name, namespace, instance))

if devices:
mon = Monitor(hass, devices, bt_device_id)
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/filesize/sensor.py
Expand Up @@ -27,8 +27,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
if not hass.config.is_allowed_path(path):
_LOGGER.error("Filepath %s is not valid or allowed", path)
continue
else:
sensors.append(Filesize(path))
sensors.append(Filesize(path))

if sensors:
add_entities(sensors, True)
Expand Down
6 changes: 3 additions & 3 deletions homeassistant/components/isy994/__init__.py
Expand Up @@ -323,9 +323,9 @@ def _categorize_nodes(
# determine if it should be a binary_sensor.
if _is_sensor_a_binary_sensor(hass, node):
continue
else:
hass.data[ISY994_NODES]["sensor"].append(node)
continue

hass.data[ISY994_NODES]["sensor"].append(node)
continue

# We have a bunch of different methods for determining the device type,
# each of which works with different ISY firmware versions or device
Expand Down
12 changes: 7 additions & 5 deletions homeassistant/components/mvglive/sensor.py
Expand Up @@ -189,17 +189,19 @@ def update(self):
and _departure["destination"] not in self._destinations
):
continue
elif (

if (
"" not in self._directions[:1]
and _departure["direction"] not in self._directions
):
continue
elif (
"" not in self._lines[:1] and _departure["linename"] not in self._lines
):

if "" not in self._lines[:1] and _departure["linename"] not in self._lines:
continue
elif _departure["time"] < self._timeoffset:

if _departure["time"] < self._timeoffset:
continue

# now select the relevant data
_nextdep = {ATTR_ATTRIBUTION: ATTRIBUTION}
for k in ["destination", "linename", "time", "direction", "product"]:
Expand Down
6 changes: 2 additions & 4 deletions homeassistant/components/onkyo/media_player.py
Expand Up @@ -264,8 +264,7 @@ def update(self):
if source in self._source_mapping:
self._current_source = self._source_mapping[source]
break
else:
self._current_source = "_".join([i for i in current_source_tuples[1]])
self._current_source = "_".join([i for i in current_source_tuples[1]])
if preset_raw and self._current_source.lower() == "radio":
self._attributes[ATTR_PRESET] = preset_raw[1]
elif ATTR_PRESET in self._attributes:
Expand Down Expand Up @@ -414,8 +413,7 @@ def update(self):
if source in self._source_mapping:
self._current_source = self._source_mapping[source]
break
else:
self._current_source = "_".join([i for i in current_source_tuples[1]])
self._current_source = "_".join([i for i in current_source_tuples[1]])
self._muted = bool(mute_raw[1] == "on")
if preset_raw and self._current_source.lower() == "radio":
self._attributes[ATTR_PRESET] = preset_raw[1]
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/recorder/__init__.py
Expand Up @@ -320,10 +320,10 @@ def async_purge(now):
purge.purge_old_data(self, event.keep_days, event.repack)
self.queue.task_done()
continue
elif event.event_type == EVENT_TIME_CHANGED:
if event.event_type == EVENT_TIME_CHANGED:
self.queue.task_done()
continue
elif event.event_type in self.exclude_t:
if event.event_type in self.exclude_t:
self.queue.task_done()
continue

Expand Down
35 changes: 20 additions & 15 deletions homeassistant/components/todoist/calendar.py
Expand Up @@ -484,39 +484,44 @@ def select_best_task(project_tasks):
for proposed_event in project_tasks:
if event == proposed_event:
continue

if proposed_event[COMPLETED]:
# Event is complete!
continue

if proposed_event[END] is None:
# No end time:
if event[END] is None and (proposed_event[PRIORITY] < event[PRIORITY]):
# They also have no end time,
# but we have a higher priority.
event = proposed_event
continue
else:
continue
elif event[END] is None:
continue

if event[END] is None:
# We have an end time, they do not.
event = proposed_event
continue

if proposed_event[END].date() > event[END].date():
# Event is too late.
continue
elif proposed_event[END].date() < event[END].date():

if proposed_event[END].date() < event[END].date():
# Event is earlier than current, select it.
event = proposed_event
continue
else:
if proposed_event[PRIORITY] > event[PRIORITY]:
# Proposed event has a higher priority.
event = proposed_event
continue
elif proposed_event[PRIORITY] == event[PRIORITY] and (
proposed_event[END] < event[END]
):
event = proposed_event
continue

if proposed_event[PRIORITY] > event[PRIORITY]:
# Proposed event has a higher priority.
event = proposed_event
continue

if proposed_event[PRIORITY] == event[PRIORITY] and (
proposed_event[END] < event[END]
):
event = proposed_event
continue

return event

async def async_get_events(self, hass, start_date, end_date):
Expand Down
6 changes: 4 additions & 2 deletions homeassistant/components/webostv/media_player.py
Expand Up @@ -396,10 +396,12 @@ def play_media(self, media_type, media_id, **kwargs):
if media_id == channel["channelNumber"]:
perfect_match_channel_id = channel["channelId"]
continue
elif media_id.lower() == channel["channelName"].lower():

if media_id.lower() == channel["channelName"].lower():
perfect_match_channel_id = channel["channelId"]
continue
elif media_id.lower() in channel["channelName"].lower():

if media_id.lower() in channel["channelName"].lower():
partial_match_channel_id = channel["channelId"]

if perfect_match_channel_id is not None:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/websocket_api/http.py
Expand Up @@ -165,7 +165,7 @@ def handle_hass_stop(event):
if msg.type in (WSMsgType.CLOSE, WSMsgType.CLOSING):
break

elif msg.type != WSMsgType.TEXT:
if msg.type != WSMsgType.TEXT:
disconnect_warn = "Received non-Text message."
break

Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/zha/core/discovery.py
Expand Up @@ -199,11 +199,13 @@ def _async_handle_single_cluster_matches(
zha_device.is_mains_powered or matched_power_configuration
):
continue
elif (

if (
cluster.cluster_id == PowerConfiguration.cluster_id
and not zha_device.is_mains_powered
):
matched_power_configuration = True

cluster_match_results.append(
_async_handle_single_cluster_match(
hass,
Expand Down
7 changes: 4 additions & 3 deletions homeassistant/components/zwave/__init__.py
Expand Up @@ -851,7 +851,8 @@ async def _check_awaked():
# Need to be in STATE_AWAKED before talking to nodes.
_LOGGER.info("Z-Wave ready after %d seconds", waited)
break
elif waited >= const.NETWORK_READY_WAIT_SECS:

if waited >= const.NETWORK_READY_WAIT_SECS:
# Wait up to NETWORK_READY_WAIT_SECS seconds for the Z-Wave
# network to be ready.
_LOGGER.warning(
Expand All @@ -861,8 +862,8 @@ async def _check_awaked():
"final network state: %d %s", network.state, network.state_str
)
break
else:
await asyncio.sleep(1)

await asyncio.sleep(1)

hass.async_add_job(_finalize_start)

Expand Down
3 changes: 2 additions & 1 deletion homeassistant/helpers/__init__.py
Expand Up @@ -19,7 +19,8 @@ def config_per_platform(config: ConfigType, domain: str) -> Iterable[Tuple[Any,

if not platform_config:
continue
elif not isinstance(platform_config, list):

if not isinstance(platform_config, list):
platform_config = [platform_config]

for item in platform_config:
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/scripts/__init__.py
Expand Up @@ -23,7 +23,8 @@ def run(args: List) -> int:
for fil in os.listdir(path):
if fil == "__pycache__":
continue
elif os.path.isdir(os.path.join(path, fil)):

if os.path.isdir(os.path.join(path, fil)):
scripts.append(fil)
elif fil != "__init__.py" and fil.endswith(".py"):
scripts.append(fil[:-3])
Expand Down

0 comments on commit b1118cb

Please sign in to comment.