mirror of
https://github.com/esphome/esphome.git
synced 2024-12-04 04:28:19 +01:00
947c104eff
Co-authored-by: Ben Buxton <bb@cactii.net> Co-authored-by: Otto Winter <otto@otto-winter.com> Co-authored-by: Stefan Agner <stefan@agner.ch> Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Co-authored-by: René Klomp <rene@klomp.ws> Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl> Co-authored-by: Geoff Davis <geoff@geoffdavis.com> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> Co-authored-by: dentra <dentra@users.noreply.github.com> Co-authored-by: Guillermo Ruffino <glm.net@gmail.com> Co-authored-by: Franck Nijhof <frenck@frenck.nl> Co-authored-by: Barry Loong <loongyh@users.noreply.github.com> Co-authored-by: Sergey V. DUDANOV <sergey.dudanov@gmail.com> Co-authored-by: Balazs Scheidler <bazsi77@gmail.com>
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
import esphome.codegen as cg
|
|
import esphome.config_validation as cv
|
|
from esphome.components import sensor, ble_client
|
|
from esphome.const import (
|
|
CONF_ID,
|
|
CONF_BATTERY_LEVEL,
|
|
ICON_BATTERY,
|
|
CONF_ILLUMINANCE,
|
|
ICON_BRIGHTNESS_5,
|
|
UNIT_PERCENT,
|
|
)
|
|
|
|
CODEOWNERS = ["@buxtronix"]
|
|
|
|
am43_ns = cg.esphome_ns.namespace("am43")
|
|
Am43 = am43_ns.class_("Am43", ble_client.BLEClientNode, cg.PollingComponent)
|
|
|
|
CONFIG_SCHEMA = (
|
|
cv.Schema(
|
|
{
|
|
cv.GenerateID(): cv.declare_id(Am43),
|
|
cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(
|
|
UNIT_PERCENT, ICON_BATTERY, 0
|
|
),
|
|
cv.Optional(CONF_ILLUMINANCE): sensor.sensor_schema(
|
|
UNIT_PERCENT, ICON_BRIGHTNESS_5, 0
|
|
),
|
|
}
|
|
)
|
|
.extend(ble_client.BLE_CLIENT_SCHEMA)
|
|
.extend(cv.polling_component_schema("120s"))
|
|
)
|
|
|
|
|
|
def to_code(config):
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
|
yield cg.register_component(var, config)
|
|
yield ble_client.register_ble_node(var, config)
|
|
|
|
if CONF_BATTERY_LEVEL in config:
|
|
sens = yield sensor.new_sensor(config[CONF_BATTERY_LEVEL])
|
|
cg.add(var.set_battery(sens))
|
|
|
|
if CONF_ILLUMINANCE in config:
|
|
sens = yield sensor.new_sensor(config[CONF_ILLUMINANCE])
|
|
cg.add(var.set_illuminance(sens))
|