mirror of
https://github.com/esphome/esphome.git
synced 2026-02-08 00:31:58 +00:00
[nrf52,zigbee] Warning if spaces in description (#13114)
Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from esphome import automation, core
|
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 import zephyr_add_pm_static, zephyr_data
|
||||||
from esphome.components.zephyr.const import KEY_BOOTLOADER
|
from esphome.components.zephyr.const import KEY_BOOTLOADER
|
||||||
import esphome.config_validation as cv
|
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.core import CORE
|
||||||
from esphome.types import ConfigType
|
from esphome.types import ConfigType
|
||||||
|
|
||||||
@@ -24,6 +25,8 @@ from .const_zephyr import (
|
|||||||
)
|
)
|
||||||
from .zigbee_zephyr import zephyr_binary_sensor, zephyr_sensor
|
from .zigbee_zephyr import zephyr_binary_sensor, zephyr_sensor
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
CODEOWNERS = ["@tomaszduda23"]
|
CODEOWNERS = ["@tomaszduda23"]
|
||||||
|
|
||||||
|
|
||||||
@@ -107,6 +110,12 @@ async def setup_sensor(entity: cg.MockObj, config: ConfigType) -> None:
|
|||||||
def consume_endpoint(config: ConfigType) -> ConfigType:
|
def consume_endpoint(config: ConfigType) -> ConfigType:
|
||||||
if not config.get(CONF_ZIGBEE_ID) or config.get(CONF_INTERNAL):
|
if not config.get(CONF_ZIGBEE_ID) or config.get(CONF_INTERNAL):
|
||||||
return config
|
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, {})
|
data: dict[str, Any] = CORE.data.setdefault(KEY_ZIGBEE, {})
|
||||||
slots: list[str] = data.setdefault(KEY_EP_NUMBER, [])
|
slots: list[str] = data.setdefault(KEY_EP_NUMBER, [])
|
||||||
slots.extend([""])
|
slots.extend([""])
|
||||||
|
|||||||
@@ -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:
|
def zigbee_set_string(target: cg.MockObj, value: str) -> str:
|
||||||
"""Set a ZCL string value and return the target name (arrays decay to pointers)."""
|
"""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.add(
|
||||||
cg.RawExpression(
|
cg.RawExpression(
|
||||||
f"ZB_ZCL_SET_STRING_VAL({target}, {cg.safe_exp(value)}, ZB_ZCL_STRING_CONST_SIZE({cg.safe_exp(value)}))"
|
f"ZB_ZCL_SET_STRING_VAL({target}, {cg.safe_exp(value)}, ZB_ZCL_STRING_CONST_SIZE({cg.safe_exp(value)}))"
|
||||||
|
|||||||
Reference in New Issue
Block a user