Merge of nested IF-IF cases - A-C (#48365)

This commit is contained in:
Franck Nijhof 2021-03-27 10:58:38 +01:00 committed by GitHub
parent 8d5ce53098
commit db355f9b23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 32 deletions

View file

@ -102,10 +102,10 @@ class AgentCamera(MjpegCamera):
_LOGGER.debug("%s reacquired", self._name)
self._removed = False
except AgentError:
if self.device.client.is_available: # server still available - camera error
if not self._removed:
_LOGGER.error("%s lost", self._name)
self._removed = True
# server still available - camera error
if self.device.client.is_available and not self._removed:
_LOGGER.error("%s lost", self._name)
self._removed = True
@property
def extra_state_attributes(self):

View file

@ -349,12 +349,18 @@ def _device_already_added(current_entries, user_input, protocol):
entry_path = entry.data.get(CONF_DEVICE_PATH)
entry_baud = entry.data.get(CONF_DEVICE_BAUD)
if protocol == PROTOCOL_SOCKET:
if user_host == entry_host and user_port == entry_port:
return True
if (
protocol == PROTOCOL_SOCKET
and user_host == entry_host
and user_port == entry_port
):
return True
if protocol == PROTOCOL_SERIAL:
if user_baud == entry_baud and user_path == entry_path:
return True
if (
protocol == PROTOCOL_SERIAL
and user_baud == entry_baud
and user_path == entry_path
):
return True
return False

View file

@ -653,10 +653,9 @@ def temperature_from_object(hass, temp_obj, interval=False):
if temp_obj["scale"] == "FAHRENHEIT":
from_unit = TEMP_FAHRENHEIT
elif temp_obj["scale"] == "KELVIN":
elif temp_obj["scale"] == "KELVIN" and not interval:
# convert to Celsius if absolute temperature
if not interval:
temp -= 273.15
temp -= 273.15
return convert_temperature(temp, from_unit, to_unit, interval)

View file

@ -42,11 +42,10 @@ def get_service(hass, config, discovery_info=None):
_LOGGER.error("Invalid Apprise config url provided")
return None
if config.get(CONF_URL):
# Ordered list of URLs
if not a_obj.add(config[CONF_URL]):
_LOGGER.error("Invalid Apprise URL(s) supplied")
return None
# Ordered list of URLs
if config.get(CONF_URL) and not a_obj.add(config[CONF_URL]):
_LOGGER.error("Invalid Apprise URL(s) supplied")
return None
return AppriseNotificationService(a_obj)

View file

@ -341,9 +341,8 @@ class AsusWrtRouter:
async def close(self) -> None:
"""Close the connection."""
if self._api is not None:
if self._protocol == PROTOCOL_TELNET:
self._api.connection.disconnect()
if self._api is not None and self._protocol == PROTOCOL_TELNET:
self._api.connection.disconnect()
self._api = None
for func in self._on_close:

View file

@ -706,15 +706,15 @@ class CastDevice(MediaPlayerEntity):
support = SUPPORT_CAST
media_status = self._media_status()[0]
if self.cast_status:
if self.cast_status.volume_control_type != VOLUME_CONTROL_TYPE_FIXED:
support |= SUPPORT_VOLUME_MUTE | SUPPORT_VOLUME_SET
if (
self.cast_status
and self.cast_status.volume_control_type != VOLUME_CONTROL_TYPE_FIXED
):
support |= SUPPORT_VOLUME_MUTE | SUPPORT_VOLUME_SET
if media_status:
if media_status.supports_queue_next:
support |= SUPPORT_PREVIOUS_TRACK
if media_status.supports_queue_next:
support |= SUPPORT_NEXT_TRACK
support |= SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK
if media_status.supports_seek:
support |= SUPPORT_SEEK

View file

@ -274,13 +274,12 @@ class ClimaCellWeatherEntity(ClimaCellEntity, WeatherEntity):
),
temp_low,
)
elif self.forecast_type == NOWCAST:
elif self.forecast_type == NOWCAST and precipitation:
# Precipitation is forecasted in CONF_TIMESTEP increments but in a
# per hour rate, so value needs to be converted to an amount.
if precipitation:
precipitation = (
precipitation / 60 * self._config_entry.options[CONF_TIMESTEP]
)
precipitation = (
precipitation / 60 * self._config_entry.options[CONF_TIMESTEP]
)
forecasts.append(
_forecast_dict(