Merge of nested IF-IF cases - H-J (#48368)
parent
db355f9b23
commit
786023fce4
|
@ -258,9 +258,8 @@ class HERETravelTimeSensor(SensorEntity):
|
|||
@property
|
||||
def state(self) -> str | None:
|
||||
"""Return the state of the sensor."""
|
||||
if self._here_data.traffic_mode:
|
||||
if self._here_data.traffic_time is not None:
|
||||
return str(round(self._here_data.traffic_time / 60))
|
||||
if self._here_data.traffic_mode and self._here_data.traffic_time is not None:
|
||||
return str(round(self._here_data.traffic_time / 60))
|
||||
if self._here_data.base_time is not None:
|
||||
return str(round(self._here_data.base_time / 60))
|
||||
|
||||
|
|
|
@ -74,10 +74,9 @@ class HitronCODADeviceScanner(DeviceScanner):
|
|||
|
||||
def get_device_name(self, device):
|
||||
"""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
|
||||
)
|
||||
return name
|
||||
|
||||
def _login(self):
|
||||
"""Log in to the router. This is required for subsequent api calls."""
|
||||
|
@ -103,10 +102,9 @@ class HitronCODADeviceScanner(DeviceScanner):
|
|||
"""Get ARP from router."""
|
||||
_LOGGER.info("Fetching")
|
||||
|
||||
if self._userid is None:
|
||||
if not self._login():
|
||||
_LOGGER.error("Could not obtain a user ID from the router")
|
||||
return False
|
||||
if self._userid is None and not self._login():
|
||||
_LOGGER.error("Could not obtain a user ID from the router")
|
||||
return False
|
||||
last_results = []
|
||||
|
||||
# doing a request
|
||||
|
|
|
@ -99,9 +99,11 @@ def enumerate_stateless_switch(service):
|
|||
|
||||
# A stateless switch that has a SERVICE_LABEL_INDEX is part of a group
|
||||
# And is handled separately
|
||||
if service.has(CharacteristicsTypes.SERVICE_LABEL_INDEX):
|
||||
if len(service.linked) > 0:
|
||||
return []
|
||||
if (
|
||||
service.has(CharacteristicsTypes.SERVICE_LABEL_INDEX)
|
||||
and len(service.linked) > 0
|
||||
):
|
||||
return []
|
||||
|
||||
char = service[CharacteristicsTypes.INPUT_EVENT]
|
||||
|
||||
|
@ -109,17 +111,15 @@ def enumerate_stateless_switch(service):
|
|||
# manufacturer might not - clamp options to what they say.
|
||||
all_values = clamp_enum_to_char(InputEventValues, char)
|
||||
|
||||
results = []
|
||||
for event_type in all_values:
|
||||
results.append(
|
||||
{
|
||||
"characteristic": char.iid,
|
||||
"value": event_type,
|
||||
"type": "button1",
|
||||
"subtype": HK_TO_HA_INPUT_EVENT_VALUES[event_type],
|
||||
}
|
||||
)
|
||||
return results
|
||||
return [
|
||||
{
|
||||
"characteristic": char.iid,
|
||||
"value": event_type,
|
||||
"type": "button1",
|
||||
"subtype": HK_TO_HA_INPUT_EVENT_VALUES[event_type],
|
||||
}
|
||||
for event_type in all_values
|
||||
]
|
||||
|
||||
|
||||
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]
|
||||
|
||||
triggers = []
|
||||
|
||||
for trigger, subtype in device.async_get_triggers():
|
||||
triggers.append(
|
||||
{
|
||||
CONF_PLATFORM: "device",
|
||||
CONF_DEVICE_ID: device_id,
|
||||
CONF_DOMAIN: DOMAIN,
|
||||
CONF_TYPE: trigger,
|
||||
CONF_SUBTYPE: subtype,
|
||||
}
|
||||
)
|
||||
|
||||
return triggers
|
||||
return [
|
||||
{
|
||||
CONF_PLATFORM: "device",
|
||||
CONF_DEVICE_ID: device_id,
|
||||
CONF_DOMAIN: DOMAIN,
|
||||
CONF_TYPE: trigger,
|
||||
CONF_SUBTYPE: subtype,
|
||||
}
|
||||
for trigger, subtype in device.async_get_triggers()
|
||||
]
|
||||
|
||||
|
||||
async def async_attach_trigger(
|
||||
|
|
|
@ -93,9 +93,11 @@ class HomeKitTelevision(HomeKitEntity, MediaPlayerEntity):
|
|||
if TargetMediaStateValues.STOP in self.supported_media_states:
|
||||
features |= SUPPORT_STOP
|
||||
|
||||
if self.service.has(CharacteristicsTypes.REMOTE_KEY):
|
||||
if RemoteKeyValues.PLAY_PAUSE in self.supported_remote_keys:
|
||||
features |= SUPPORT_PAUSE | SUPPORT_PLAY
|
||||
if (
|
||||
self.service.has(CharacteristicsTypes.REMOTE_KEY)
|
||||
and RemoteKeyValues.PLAY_PAUSE in self.supported_remote_keys
|
||||
):
|
||||
features |= SUPPORT_PAUSE | SUPPORT_PLAY
|
||||
|
||||
return features
|
||||
|
||||
|
|
|
@ -229,7 +229,7 @@ async def async_safe_fetch(bridge, fetch_method):
|
|||
except aiohue.Unauthorized as err:
|
||||
await bridge.handle_unauthorized_error()
|
||||
raise UpdateFailed("Unauthorized") from err
|
||||
except (aiohue.AiohueException,) as err:
|
||||
except aiohue.AiohueException as err:
|
||||
raise UpdateFailed(f"Hue error: {err}") from err
|
||||
|
||||
|
||||
|
@ -297,12 +297,11 @@ class HueLight(CoordinatorEntity, LightEntity):
|
|||
"bulb in the Philips Hue App."
|
||||
)
|
||||
_LOGGER.warning(err, self.name)
|
||||
if self.gamut:
|
||||
if not color.check_valid_gamut(self.gamut):
|
||||
err = "Color gamut of %s: %s, not valid, setting gamut to None."
|
||||
_LOGGER.warning(err, self.name, str(self.gamut))
|
||||
self.gamut_typ = GAMUT_TYPE_UNAVAILABLE
|
||||
self.gamut = None
|
||||
if self.gamut and not color.check_valid_gamut(self.gamut):
|
||||
err = "Color gamut of %s: %s, not valid, setting gamut to None."
|
||||
_LOGGER.warning(err, self.name, str(self.gamut))
|
||||
self.gamut_typ = GAMUT_TYPE_UNAVAILABLE
|
||||
self.gamut = None
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
|
|
|
@ -241,8 +241,9 @@ class HyperionBaseLight(LightEntity):
|
|||
if ATTR_BRIGHTNESS in kwargs:
|
||||
brightness = kwargs[ATTR_BRIGHTNESS]
|
||||
for item in self._client.adjustment or []:
|
||||
if const.KEY_ID in item:
|
||||
if not await self._client.async_send_set_adjustment(
|
||||
if (
|
||||
const.KEY_ID in item
|
||||
and not await self._client.async_send_set_adjustment(
|
||||
**{
|
||||
const.KEY_ADJUSTMENT: {
|
||||
const.KEY_BRIGHTNESS: int(
|
||||
|
@ -251,8 +252,9 @@ class HyperionBaseLight(LightEntity):
|
|||
const.KEY_ID: item[const.KEY_ID],
|
||||
}
|
||||
}
|
||||
):
|
||||
return
|
||||
)
|
||||
):
|
||||
return
|
||||
|
||||
# == Set an external source
|
||||
if (
|
||||
|
|
|
@ -208,9 +208,12 @@ class ImageProcessingFaceEntity(ImageProcessingEntity):
|
|||
"""
|
||||
# Send events
|
||||
for face in faces:
|
||||
if ATTR_CONFIDENCE in face and self.confidence:
|
||||
if face[ATTR_CONFIDENCE] < self.confidence:
|
||||
continue
|
||||
if (
|
||||
ATTR_CONFIDENCE in face
|
||||
and self.confidence
|
||||
and face[ATTR_CONFIDENCE] < self.confidence
|
||||
):
|
||||
continue
|
||||
|
||||
face.update({ATTR_ENTITY_ID: self.entity_id})
|
||||
self.hass.async_add_job(self.hass.bus.async_fire, EVENT_DETECT_FACE, face)
|
||||
|
|
|
@ -220,9 +220,11 @@ class EmailContentSensor(SensorEntity):
|
|||
elif part.get_content_type() == "text/html":
|
||||
if message_html is None:
|
||||
message_html = part.get_payload()
|
||||
elif part.get_content_type().startswith("text"):
|
||||
if message_untyped_text is None:
|
||||
message_untyped_text = part.get_payload()
|
||||
elif (
|
||||
part.get_content_type().startswith("text")
|
||||
and message_untyped_text is None
|
||||
):
|
||||
message_untyped_text = part.get_payload()
|
||||
|
||||
if message_text is not None:
|
||||
return message_text
|
||||
|
|
|
@ -69,10 +69,12 @@ class iOSNotificationService(BaseNotificationService):
|
|||
"""Send a message to the Lambda APNS gateway."""
|
||||
data = {ATTR_MESSAGE: message}
|
||||
|
||||
if kwargs.get(ATTR_TITLE) is not None:
|
||||
# Remove default title from notifications.
|
||||
if kwargs.get(ATTR_TITLE) != ATTR_TITLE_DEFAULT:
|
||||
data[ATTR_TITLE] = kwargs.get(ATTR_TITLE)
|
||||
# Remove default title from notifications.
|
||||
if (
|
||||
kwargs.get(ATTR_TITLE) is not None
|
||||
and kwargs.get(ATTR_TITLE) != ATTR_TITLE_DEFAULT
|
||||
):
|
||||
data[ATTR_TITLE] = kwargs.get(ATTR_TITLE)
|
||||
|
||||
targets = kwargs.get(ATTR_TARGET)
|
||||
|
||||
|
|
|
@ -281,15 +281,17 @@ class ISYInsteonBinarySensorEntity(ISYBinarySensorEntity):
|
|||
"""
|
||||
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
|
||||
# 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
|
||||
# both OFF).
|
||||
if self._negative_node.status == self._node.status:
|
||||
# The states disagree, therefore we cannot determine the state
|
||||
# of the sensor until we receive our first ON event.
|
||||
self._computed_state = None
|
||||
# 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
|
||||
# negative and positive nodes disagree on the state (both ON or
|
||||
# both OFF).
|
||||
if (
|
||||
self._negative_node.status != ISY_VALUE_UNKNOWN
|
||||
and self._negative_node.status == self._node.status
|
||||
):
|
||||
# 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:
|
||||
"""Handle an "On" control event from the "negative" node."""
|
||||
|
|
|
@ -121,10 +121,9 @@ def setup(hass, config):
|
|||
device_names = device.get(CONF_DEVICE_NAMES)
|
||||
name = device.get(CONF_NAME)
|
||||
name = f"{name.lower().replace(' ', '_')}_" if name else ""
|
||||
if api_key:
|
||||
if not get_devices(api_key):
|
||||
_LOGGER.error("Error connecting to Join, check API key")
|
||||
return False
|
||||
if api_key and not get_devices(api_key):
|
||||
_LOGGER.error("Error connecting to Join, check API key")
|
||||
return False
|
||||
if device_id is None and device_ids is None and device_names is None:
|
||||
_LOGGER.error(
|
||||
"No device was provided. Please specify device_id"
|
||||
|
|
|
@ -35,10 +35,9 @@ def get_service(hass, config, discovery_info=None):
|
|||
device_id = config.get(CONF_DEVICE_ID)
|
||||
device_ids = config.get(CONF_DEVICE_IDS)
|
||||
device_names = config.get(CONF_DEVICE_NAMES)
|
||||
if api_key:
|
||||
if not get_devices(api_key):
|
||||
_LOGGER.error("Error connecting to Join. Check the API key")
|
||||
return False
|
||||
if api_key and not get_devices(api_key):
|
||||
_LOGGER.error("Error connecting to Join. Check the API key")
|
||||
return False
|
||||
if device_id is None and device_ids is None and device_names is None:
|
||||
_LOGGER.error(
|
||||
"No device was provided. Please specify device_id"
|
||||
|
|
Loading…
Reference in New Issue