mirror of
https://github.com/esphome/esphome.git
synced 2024-12-02 11:44:13 +01:00
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
import esphome.codegen as cg
|
|
from esphome import automation
|
|
import esphome.config_validation as cv
|
|
from esphome.components import esp32_ble_tracker
|
|
from esphome.const import CONF_TRIGGER_ID
|
|
|
|
CODEOWNERS = ["@OttoWinter"]
|
|
DEPENDENCIES = ["esp32_ble_tracker"]
|
|
|
|
exposure_notifications_ns = cg.esphome_ns.namespace("exposure_notifications")
|
|
ExposureNotification = exposure_notifications_ns.struct("ExposureNotification")
|
|
ExposureNotificationTrigger = exposure_notifications_ns.class_(
|
|
"ExposureNotificationTrigger",
|
|
esp32_ble_tracker.ESPBTDeviceListener,
|
|
automation.Trigger.template(ExposureNotification),
|
|
)
|
|
|
|
CONF_ON_EXPOSURE_NOTIFICATION = "on_exposure_notification"
|
|
|
|
CONFIG_SCHEMA = cv.Schema(
|
|
{
|
|
cv.Required(CONF_ON_EXPOSURE_NOTIFICATION): automation.validate_automation(
|
|
cv.Schema(
|
|
{
|
|
cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(
|
|
ExposureNotificationTrigger
|
|
),
|
|
}
|
|
).extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA)
|
|
),
|
|
}
|
|
)
|
|
|
|
|
|
async def to_code(config):
|
|
for conf in config.get(CONF_ON_EXPOSURE_NOTIFICATION, []):
|
|
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID])
|
|
await automation.build_automation(trigger, [(ExposureNotification, "x")], conf)
|
|
await esp32_ble_tracker.register_ble_device(trigger, conf)
|