mirror of
https://github.com/esphome/esphome.git
synced 2024-11-30 13:04:13 +01:00
7c7032c59e
* Implement custom sensor platform
* Update
* Ethernet
* Lint
* Fix
* Login page
* Rename cookie secret
* Update manifest
* Update cookie check logic
* Favicon
* Fix
* Favicon manifest
* Fix
* Fix
* Fix
* Use hostname
* Message
* Temporary commit for screenshot
* Automatic board selection
* Undo temporary commit
* Update esphomeyaml-edge
* In-dashboard editing and hosting files locally
* Update esphomeyaml-edge
* Better ANSI color escaping
* Message
* Lint
* Download Efficiency
* Fix gitlab
* Fix
* Rename extra_libraries to libraries
* Add example
* Update README.md
* Update README.md
* Update README.md
* HassIO -> Hass.io
* Updates
* Add update available notice
* Update
* Fix substitutions
* Better error message
* Re-do dashboard ANSI colors
* Only include FastLED if user says so
* Autoscroll logs
* Remove old checks
* Use safer RedirectText
* Improvements
* Fix
* Use enviornment variable
* Use http://hassio/host/info
* Fix conditions
* Update platformio versions
* Revert "Use enviornment variable"
This reverts commit 7f038eb5d2
.
* Fix
* README update
* Temp
* Better invalid config messages
* Platformio debug
* Improve error messages
* Debug
* Remove debug
* Multi Conf
* Update
* Better paths
* Remove unused
* Fixes
* Lint
* lib_ignore
* Try fix platformio colors
* Fix dashboard scrolling
* Revert
* Lint
* Revert
54 lines
2.4 KiB
Python
54 lines
2.4 KiB
Python
import voluptuous as vol
|
|
|
|
from esphomeyaml.components import esp32_ble_tracker, sensor
|
|
from esphomeyaml.components.esp32_ble_tracker import CONF_ESP32_BLE_ID, ESP32BLETracker, \
|
|
make_address_array
|
|
import esphomeyaml.config_validation as cv
|
|
from esphomeyaml.const import CONF_BATTERY_LEVEL, CONF_CONDUCTIVITY, CONF_ID, CONF_ILLUMINANCE, \
|
|
CONF_MAC_ADDRESS, CONF_MOISTURE, CONF_NAME, CONF_TEMPERATURE
|
|
from esphomeyaml.cpp_generator import get_variable, Pvariable
|
|
|
|
DEPENDENCIES = ['esp32_ble_tracker']
|
|
|
|
PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
|
|
cv.GenerateID(): cv.declare_variable_id(esp32_ble_tracker.XiaomiDevice),
|
|
cv.GenerateID(CONF_ESP32_BLE_ID): cv.use_variable_id(ESP32BLETracker),
|
|
vol.Required(CONF_MAC_ADDRESS): cv.mac_address,
|
|
vol.Optional(CONF_TEMPERATURE): cv.nameable(esp32_ble_tracker.XIAOMI_SENSOR_SCHEMA),
|
|
vol.Optional(CONF_MOISTURE): cv.nameable(esp32_ble_tracker.XIAOMI_SENSOR_SCHEMA),
|
|
vol.Optional(CONF_ILLUMINANCE): cv.nameable(esp32_ble_tracker.XIAOMI_SENSOR_SCHEMA),
|
|
vol.Optional(CONF_CONDUCTIVITY): cv.nameable(esp32_ble_tracker.XIAOMI_SENSOR_SCHEMA),
|
|
vol.Optional(CONF_BATTERY_LEVEL): cv.nameable(esp32_ble_tracker.XIAOMI_SENSOR_SCHEMA),
|
|
})
|
|
|
|
|
|
def to_code(config):
|
|
for hub in get_variable(config[CONF_ESP32_BLE_ID]):
|
|
yield
|
|
rhs = hub.make_xiaomi_device(make_address_array(config[CONF_MAC_ADDRESS]))
|
|
dev = Pvariable(config[CONF_ID], rhs)
|
|
if CONF_TEMPERATURE in config:
|
|
conf = config[CONF_TEMPERATURE]
|
|
sensor.register_sensor(dev.Pmake_temperature_sensor(conf[CONF_NAME]), conf)
|
|
if CONF_MOISTURE in config:
|
|
conf = config[CONF_MOISTURE]
|
|
sensor.register_sensor(dev.Pmake_moisture_sensor(conf[CONF_NAME]), conf)
|
|
if CONF_ILLUMINANCE in config:
|
|
conf = config[CONF_ILLUMINANCE]
|
|
sensor.register_sensor(dev.Pmake_illuminance_sensor(conf[CONF_NAME]), conf)
|
|
if CONF_CONDUCTIVITY in config:
|
|
conf = config[CONF_CONDUCTIVITY]
|
|
sensor.register_sensor(dev.Pmake_conductivity_sensor(conf[CONF_NAME]), conf)
|
|
if CONF_BATTERY_LEVEL in config:
|
|
conf = config[CONF_BATTERY_LEVEL]
|
|
sensor.register_sensor(dev.Pmake_battery_level_sensor(conf[CONF_NAME]), conf)
|
|
|
|
|
|
def to_hass_config(data, config):
|
|
ret = []
|
|
for key in (CONF_TEMPERATURE, CONF_MOISTURE, CONF_ILLUMINANCE, CONF_CONDUCTIVITY,
|
|
CONF_BATTERY_LEVEL):
|
|
if key in config:
|
|
ret.append(sensor.core_to_hass_config(data, config[key]))
|
|
return ret
|