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