52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
import esphome.config_validation as cv
|
|
import esphome.codegen as cg
|
|
from esphome.const import (
|
|
CONF_ID,
|
|
)
|
|
from esphome.components import mqtt, nimble_tracker
|
|
from esphome.components.esp32 import add_idf_sdkconfig_option
|
|
|
|
DEPENDENCIES = ["mqtt"]
|
|
|
|
# CONF_NIMBLE_ID = "esp32_nimble_mqtt_room"
|
|
|
|
CONF_ROOM_KEY = 'room'
|
|
CONF_BASE_TOPIC_KEY = 'base_topic'
|
|
CONF_MAC_KEY = 'mac_addr'
|
|
CONF_MAX_DISTANCE = 'max_distance'
|
|
|
|
esp32_nimble_tracker_ns = cg.esphome_ns.namespace("esp32_presense")
|
|
ESP32Presense = esp32_nimble_tracker_ns.class_(
|
|
"ESP32Presense", cg.Component
|
|
)
|
|
|
|
CONFIG_SCHEMA = cv.Schema({
|
|
cv.GenerateID(): cv.declare_id(ESP32Presense),
|
|
cv.Required(CONF_ROOM_KEY): cv.string,
|
|
cv.Required(CONF_MAC_KEY): cv.All(cv.ensure_list(cv.string)),
|
|
cv.Optional(CONF_MAX_DISTANCE, default=16.0): cv.float_,
|
|
cv.Optional(CONF_BASE_TOPIC_KEY, default="esphome_presense"): cv.string,
|
|
}).extend(cv.COMPONENT_SCHEMA)
|
|
|
|
async def to_code(config):
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
|
await cg.register_component(var, config)
|
|
|
|
cg.add(var.set_room(config[CONF_ROOM_KEY]))
|
|
cg.add(var.set_base_topic(config[CONF_BASE_TOPIC_KEY]))
|
|
cg.add(var.set_addresses(config[CONF_MAC_KEY]))
|
|
cg.add(var.set_max_distance(config[CONF_MAX_DISTANCE]))
|
|
|
|
add_idf_sdkconfig_option("CONFIG_BT_ENABLED", True)
|
|
add_idf_sdkconfig_option("CONFIG_BT_BLUEDROID_ENABLED", False)
|
|
add_idf_sdkconfig_option("CONFIG_BT_NIMBLE_ENABLED", True)
|
|
add_idf_sdkconfig_option("CONFIG_MBEDTLS_HARDWARE_AES", False)
|
|
|
|
cg.add_library(
|
|
name="esp-nimble-cpp",
|
|
repository="https://github.com/h2zero/esp-nimble-cpp",
|
|
version="1.4.1"
|
|
)
|
|
|
|
# await nimble_tracker.device_listener_to_code(var, config)
|
|
# await nimble_tracker.register_ble_device(var, config) |