2022-02-28 23:30:33 +01:00
|
|
|
import esphome.codegen as cg
|
|
|
|
import esphome.config_validation as cv
|
|
|
|
from esphome.components import esp32_ble_tracker
|
|
|
|
from esphome.const import CONF_ID
|
|
|
|
|
2023-02-21 22:48:29 +01:00
|
|
|
CODEOWNERS = ["@spbrogan", "@Fabian-Schmidt"]
|
2022-02-28 23:30:33 +01:00
|
|
|
DEPENDENCIES = ["esp32_ble_tracker"]
|
|
|
|
|
2023-02-21 22:48:29 +01:00
|
|
|
CONF_SHOW_SENSORS_WITHOUT_SYNC = "show_sensors_without_sync"
|
|
|
|
|
2022-02-28 23:30:33 +01:00
|
|
|
mopeka_ble_ns = cg.esphome_ns.namespace("mopeka_ble")
|
|
|
|
MopekaListener = mopeka_ble_ns.class_(
|
|
|
|
"MopekaListener", esp32_ble_tracker.ESPBTDeviceListener
|
|
|
|
)
|
|
|
|
|
|
|
|
CONFIG_SCHEMA = cv.Schema(
|
|
|
|
{
|
|
|
|
cv.GenerateID(): cv.declare_id(MopekaListener),
|
2023-02-21 22:48:29 +01:00
|
|
|
cv.Optional(CONF_SHOW_SENSORS_WITHOUT_SYNC, default=False): cv.boolean,
|
2022-02-28 23:30:33 +01:00
|
|
|
}
|
|
|
|
).extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA)
|
|
|
|
|
|
|
|
|
|
|
|
async def to_code(config):
|
|
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
2023-02-21 22:48:29 +01:00
|
|
|
if CONF_SHOW_SENSORS_WITHOUT_SYNC in config:
|
|
|
|
cg.add(
|
|
|
|
var.set_show_sensors_without_sync(config[CONF_SHOW_SENSORS_WITHOUT_SYNC])
|
|
|
|
)
|
2022-02-28 23:30:33 +01:00
|
|
|
await esp32_ble_tracker.register_ble_device(var, config)
|