mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Merge of nested IF-IF cases - X-Z (#48373)
This commit is contained in:
parent
8fa935234a
commit
f4cc4a0896
@ -45,14 +45,15 @@ async def async_setup_entry(
|
||||
):
|
||||
"""Set up the Xiaomi Miio components from a config entry."""
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
if entry.data[CONF_FLOW_TYPE] == CONF_GATEWAY:
|
||||
if not await async_setup_gateway_entry(hass, entry):
|
||||
return False
|
||||
if entry.data[CONF_FLOW_TYPE] == CONF_DEVICE:
|
||||
if not await async_setup_device_entry(hass, entry):
|
||||
return False
|
||||
if entry.data[
|
||||
CONF_FLOW_TYPE
|
||||
] == CONF_GATEWAY and not await async_setup_gateway_entry(hass, entry):
|
||||
return False
|
||||
|
||||
return True
|
||||
return bool(
|
||||
entry.data[CONF_FLOW_TYPE] != CONF_DEVICE
|
||||
or await async_setup_device_entry(hass, entry)
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_gateway_entry(
|
||||
|
@ -448,15 +448,22 @@ class Thermostat(ZhaEntity, ClimateEntity):
|
||||
self.debug("preset mode '%s' is not supported", preset_mode)
|
||||
return
|
||||
|
||||
if self.preset_mode not in (preset_mode, PRESET_NONE):
|
||||
if not await self.async_preset_handler(self.preset_mode, enable=False):
|
||||
self.debug("Couldn't turn off '%s' preset", self.preset_mode)
|
||||
return
|
||||
if (
|
||||
self.preset_mode
|
||||
not in (
|
||||
preset_mode,
|
||||
PRESET_NONE,
|
||||
)
|
||||
and not await self.async_preset_handler(self.preset_mode, enable=False)
|
||||
):
|
||||
self.debug("Couldn't turn off '%s' preset", self.preset_mode)
|
||||
return
|
||||
|
||||
if preset_mode != PRESET_NONE:
|
||||
if not await self.async_preset_handler(preset_mode, enable=True):
|
||||
self.debug("Couldn't turn on '%s' preset", preset_mode)
|
||||
return
|
||||
if preset_mode != PRESET_NONE and not await self.async_preset_handler(
|
||||
preset_mode, enable=True
|
||||
):
|
||||
self.debug("Couldn't turn on '%s' preset", preset_mode)
|
||||
return
|
||||
self._preset = preset_mode
|
||||
self.async_write_ha_state()
|
||||
|
||||
|
@ -728,9 +728,8 @@ class LogRelayHandler(logging.Handler):
|
||||
def emit(self, record):
|
||||
"""Relay log message via dispatcher."""
|
||||
stack = []
|
||||
if record.levelno >= logging.WARN:
|
||||
if not record.exc_info:
|
||||
stack = [f for f, _, _, _ in traceback.extract_stack()]
|
||||
if record.levelno >= logging.WARN and not record.exc_info:
|
||||
stack = [f for f, _, _, _ in traceback.extract_stack()]
|
||||
|
||||
entry = LogEntry(record, stack, _figure_out_source(record, stack, self.hass))
|
||||
async_dispatcher_send(
|
||||
|
@ -182,10 +182,12 @@ class ZWaveClimateBase(ZWaveDeviceEntity, ClimateEntity):
|
||||
int(self.node.manufacturer_id, 16),
|
||||
int(self.node.product_id, 16),
|
||||
)
|
||||
if specific_sensor_key in DEVICE_MAPPINGS:
|
||||
if DEVICE_MAPPINGS[specific_sensor_key] == WORKAROUND_ZXT_120:
|
||||
_LOGGER.debug("Remotec ZXT-120 Zwave Thermostat workaround")
|
||||
self._zxt_120 = 1
|
||||
if (
|
||||
specific_sensor_key in DEVICE_MAPPINGS
|
||||
and DEVICE_MAPPINGS[specific_sensor_key] == WORKAROUND_ZXT_120
|
||||
):
|
||||
_LOGGER.debug("Remotec ZXT-120 Zwave Thermostat workaround")
|
||||
self._zxt_120 = 1
|
||||
self.update_properties()
|
||||
|
||||
def _mode(self) -> None:
|
||||
@ -567,9 +569,8 @@ class ZWaveClimateBase(ZWaveDeviceEntity, ClimateEntity):
|
||||
def set_swing_mode(self, swing_mode):
|
||||
"""Set new target swing mode."""
|
||||
_LOGGER.debug("Set swing_mode to %s", swing_mode)
|
||||
if self._zxt_120 == 1:
|
||||
if self.values.zxt_120_swing_mode:
|
||||
self.values.zxt_120_swing_mode.data = swing_mode
|
||||
if self._zxt_120 == 1 and self.values.zxt_120_swing_mode:
|
||||
self.values.zxt_120_swing_mode.data = swing_mode
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
|
@ -138,10 +138,12 @@ class ZwaveDimmer(ZWaveDeviceEntity, LightEntity):
|
||||
int(self.node.manufacturer_id, 16),
|
||||
int(self.node.product_id, 16),
|
||||
)
|
||||
if specific_sensor_key in DEVICE_MAPPINGS:
|
||||
if DEVICE_MAPPINGS[specific_sensor_key] == WORKAROUND_ZW098:
|
||||
_LOGGER.debug("AEOTEC ZW098 workaround enabled")
|
||||
self._zw098 = 1
|
||||
if (
|
||||
specific_sensor_key in DEVICE_MAPPINGS
|
||||
and DEVICE_MAPPINGS[specific_sensor_key] == WORKAROUND_ZW098
|
||||
):
|
||||
_LOGGER.debug("AEOTEC ZW098 workaround enabled")
|
||||
self._zw098 = 1
|
||||
|
||||
# Used for value change event handling
|
||||
self._refreshing = False
|
||||
|
@ -291,17 +291,17 @@ class ZwaveLock(ZWaveDeviceEntity, LockEntity):
|
||||
if self._state_workaround:
|
||||
self._state = LOCK_STATUS.get(str(notification_data))
|
||||
_LOGGER.debug("workaround: lock state set to %s", self._state)
|
||||
if self._v2btze:
|
||||
if (
|
||||
self.values.v2btze_advanced
|
||||
and self.values.v2btze_advanced.data == CONFIG_ADVANCED
|
||||
):
|
||||
self._state = LOCK_STATUS.get(str(notification_data))
|
||||
_LOGGER.debug(
|
||||
"Lock state set from Access Control value and is %s, get=%s",
|
||||
str(notification_data),
|
||||
self.state,
|
||||
)
|
||||
if (
|
||||
self._v2btze
|
||||
and self.values.v2btze_advanced
|
||||
and self.values.v2btze_advanced.data == CONFIG_ADVANCED
|
||||
):
|
||||
self._state = LOCK_STATUS.get(str(notification_data))
|
||||
_LOGGER.debug(
|
||||
"Lock state set from Access Control value and is %s, get=%s",
|
||||
str(notification_data),
|
||||
self.state,
|
||||
)
|
||||
|
||||
if self._track_message_workaround:
|
||||
this_message = self.node.stats["lastReceivedMessage"][5]
|
||||
|
@ -285,12 +285,12 @@ class ZWaveBooleanBinarySensor(ZWaveBaseEntity, BinarySensorEntity):
|
||||
@property
|
||||
def entity_registry_enabled_default(self) -> bool:
|
||||
"""Return if the entity should be enabled when first added to the entity registry."""
|
||||
if self.info.primary_value.command_class == CommandClass.SENSOR_BINARY:
|
||||
# Legacy binary sensors are phased out (replaced by notification sensors)
|
||||
# Disable by default to not confuse users
|
||||
if self.info.node.device_class.generic.key != 0x20:
|
||||
return False
|
||||
return True
|
||||
# Legacy binary sensors are phased out (replaced by notification sensors)
|
||||
# Disable by default to not confuse users
|
||||
return bool(
|
||||
self.info.primary_value.command_class != CommandClass.SENSOR_BINARY
|
||||
or self.info.node.device_class.generic.key == 0x20
|
||||
)
|
||||
|
||||
|
||||
class ZWaveNotificationBinarySensor(ZWaveBaseEntity, BinarySensorEntity):
|
||||
|
@ -403,56 +403,64 @@ def async_discover_values(node: ZwaveNode) -> Generator[ZwaveDiscoveryInfo, None
|
||||
and value.node.manufacturer_id not in schema.manufacturer_id
|
||||
):
|
||||
continue
|
||||
|
||||
# check product_id
|
||||
if (
|
||||
schema.product_id is not None
|
||||
and value.node.product_id not in schema.product_id
|
||||
):
|
||||
continue
|
||||
|
||||
# check product_type
|
||||
if (
|
||||
schema.product_type is not None
|
||||
and value.node.product_type not in schema.product_type
|
||||
):
|
||||
continue
|
||||
|
||||
# check firmware_version
|
||||
if (
|
||||
schema.firmware_version is not None
|
||||
and value.node.firmware_version not in schema.firmware_version
|
||||
):
|
||||
continue
|
||||
|
||||
# check device_class_basic
|
||||
if not check_device_class(
|
||||
value.node.device_class.basic, schema.device_class_basic
|
||||
):
|
||||
continue
|
||||
|
||||
# check device_class_generic
|
||||
if not check_device_class(
|
||||
value.node.device_class.generic, schema.device_class_generic
|
||||
):
|
||||
continue
|
||||
|
||||
# check device_class_specific
|
||||
if not check_device_class(
|
||||
value.node.device_class.specific, schema.device_class_specific
|
||||
):
|
||||
continue
|
||||
|
||||
# check primary value
|
||||
if not check_value(value, schema.primary_value):
|
||||
continue
|
||||
|
||||
# check additional required values
|
||||
if schema.required_values is not None:
|
||||
if not all(
|
||||
any(check_value(val, val_scheme) for val in node.values.values())
|
||||
for val_scheme in schema.required_values
|
||||
):
|
||||
continue
|
||||
if schema.required_values is not None and not all(
|
||||
any(check_value(val, val_scheme) for val in node.values.values())
|
||||
for val_scheme in schema.required_values
|
||||
):
|
||||
continue
|
||||
|
||||
# check for values that may not be present
|
||||
if schema.absent_values is not None:
|
||||
if any(
|
||||
any(check_value(val, val_scheme) for val in node.values.values())
|
||||
for val_scheme in schema.absent_values
|
||||
):
|
||||
continue
|
||||
if schema.absent_values is not None and any(
|
||||
any(check_value(val, val_scheme) for val in node.values.values())
|
||||
for val_scheme in schema.absent_values
|
||||
):
|
||||
continue
|
||||
|
||||
# all checks passed, this value belongs to an entity
|
||||
yield ZwaveDiscoveryInfo(
|
||||
node=value.node,
|
||||
@ -460,6 +468,7 @@ def async_discover_values(node: ZwaveNode) -> Generator[ZwaveDiscoveryInfo, None
|
||||
platform=schema.platform,
|
||||
platform_hint=schema.hint,
|
||||
)
|
||||
|
||||
if not schema.allow_multi:
|
||||
# break out of loop, this value may not be discovered by other schemas/platforms
|
||||
break
|
||||
|
Loading…
x
Reference in New Issue
Block a user