Merge of nested IF-IF cases - H-J (#48368)

pull/48400/head
Franck Nijhof 2021-03-27 11:30:29 +01:00 committed by GitHub
parent db355f9b23
commit 786023fce4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 81 additions and 78 deletions

View File

@ -258,9 +258,8 @@ class HERETravelTimeSensor(SensorEntity):
@property @property
def state(self) -> str | None: def state(self) -> str | None:
"""Return the state of the sensor.""" """Return the state of the sensor."""
if self._here_data.traffic_mode: if self._here_data.traffic_mode and self._here_data.traffic_time is not None:
if self._here_data.traffic_time is not None: return str(round(self._here_data.traffic_time / 60))
return str(round(self._here_data.traffic_time / 60))
if self._here_data.base_time is not None: if self._here_data.base_time is not None:
return str(round(self._here_data.base_time / 60)) return str(round(self._here_data.base_time / 60))

View File

@ -74,10 +74,9 @@ class HitronCODADeviceScanner(DeviceScanner):
def get_device_name(self, device): def get_device_name(self, device):
"""Return the name of the device with the given MAC address.""" """Return the name of the device with the given MAC address."""
name = next( return next(
(result.name for result in self.last_results if result.mac == device), None (result.name for result in self.last_results if result.mac == device), None
) )
return name
def _login(self): def _login(self):
"""Log in to the router. This is required for subsequent api calls.""" """Log in to the router. This is required for subsequent api calls."""
@ -103,10 +102,9 @@ class HitronCODADeviceScanner(DeviceScanner):
"""Get ARP from router.""" """Get ARP from router."""
_LOGGER.info("Fetching") _LOGGER.info("Fetching")
if self._userid is None: if self._userid is None and not self._login():
if not self._login(): _LOGGER.error("Could not obtain a user ID from the router")
_LOGGER.error("Could not obtain a user ID from the router") return False
return False
last_results = [] last_results = []
# doing a request # doing a request

View File

@ -99,9 +99,11 @@ def enumerate_stateless_switch(service):
# A stateless switch that has a SERVICE_LABEL_INDEX is part of a group # A stateless switch that has a SERVICE_LABEL_INDEX is part of a group
# And is handled separately # And is handled separately
if service.has(CharacteristicsTypes.SERVICE_LABEL_INDEX): if (
if len(service.linked) > 0: service.has(CharacteristicsTypes.SERVICE_LABEL_INDEX)
return [] and len(service.linked) > 0
):
return []
char = service[CharacteristicsTypes.INPUT_EVENT] char = service[CharacteristicsTypes.INPUT_EVENT]
@ -109,17 +111,15 @@ def enumerate_stateless_switch(service):
# manufacturer might not - clamp options to what they say. # manufacturer might not - clamp options to what they say.
all_values = clamp_enum_to_char(InputEventValues, char) all_values = clamp_enum_to_char(InputEventValues, char)
results = [] return [
for event_type in all_values: {
results.append( "characteristic": char.iid,
{ "value": event_type,
"characteristic": char.iid, "type": "button1",
"value": event_type, "subtype": HK_TO_HA_INPUT_EVENT_VALUES[event_type],
"type": "button1", }
"subtype": HK_TO_HA_INPUT_EVENT_VALUES[event_type], for event_type in all_values
} ]
)
return results
def enumerate_stateless_switch_group(service): def enumerate_stateless_switch_group(service):
@ -234,20 +234,16 @@ async def async_get_triggers(hass: HomeAssistant, device_id: str) -> list[dict]:
device = hass.data[TRIGGERS][device_id] device = hass.data[TRIGGERS][device_id]
triggers = [] return [
{
for trigger, subtype in device.async_get_triggers(): CONF_PLATFORM: "device",
triggers.append( CONF_DEVICE_ID: device_id,
{ CONF_DOMAIN: DOMAIN,
CONF_PLATFORM: "device", CONF_TYPE: trigger,
CONF_DEVICE_ID: device_id, CONF_SUBTYPE: subtype,
CONF_DOMAIN: DOMAIN, }
CONF_TYPE: trigger, for trigger, subtype in device.async_get_triggers()
CONF_SUBTYPE: subtype, ]
}
)
return triggers
async def async_attach_trigger( async def async_attach_trigger(

View File

@ -93,9 +93,11 @@ class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity):
if TargetMediaStateValues.STOP in self.supported_media_states: if TargetMediaStateValues.STOP in self.supported_media_states:
features |= SUPPORT_STOP features |= SUPPORT_STOP
if self.service.has(CharacteristicsTypes.REMOTE_KEY): if (
if RemoteKeyValues.PLAY_PAUSE in self.supported_remote_keys: self.service.has(CharacteristicsTypes.REMOTE_KEY)
features |= SUPPORT_PAUSE | SUPPORT_PLAY and RemoteKeyValues.PLAY_PAUSE in self.supported_remote_keys
):
features |= SUPPORT_PAUSE | SUPPORT_PLAY
return features return features

View File

@ -229,7 +229,7 @@ async def async_safe_fetch(bridge, fetch_method):
except aiohue.Unauthorized as err: except aiohue.Unauthorized as err:
await bridge.handle_unauthorized_error() await bridge.handle_unauthorized_error()
raise UpdateFailed("Unauthorized") from err raise UpdateFailed("Unauthorized") from err
except (aiohue.AiohueException,) as err: except aiohue.AiohueException as err:
raise UpdateFailed(f"Hue error: {err}") from err raise UpdateFailed(f"Hue error: {err}") from err
@ -297,12 +297,11 @@ class HueLight(CoordinatorEntity, LightEntity):
"bulb in the Philips Hue App." "bulb in the Philips Hue App."
) )
_LOGGER.warning(err, self.name) _LOGGER.warning(err, self.name)
if self.gamut: if self.gamut and not color.check_valid_gamut(self.gamut):
if not color.check_valid_gamut(self.gamut): err = "Color gamut of %s: %s, not valid, setting gamut to None."
err = "Color gamut of %s: %s, not valid, setting gamut to None." _LOGGER.warning(err, self.name, str(self.gamut))
_LOGGER.warning(err, self.name, str(self.gamut)) self.gamut_typ = GAMUT_TYPE_UNAVAILABLE
self.gamut_typ = GAMUT_TYPE_UNAVAILABLE self.gamut = None
self.gamut = None
@property @property
def unique_id(self): def unique_id(self):

