esphome/components/esp32_nimble_mqtt_room/__init__.py

41 lines
1.4 KiB
Python
Raw Normal View History

2023-12-03 22:19:57 +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
DEPENDENCIES = ["mqtt"]
AUTO_LOAD=["nimble_distance_custom"]
CONF_NIMBLE_ID = "esp32_nimble_mqtt_room"
CONF_ROOM_KEY = 'room'
CONF_BASE_TOPIC_KEY = 'base_topic'
CONF_MAC_KEY = 'mac_addr'
2023-12-06 21:01:11 +03:00
CONF_MAX_DISTANCE = 'max_distance'
2023-12-03 22:19:57 +03:00
esp32_nimble_tracker_ns = cg.esphome_ns.namespace("esp32_nimble_mqtt_room")
ESP32NimbleMQTTRoom = esp32_nimble_tracker_ns.class_(
"ESP32NimbleMQTTRoom", cg.Component, nimble_tracker.NimbleDeviceListener
)
CONFIG_SCHEMA = cv.Schema({
cv.GenerateID(): cv.declare_id(ESP32NimbleMQTTRoom),
cv.Required(CONF_ROOM_KEY): cv.string,
cv.Required(CONF_MAC_KEY): cv.All(cv.ensure_list(cv.string)),
2023-12-06 21:01:11 +03:00
cv.Optional(CONF_MAX_DISTANCE, default=16.0): cv.float_,
2023-12-03 22:19:57 +03:00
cv.Optional(CONF_BASE_TOPIC_KEY, default="esphome_presense"): cv.string,
}).extend(cv.COMPONENT_SCHEMA).extend(nimble_tracker.NIMBLE_DEVICE_LISTENER_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]))
2023-12-06 21:01:11 +03:00
cg.add(var.set_max_distance(config[CONF_MAX_DISTANCE]))
2023-12-03 22:19:57 +03:00
await nimble_tracker.device_listener_to_code(var, config)
await nimble_tracker.register_ble_device(var, config)