esphome/components/esp32_presense/__init__.py

48 lines
1.7 KiB
Python
Raw Normal View History

2023-12-07 23:51:43 +03:00
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])
2023-12-10 09:08:23 +03:00
# await cg.register_component(var, config)
2023-12-07 23:51:43 +03:00
cg.add(var.set_room(config[CONF_ROOM_KEY]))
2023-12-10 09:08:23 +03:00
# 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]))
2023-12-07 23:51:43 +03:00
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)
2023-12-10 10:29:34 +03:00
cg.add_library("esp-nimble-cpp", repository="https://github.com/h2zero/esp-nimble-cpp#v1.4.1", version="v1.4.1")
2023-12-07 23:51:43 +03:00
# await nimble_tracker.device_listener_to_code(var, config)
# await nimble_tracker.register_ble_device(var, config)