View File

@ -241,8 +241,9 @@ class HyperionBaseLight(LightEntity):
if ATTR_BRIGHTNESS in kwargs: if ATTR_BRIGHTNESS in kwargs:
brightness = kwargs[ATTR_BRIGHTNESS] brightness = kwargs[ATTR_BRIGHTNESS]
for item in self._client.adjustment or []: for item in self._client.adjustment or []:
if const.KEY_ID in item: if (
if not await self._client.async_send_set_adjustment( const.KEY_ID in item
and not await self._client.async_send_set_adjustment(
**{ **{
const.KEY_ADJUSTMENT: { const.KEY_ADJUSTMENT: {
const.KEY_BRIGHTNESS: int( const.KEY_BRIGHTNESS: int(
@ -251,8 +252,9 @@ class HyperionBaseLight(LightEntity):
const.KEY_ID: item[const.KEY_ID], const.KEY_ID: item[const.KEY_ID],
} }
} }
): )
return ):
return
# == Set an external source # == Set an external source
if ( if (

View File

@ -208,9 +208,12 @@ class ImageProcessingFaceEntity(ImageProcessingEntity):
""" """
# Send events # Send events
for face in faces: for face in faces:
if ATTR_CONFIDENCE in face and self.confidence: if (
if face[ATTR_CONFIDENCE] < self.confidence: ATTR_CONFIDENCE in face
continue and self.confidence
and face[ATTR_CONFIDENCE] < self.confidence
):
continue
face.update({ATTR_ENTITY_ID: self.entity_id}) face.update({ATTR_ENTITY_ID: self.entity_id})
self.hass.async_add_job(self.hass.bus.async_fire, EVENT_DETECT_FACE, face) self.hass.async_add_job(self.hass.bus.async_fire, EVENT_DETECT_FACE, face)

View File

@ -220,9 +220,11 @@ class EmailContentSensor(SensorEntity):
elif part.get_content_type() == "text/html": elif part.get_content_type() == "text/html":
if message_html is None: if message_html is None:
message_html = part.get_payload() message_html = part.get_payload()
elif part.get_content_type().startswith("text"): elif (
if message_untyped_text is None: part.get_content_type().startswith("text")
message_untyped_text = part.get_payload() and message_untyped_text is None
):
message_untyped_text = part.get_payload()
if message_text is not None: if message_text is not None:
return message_text return message_text

View File

@ -69,10 +69,12 @@ class iOSNotificationService(BaseNotificationService):
"""Send a message to the Lambda APNS gateway.""" """Send a message to the Lambda APNS gateway."""
data = {ATTR_MESSAGE: message} data = {ATTR_MESSAGE: message}
if kwargs.get(ATTR_TITLE) is not None: # Remove default title from notifications.
# Remove default title from notifications. if (
if kwargs.get(ATTR_TITLE) != ATTR_TITLE_DEFAULT: kwargs.get(ATTR_TITLE) is not None
data[ATTR_TITLE] = kwargs.get(ATTR_TITLE) and kwargs.get(ATTR_TITLE) != ATTR_TITLE_DEFAULT
):
data[ATTR_TITLE] = kwargs.get(ATTR_TITLE)
targets = kwargs.get(ATTR_TARGET) targets = kwargs.get(ATTR_TARGET)

View File

@ -281,15 +281,17 @@ class ISYInsteonBinarySensorEntity(ISYBinarySensorEntity):
""" """
self._negative_node = child self._negative_node = child
if self._negative_node.status != ISY_VALUE_UNKNOWN: # If the negative node has a value, it means the negative node is
# If the negative node has a value, it means the negative node is # in use for this device. Next we need to check to see if the
# in use for this device. Next we need to check to see if the # negative and positive nodes disagree on the state (both ON or
# negative and positive nodes disagree on the state (both ON or # both OFF).
# both OFF). if (
if self._negative_node.status == self._node.status: self._negative_node.status != ISY_VALUE_UNKNOWN
# The states disagree, therefore we cannot determine the state and self._negative_node.status == self._node.status
# of the sensor until we receive our first ON event. ):
self._computed_state = None # The states disagree, therefore we cannot determine the state
# of the sensor until we receive our first ON event.
self._computed_state = None
def _negative_node_control_handler(self, event: object) -> None: def _negative_node_control_handler(self, event: object) -> None:
"""Handle an "On" control event from the "negative" node.""" """Handle an "On" control event from the "negative" node."""

View File

@ -121,10 +121,9 @@ def setup(hass, config):
device_names = device.get(CONF_DEVICE_NAMES) device_names = device.get(CONF_DEVICE_NAMES)
name = device.get(CONF_NAME) name = device.get(CONF_NAME)
name = f"{name.lower().replace(' ', '_')}_" if name else "" name = f"{name.lower().replace(' ', '_')}_" if name else ""
if api_key: if api_key and not get_devices(api_key):
if not get_devices(api_key): _LOGGER.error("Error connecting to Join, check API key")
_LOGGER.error("Error connecting to Join, check API key") return False
return False
if device_id is None and device_ids is None and device_names is None: if device_id is None and device_ids is None and device_names is None:
_LOGGER.error( _LOGGER.error(
"No device was provided. Please specify device_id" "No device was provided. Please specify device_id"

View File

@ -35,10 +35,9 @@ def get_service(hass, config, discovery_info=None):
device_id = config.get(CONF_DEVICE_ID) device_id = config.get(CONF_DEVICE_ID)
device_ids = config.get(CONF_DEVICE_IDS) device_ids = config.get(CONF_DEVICE_IDS)
device_names = config.get(CONF_DEVICE_NAMES) device_names = config.get(CONF_DEVICE_NAMES)
if api_key: if api_key and not get_devices(api_key):
if not get_devices(api_key): _LOGGER.error("Error connecting to Join. Check the API key")
_LOGGER.error("Error connecting to Join. Check the API key") return False
return False
if device_id is None and device_ids is None and device_names is None: if device_id is None and device_ids is None and device_names is None:
_LOGGER.error( _LOGGER.error(
"No device was provided. Please specify device_id" "No device was provided. Please specify device_id"