[nrf52, zigbee] Add sensor (#12187)

Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com>
This commit is contained in:
tomaszduda23andJonathan Swoboda authored and GitHub committed 2026-01-07 08:20:01 -10:00
1 parent d6554702d8
commit ada4e6d5e9
12 files changed
+471 -54

No files matched your search

+29 -3
View File
@@ -13,14 +13,16 @@ from esphome.types import ConfigType
from .const_zephyr import (
CONF_MAX_EP_NUMBER,
CONF_ON_JOIN,
CONF_POWER_SOURCE,
CONF_WIPE_ON_BOOT,
CONF_ZIGBEE_ID,
KEY_EP_NUMBER,
KEY_ZIGBEE,
POWER_SOURCE,
ZigbeeComponent,
zigbee_ns,
)
from .zigbee_zephyr import zephyr_binary_sensor
from .zigbee_zephyr import zephyr_binary_sensor, zephyr_sensor
CODEOWNERS = ["@tomaszduda23"]
@@ -35,6 +37,7 @@ def zigbee_set_core_data(config: ConfigType) -> ConfigType:
BINARY_SENSOR_SCHEMA = cv.Schema({}).extend(zephyr_binary_sensor)
SENSOR_SCHEMA = cv.Schema({}).extend(zephyr_sensor)
CONFIG_SCHEMA = cv.All(
cv.Schema(
@@ -42,9 +45,15 @@ CONFIG_SCHEMA = cv.All(
cv.GenerateID(CONF_ID): cv.declare_id(ZigbeeComponent),
cv.Optional(CONF_ON_JOIN): automation.validate_automation(single=True),
cv.Optional(CONF_WIPE_ON_BOOT, default=False): cv.All(
cv.boolean,
cv.Any(
cv.boolean,
cv.one_of(*["once"], lower=True),
),
cv.requires_component("nrf52"),
),
cv.Optional(CONF_POWER_SOURCE, default="DC_SOURCE"): cv.enum(
POWER_SOURCE, upper=True
),
}
).extend(cv.COMPONENT_SCHEMA),
zigbee_set_core_data,
@@ -86,7 +95,16 @@ async def setup_binary_sensor(entity: cg.MockObj, config: ConfigType) -> None:
await zephyr_setup_binary_sensor(entity, config)
def validate_binary_sensor(config: ConfigType) -> ConfigType:
async def setup_sensor(entity: cg.MockObj, config: ConfigType) -> None:
if not config.get(CONF_ZIGBEE_ID) or config.get(CONF_INTERNAL):
return
if CORE.using_zephyr:
from .zigbee_zephyr import zephyr_setup_sensor
await zephyr_setup_sensor(entity, config)
def consume_endpoint(config: ConfigType) -> ConfigType:
if not config.get(CONF_ZIGBEE_ID) or config.get(CONF_INTERNAL):
return config
data: dict[str, Any] = CORE.data.setdefault(KEY_ZIGBEE, {})
@@ -95,6 +113,14 @@ def validate_binary_sensor(config: ConfigType) -> ConfigType:
return config
def validate_binary_sensor(config: ConfigType) -> ConfigType:
return consume_endpoint(config)
def validate_sensor(config: ConfigType) -> ConfigType:
return consume_endpoint(config)
ZIGBEE_ACTION_SCHEMA = automation.maybe_simple_id(
cv.Schema(
{