mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 22:37:11 +00:00
Remove unnecessary try-else (3) (#86160)
This commit is contained in:
parent
bc115634d1
commit
141acba40d
@ -145,8 +145,8 @@ class DataUpdateCoordinatorMixin:
|
|||||||
await client.set_setting_values(module_id, value)
|
await client.set_setting_values(module_id, value)
|
||||||
except ApiException:
|
except ApiException:
|
||||||
return False
|
return False
|
||||||
else:
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class PlenticoreUpdateCoordinator(DataUpdateCoordinator[_DataT]):
|
class PlenticoreUpdateCoordinator(DataUpdateCoordinator[_DataT]):
|
||||||
|
@ -140,18 +140,16 @@ class MediaExtractor:
|
|||||||
except MEQueryException:
|
except MEQueryException:
|
||||||
_LOGGER.error("Wrong query format: %s", stream_query)
|
_LOGGER.error("Wrong query format: %s", stream_query)
|
||||||
return
|
return
|
||||||
else:
|
|
||||||
data = {k: v for k, v in self.call_data.items() if k != ATTR_ENTITY_ID}
|
|
||||||
data[ATTR_MEDIA_CONTENT_ID] = stream_url
|
|
||||||
|
|
||||||
if entity_id:
|
data = {k: v for k, v in self.call_data.items() if k != ATTR_ENTITY_ID}
|
||||||
data[ATTR_ENTITY_ID] = entity_id
|
data[ATTR_MEDIA_CONTENT_ID] = stream_url
|
||||||
|
|
||||||
self.hass.async_create_task(
|
if entity_id:
|
||||||
self.hass.services.async_call(
|
data[ATTR_ENTITY_ID] = entity_id
|
||||||
MEDIA_PLAYER_DOMAIN, SERVICE_PLAY_MEDIA, data
|
|
||||||
)
|
self.hass.async_create_task(
|
||||||
)
|
self.hass.services.async_call(MEDIA_PLAYER_DOMAIN, SERVICE_PLAY_MEDIA, data)
|
||||||
|
)
|
||||||
|
|
||||||
def get_stream_query_for_entity(self, entity_id):
|
def get_stream_query_for_entity(self, entity_id):
|
||||||
"""Get stream format query for entity."""
|
"""Get stream format query for entity."""
|
||||||
|
@ -35,18 +35,18 @@ def fetch_data(connection: datapoint.Manager, site: Site, mode: str) -> MetOffic
|
|||||||
except (ValueError, datapoint.exceptions.APIException) as err:
|
except (ValueError, datapoint.exceptions.APIException) as err:
|
||||||
_LOGGER.error("Check Met Office connection: %s", err.args)
|
_LOGGER.error("Check Met Office connection: %s", err.args)
|
||||||
raise UpdateFailed from err
|
raise UpdateFailed from err
|
||||||
else:
|
|
||||||
time_now = utcnow()
|
time_now = utcnow()
|
||||||
return MetOfficeData(
|
return MetOfficeData(
|
||||||
now=forecast.now(),
|
now=forecast.now(),
|
||||||
forecast=[
|
forecast=[
|
||||||
timestep
|
timestep
|
||||||
for day in forecast.days
|
for day in forecast.days
|
||||||
for timestep in day.timesteps
|
for timestep in day.timesteps
|
||||||
if timestep.date > time_now
|
if timestep.date > time_now
|
||||||
and (
|
and (
|
||||||
mode == MODE_3HOURLY or timestep.date.hour > 6
|
mode == MODE_3HOURLY or timestep.date.hour > 6
|
||||||
) # ensures only one result per day in MODE_DAILY
|
) # ensures only one result per day in MODE_DAILY
|
||||||
],
|
],
|
||||||
site=site,
|
site=site,
|
||||||
)
|
)
|
||||||
|
@ -371,10 +371,10 @@ class ModbusHub:
|
|||||||
except ModbusException as exception_error:
|
except ModbusException as exception_error:
|
||||||
self._log_error(str(exception_error), error_state=False)
|
self._log_error(str(exception_error), error_state=False)
|
||||||
return False
|
return False
|
||||||
else:
|
|
||||||
message = f"modbus {self.name} communication open"
|
message = f"modbus {self.name} communication open"
|
||||||
_LOGGER.info(message)
|
_LOGGER.info(message)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _pymodbus_call(
|
def _pymodbus_call(
|
||||||
self, unit: int | None, address: int, value: int | list[int], use_call: str
|
self, unit: int | None, address: int, value: int | list[int], use_call: str
|
||||||
|
@ -111,5 +111,5 @@ class PhoneModemFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
await api.test(dev_path)
|
await api.test(dev_path)
|
||||||
except EXCEPTIONS:
|
except EXCEPTIONS:
|
||||||
return {"base": "cannot_connect"}
|
return {"base": "cannot_connect"}
|
||||||
else:
|
|
||||||
return None
|
return None
|
||||||
|
@ -71,8 +71,8 @@ class DataUpdateCoordinatorMotionBlinds(DataUpdateCoordinator):
|
|||||||
except (timeout, ParseException):
|
except (timeout, ParseException):
|
||||||
# let the error be logged and handled by the motionblinds library
|
# let the error be logged and handled by the motionblinds library
|
||||||
return {ATTR_AVAILABLE: False}
|
return {ATTR_AVAILABLE: False}
|
||||||
else:
|
|
||||||
return {ATTR_AVAILABLE: True}
|
return {ATTR_AVAILABLE: True}
|
||||||
|
|
||||||
def update_blind(self, blind):
|
def update_blind(self, blind):
|
||||||
"""Fetch data from a blind."""
|
"""Fetch data from a blind."""
|
||||||
@ -84,8 +84,8 @@ class DataUpdateCoordinatorMotionBlinds(DataUpdateCoordinator):
|
|||||||
except (timeout, ParseException):
|
except (timeout, ParseException):
|
||||||
# let the error be logged and handled by the motionblinds library
|
# let the error be logged and handled by the motionblinds library
|
||||||
return {ATTR_AVAILABLE: False}
|
return {ATTR_AVAILABLE: False}
|
||||||
else:
|
|
||||||
return {ATTR_AVAILABLE: True}
|
return {ATTR_AVAILABLE: True}
|
||||||
|
|
||||||
async def _async_update_data(self):
|
async def _async_update_data(self):
|
||||||
"""Fetch the latest data from the gateway and blinds."""
|
"""Fetch the latest data from the gateway and blinds."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user