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) _LOGGER.debug("%s reacquired", self._name)
self._removed = False self._removed = False
except AgentError: except AgentError:
if self.device.client.is_available: # server still available - camera error # server still available - camera error
if not self._removed: if self.device.client.is_available and not self._removed:
_LOGGER.error("%s lost", self._name) _LOGGER.error("%s lost", self._name)
self._removed = True self._removed = True
@property @property
def extra_state_attributes(self): 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_path = entry.data.get(CONF_DEVICE_PATH)
entry_baud = entry.data.get(CONF_DEVICE_BAUD) entry_baud = entry.data.get(CONF_DEVICE_BAUD)
if protocol == PROTOCOL_SOCKET: if (
if user_host == entry_host and user_port == entry_port: protocol == PROTOCOL_SOCKET
return True and user_host == entry_host
and user_port == entry_port
):
return True
if protocol == PROTOCOL_SERIAL: if (
if user_baud == entry_baud and user_path == entry_path: protocol == PROTOCOL_SERIAL
return True and user_baud == entry_baud
and user_path == entry_path
):
return True
return False return False

View File

@ -653,10 +653,9 @@ def temperature_from_object(hass, temp_obj, interval=False):
if temp_obj["scale"] == "FAHRENHEIT": if temp_obj["scale"] == "FAHRENHEIT":
from_unit = TEMP_FAHRENHEIT from_unit = TEMP_FAHRENHEIT
elif temp_obj["scale"] == "KELVIN": elif temp_obj["scale"] == "KELVIN" and not interval:
# convert to Celsius if absolute temperature # convert to Celsius if absolute temperature
if not interval: temp -= 273.15
temp -= 273.15
return convert_temperature(temp, from_unit, to_unit, interval) 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") _LOGGER.error("Invalid Apprise config url provided")
return None return None
if config.get(CONF_URL): # Ordered list of URLs
# Ordered list of URLs if config.get(CONF_URL) and not a_obj.add(config[CONF_URL]):
if not a_obj.add(config[CONF_URL]): _LOGGER.error("Invalid Apprise URL(s) supplied")
_LOGGER.error("Invalid Apprise URL(s) supplied") return None
return None
return AppriseNotificationService(a_obj) return AppriseNotificationService(a_obj)

View File

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

View File

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

View File

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