esphome/esphome/components/mopeka_ble/__init__.py
Fabian d16eff5039
Support Mopeka Standard LPG tank bluetooth sensor (#4351)
* Add mopeka standard tank sensor.

* Enhance mopeka ble to find standard sensors.

* Updated `CODEOWNERS` file

* Move default from cpp to py.

* Format documents with esphome settings.

* Linter wants changes.

* Update name of `get_lpg_speed_of_sound`.

* manually update `CODEOWNERS`.

* Manually update CODEOWNER, because `build_codeowners.py. is failing.

* Add comments.

* Use percentage for `propane_butane_mix`.

* add config to `dump_config()`

* Formatting

* Use struct for data parsing and find best data.

* Add `this`.

* Consistant naming of configuration.

* Fix format issues.

* Make clang-tidy happy.

* Adjust loop variable.

---------

Co-authored-by: Your Name <you@example.com>
2023-02-21 21:48:29 +00:00

30 lines
974 B
Python

import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import esp32_ble_tracker
from esphome.const import CONF_ID
CODEOWNERS = ["@spbrogan", "@Fabian-Schmidt"]
DEPENDENCIES = ["esp32_ble_tracker"]
CONF_SHOW_SENSORS_WITHOUT_SYNC = "show_sensors_without_sync"
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),
cv.Optional(CONF_SHOW_SENSORS_WITHOUT_SYNC, default=False): cv.boolean,
}
).extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
if CONF_SHOW_SENSORS_WITHOUT_SYNC in config:
cg.add(
var.set_show_sensors_without_sync(config[CONF_SHOW_SENSORS_WITHOUT_SYNC])
)
await esp32_ble_tracker.register_ble_device(var, config)