diff --git a/esphome/components/zigbee/__init__.py b/esphome/components/zigbee/__init__.py index cf37e890c4..e363164997 100644 --- a/esphome/components/zigbee/__init__.py +++ b/esphome/components/zigbee/__init__.py @@ -1,3 +1,4 @@ +import logging from typing import Any from esphome import automation, core @@ -6,7 +7,7 @@ from esphome.components.nrf52.boards import BOOTLOADER_CONFIG, Section from esphome.components.zephyr import zephyr_add_pm_static, zephyr_data from esphome.components.zephyr.const import KEY_BOOTLOADER import esphome.config_validation as cv -from esphome.const import CONF_ID, CONF_INTERNAL +from esphome.const import CONF_ID, CONF_INTERNAL, CONF_NAME from esphome.core import CORE from esphome.types import ConfigType @@ -24,6 +25,8 @@ from .const_zephyr import ( ) from .zigbee_zephyr import zephyr_binary_sensor, zephyr_sensor +_LOGGER = logging.getLogger(__name__) + CODEOWNERS = ["@tomaszduda23"] @@ -107,6 +110,12 @@ async def setup_sensor(entity: cg.MockObj, config: ConfigType) -> None: def consume_endpoint(config: ConfigType) -> ConfigType: if not config.get(CONF_ZIGBEE_ID) or config.get(CONF_INTERNAL): return config + if " " in config[CONF_NAME]: + _LOGGER.warning( + "Spaces in '%s' work with ZHA but not Zigbee2MQTT. For Zigbee2MQTT use '%s'", + config[CONF_NAME], + config[CONF_NAME].replace(" ", "_"), + ) data: dict[str, Any] = CORE.data.setdefault(KEY_ZIGBEE, {}) slots: list[str] = data.setdefault(KEY_EP_NUMBER, []) slots.extend([""]) diff --git a/esphome/components/zigbee/zigbee_zephyr.py b/esphome/components/zigbee/zigbee_zephyr.py index d8a2716603..71ea0da6a7 100644 --- a/esphome/components/zigbee/zigbee_zephyr.py +++ b/esphome/components/zigbee/zigbee_zephyr.py @@ -212,6 +212,8 @@ def zigbee_assign(target: cg.MockObj, expression: cg.RawExpression | int) -> str def zigbee_set_string(target: cg.MockObj, value: str) -> str: """Set a ZCL string value and return the target name (arrays decay to pointers).""" + # Zigbee supports only ASCII + value = value.encode("ascii", "ignore").decode() cg.add( cg.RawExpression( f"ZB_ZCL_SET_STRING_VAL({target}, {cg.safe_exp(value)}, ZB_ZCL_STRING_CONST_SIZE({cg.safe_exp(value)}))"