Merge of nested IF-IF cases - H-J (#48368)
parent
db355f9b23
commit
786023fce4
|
@ -258,8 +258,7 @@ 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))
|
||||||
|
|
|
@ -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,8 +102,7 @@ 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 = []
|
||||||
|
|
|
@ -99,8 +99,10 @@ 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)
|
||||||
|
and len(service.linked) > 0
|
||||||
|
):
|
||||||
return []
|
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,
|
"characteristic": char.iid,
|
||||||
"value": event_type,
|
"value": event_type,
|
||||||
"type": "button1",
|
"type": "button1",
|
||||||
"subtype": HK_TO_HA_INPUT_EVENT_VALUES[event_type],
|
"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,10 +234,7 @@ 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():
|
|
||||||
triggers.append(
|
|
||||||
{
|
{
|
||||||
CONF_PLATFORM: "device",
|
CONF_PLATFORM: "device",
|
||||||
CONF_DEVICE_ID: device_id,
|
CONF_DEVICE_ID: device_id,
|
||||||
|
@ -245,9 +242,8 @@ async def async_get_triggers(hass: HomeAssistant, device_id: str) -> list[dict]:
|
||||||
CONF_TYPE: trigger,
|
CONF_TYPE: trigger,
|
||||||
CONF_SUBTYPE: subtype,
|
CONF_SUBTYPE: subtype,
|
||||||
}
|
}
|
||||||
)
|
for trigger, subtype in device.async_get_triggers()
|
||||||
|
]
|
||||||
return triggers
|
|
||||||
|
|
||||||
|
|
||||||
async def async_attach_trigger(
|
async def async_attach_trigger(
|
||||||
|
|
|
@ -93,8 +93,10 @@ 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)
|
||||||
|
and RemoteKeyValues.PLAY_PAUSE in self.supported_remote_keys
|
||||||
|
):
|
||||||
features |= SUPPORT_PAUSE | SUPPORT_PLAY
|
features |= SUPPORT_PAUSE | SUPPORT_PLAY
|
||||||
|
|
||||||
return features
|
return features
|
||||||
|
|
|
@ -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,8 +297,7 @@ 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
|
||||||
|
|
|
@ -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,6 +252,7 @@ class HyperionBaseLight(LightEntity):
|
||||||
const.KEY_ID: item[const.KEY_ID],
|
const.KEY_ID: item[const.KEY_ID],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
)
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -208,8 +208,11 @@ 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
|
||||||
|
and self.confidence
|
||||||
|
and face[ATTR_CONFIDENCE] < self.confidence
|
||||||
|
):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
face.update({ATTR_ENTITY_ID: self.entity_id})
|
face.update({ATTR_ENTITY_ID: self.entity_id})
|
||||||
|
|
|
@ -220,8 +220,10 @@ 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")
|
||||||
|
and message_untyped_text is None
|
||||||
|
):
|
||||||
message_untyped_text = part.get_payload()
|
message_untyped_text = part.get_payload()
|
||||||
|
|
||||||
if message_text is not None:
|
if message_text is not None:
|
||||||
|
|
|
@ -69,9 +69,11 @@ 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 kwargs.get(ATTR_TITLE) != ATTR_TITLE_DEFAULT:
|
if (
|
||||||
|
kwargs.get(ATTR_TITLE) is not None
|
||||||
|
and kwargs.get(ATTR_TITLE) != ATTR_TITLE_DEFAULT
|
||||||
|
):
|
||||||
data[ATTR_TITLE] = kwargs.get(ATTR_TITLE)
|
data[ATTR_TITLE] = kwargs.get(ATTR_TITLE)
|
||||||
|
|
||||||
targets = kwargs.get(ATTR_TARGET)
|
targets = kwargs.get(ATTR_TARGET)
|
||||||
|
|
|
@ -281,12 +281,14 @@ 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 self._negative_node.status == self._node.status:
|
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
|
# The states disagree, therefore we cannot determine the state
|
||||||
# of the sensor until we receive our first ON event.
|
# of the sensor until we receive our first ON event.
|
||||||
self._computed_state = None
|
self._computed_state = None
|
||||||
|
|
|
@ -121,8 +121,7 @@ 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:
|
||||||
|
|
|
@ -35,8 +35,7 @@ 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:
|
||||||
|
|
Loading…
Reference in New Issue