mirror of
https://github.com/home-assistant/core
synced 2024-09-28 03:04:04 +02:00
Remove device tracker unnecessary separate except clause (#24081)
Handle exception where it can be thrown.
This commit is contained in:
parent
02f927ae2d
commit
9d7aa8f05d
@ -478,29 +478,27 @@ async def async_load_config(path: str, hass: HomeAssistantType,
|
|||||||
vol.Optional(CONF_CONSIDER_HOME, default=consider_home): vol.All(
|
vol.Optional(CONF_CONSIDER_HOME, default=consider_home): vol.All(
|
||||||
cv.time_period, cv.positive_timedelta),
|
cv.time_period, cv.positive_timedelta),
|
||||||
})
|
})
|
||||||
|
result = []
|
||||||
try:
|
try:
|
||||||
result = []
|
devices = await hass.async_add_job(
|
||||||
try:
|
load_yaml_config_file, path)
|
||||||
devices = await hass.async_add_job(
|
except HomeAssistantError as err:
|
||||||
load_yaml_config_file, path)
|
LOGGER.error("Unable to load %s: %s", path, str(err))
|
||||||
except HomeAssistantError as err:
|
|
||||||
LOGGER.error("Unable to load %s: %s", path, str(err))
|
|
||||||
return []
|
|
||||||
|
|
||||||
for dev_id, device in devices.items():
|
|
||||||
# Deprecated option. We just ignore it to avoid breaking change
|
|
||||||
device.pop('vendor', None)
|
|
||||||
try:
|
|
||||||
device = dev_schema(device)
|
|
||||||
device['dev_id'] = cv.slugify(dev_id)
|
|
||||||
except vol.Invalid as exp:
|
|
||||||
async_log_exception(exp, dev_id, devices, hass)
|
|
||||||
else:
|
|
||||||
result.append(Device(hass, **device))
|
|
||||||
return result
|
|
||||||
except (HomeAssistantError, FileNotFoundError):
|
|
||||||
# When YAML file could not be loaded/did not contain a dict
|
|
||||||
return []
|
return []
|
||||||
|
except FileNotFoundError:
|
||||||
|
return []
|
||||||
|
|
||||||
|
for dev_id, device in devices.items():
|
||||||
|
# Deprecated option. We just ignore it to avoid breaking change
|
||||||
|
device.pop('vendor', None)
|
||||||
|
try:
|
||||||
|
device = dev_schema(device)
|
||||||
|
device['dev_id'] = cv.slugify(dev_id)
|
||||||
|
except vol.Invalid as exp:
|
||||||
|
async_log_exception(exp, dev_id, devices, hass)
|
||||||
|
else:
|
||||||
|
result.append(Device(hass, **device))
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def update_config(path: str, dev_id: str, device: Device):
|
def update_config(path: str, dev_id: str, device: Device):
|
||||||
|
Loading…
Reference in New Issue
Block a user