Remove unnecessary try-else (2) (#86159)

This commit is contained in:
Marc Mueller 2023-01-18 14:25:09 +01:00 committed by GitHub
parent 1cc8feabb7
commit bc115634d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 39 additions and 41 deletions

View File

@ -78,8 +78,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
raise ConfigEntryNotReady(
f"Could not obtain serial number from envoy: {ex}"
) from ex
else:
hass.config_entries.async_update_entry(entry, unique_id=serial)
hass.config_entries.async_update_entry(entry, unique_id=serial)
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {
COORDINATOR: coordinator,

View File

@ -65,9 +65,8 @@ async def async_setup_platform(
except pyeverlights.ConnectionError as err:
raise PlatformNotReady from err
else:
lights.append(EverLightsLight(api, pyeverlights.ZONE_1, status, effects))
lights.append(EverLightsLight(api, pyeverlights.ZONE_2, status, effects))
lights.append(EverLightsLight(api, pyeverlights.ZONE_1, status, effects))
lights.append(EverLightsLight(api, pyeverlights.ZONE_2, status, effects))
async_add_entities(lights)

View File

@ -155,16 +155,16 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
device = await self._async_try_connect(host, device)
except FLUX_LED_EXCEPTIONS:
return self.async_abort(reason="cannot_connect")
else:
discovered_mac = device[ATTR_ID]
if device[ATTR_MODEL_DESCRIPTION] or (
discovered_mac is not None
and (formatted_discovered_mac := dr.format_mac(discovered_mac))
and formatted_discovered_mac != mac
and mac_matches_by_one(discovered_mac, mac)
):
self._discovered_device = device
await self._async_set_discovered_mac(device, True)
discovered_mac = device[ATTR_ID]
if device[ATTR_MODEL_DESCRIPTION] or (
discovered_mac is not None
and (formatted_discovered_mac := dr.format_mac(discovered_mac))
and formatted_discovered_mac != mac
and mac_matches_by_one(discovered_mac, mac)
):
self._discovered_device = device
await self._async_set_discovered_mac(device, True)
return await self.async_step_discovery_confirm()
async def async_step_discovery_confirm(

View File

@ -275,5 +275,5 @@ class HarmonyData(HarmonySubscriberMixin):
except aioexc.TimeOut:
_LOGGER.error("%s: Syncing hub with Harmony cloud timed-out", self.name)
return False
else:
return True
return True

View File

@ -167,8 +167,8 @@ class SupervisorAddonUpdateEntity(HassioAddonEntity, UpdateEntity):
await async_update_addon(self.hass, slug=self._addon_slug, backup=backup)
except HassioAPIError as err:
raise HomeAssistantError(f"Error updating {self.title}: {err}") from err
else:
await self.coordinator.force_info_update_supervisor()
await self.coordinator.force_info_update_supervisor()
class SupervisorOSUpdateEntity(HassioOSEntity, UpdateEntity):

View File

@ -44,6 +44,7 @@ async def validate_input(hass: HomeAssistant, user_input):
client = await connect_client(hass, user_input)
except asyncio.TimeoutError as err:
raise CannotConnect from err
try:
def disconnect_callback():
@ -56,9 +57,9 @@ async def validate_input(hass: HomeAssistant, user_input):
client.disconnect_callback = None
client.stop()
raise
else:
client.disconnect_callback = None
client.stop()
client.disconnect_callback = None
client.stop()
class SW16FlowHandler(config_entries.ConfigFlow, domain=DOMAIN):

View File

@ -580,8 +580,8 @@ class KNXModule:
raise HomeAssistantError(
f"Could not find exposure for '{group_address}' to remove."
) from err
else:
removed_exposure.shutdown()
removed_exposure.shutdown()
return
if group_address in self.service_exposures:

View File

@ -191,11 +191,11 @@ class KonnectedFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
self.data[CONF_ID] = status.get("chipId", status["mac"].replace(":", ""))
except (CannotConnect, KeyError) as err:
raise CannotConnect from err
else:
self.data[CONF_MODEL] = status.get("model", KONN_MODEL)
self.data[CONF_ACCESS_TOKEN] = "".join(
random.choices(f"{string.ascii_uppercase}{string.digits}", k=20)
)
self.data[CONF_MODEL] = status.get("model", KONN_MODEL)
self.data[CONF_ACCESS_TOKEN] = "".join(
random.choices(f"{string.ascii_uppercase}{string.digits}", k=20)
)
async def async_step_import(self, device_config):
"""Import a configuration.yaml config.
@ -282,19 +282,17 @@ class KonnectedFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
status = await get_status(self.hass, netloc[0], int(netloc[1]))
except CannotConnect:
return self.async_abort(reason="cannot_connect")
else:
self.data[CONF_HOST] = netloc[0]
self.data[CONF_PORT] = int(netloc[1])
self.data[CONF_ID] = status.get(
"chipId", status["mac"].replace(":", "")
)
self.data[CONF_MODEL] = status.get("model", KONN_MODEL)
KonnectedFlowHandler.discovered_hosts[self.data[CONF_ID]] = {
CONF_HOST: self.data[CONF_HOST],
CONF_PORT: self.data[CONF_PORT],
}
return await self.async_step_confirm()
self.data[CONF_HOST] = netloc[0]
self.data[CONF_PORT] = int(netloc[1])
self.data[CONF_ID] = status.get("chipId", status["mac"].replace(":", ""))
self.data[CONF_MODEL] = status.get("model", KONN_MODEL)
KonnectedFlowHandler.discovered_hosts[self.data[CONF_ID]] = {
CONF_HOST: self.data[CONF_HOST],
CONF_PORT: self.data[CONF_PORT],
}
return await self.async_step_confirm()
return self.async_abort(reason="unknown")