mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 22:48:10 +01:00
Unify Xiaomi implementations (#188)
This commit is contained in:
parent
2d20a1c0fb
commit
b8d7185d99
2 changed files with 14 additions and 12 deletions
|
@ -10,10 +10,10 @@ from esphomeyaml.helpers import Pvariable, esphomelib_ns, get_variable
|
|||
|
||||
DEPENDENCIES = ['esp32_ble_tracker']
|
||||
|
||||
XiaomiMiFloraDevice = esphomelib_ns.XiaomiMiFloraDevice
|
||||
XiaomiDevice = esphomelib_ns.XiaomiDevice
|
||||
|
||||
PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(XiaomiMiFloraDevice),
|
||||
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(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(sensor.SENSOR_SCHEMA),
|
||||
|
@ -28,7 +28,7 @@ def to_code(config):
|
|||
hub = None
|
||||
for hub in get_variable(config[CONF_ESP32_BLE_ID]):
|
||||
yield
|
||||
rhs = hub.make_miflora_sensor(make_address_array(config[CONF_MAC_ADDRESS]))
|
||||
rhs = hub.make_xiaomi_device(make_address_array(config[CONF_MAC_ADDRESS]))
|
||||
dev = Pvariable(config[CONF_MAKE_ID], rhs)
|
||||
if CONF_TEMPERATURE in config:
|
||||
conf = config[CONF_TEMPERATURE]
|
||||
|
|
|
@ -10,14 +10,14 @@ from esphomeyaml.helpers import Pvariable, esphomelib_ns, get_variable
|
|||
|
||||
DEPENDENCIES = ['esp32_ble_tracker']
|
||||
|
||||
XiaomiMiJiaDevice = esphomelib_ns.XiaomiMiJiaDevice
|
||||
XiaomiDevice = esphomelib_ns.XiaomiDevice
|
||||
|
||||
PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
|
||||
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(XiaomiMiJiaDevice),
|
||||
cv.GenerateID(CONF_MAKE_ID): cv.declare_variable_id(XiaomiDevice),
|
||||
cv.GenerateID(CONF_ESP32_BLE_ID): cv.use_variable_id(ESP32BLETracker),
|
||||
vol.Required(CONF_MAC_ADDRESS): cv.mac_address,
|
||||
vol.Required(CONF_TEMPERATURE): cv.nameable(sensor.SENSOR_SCHEMA),
|
||||
vol.Required(CONF_HUMIDITY): cv.nameable(sensor.SENSOR_SCHEMA),
|
||||
vol.Optional(CONF_TEMPERATURE): cv.nameable(sensor.SENSOR_SCHEMA),
|
||||
vol.Optional(CONF_HUMIDITY): cv.nameable(sensor.SENSOR_SCHEMA),
|
||||
vol.Optional(CONF_BATTERY_LEVEL): cv.nameable(sensor.SENSOR_SCHEMA),
|
||||
})
|
||||
|
||||
|
@ -26,12 +26,14 @@ def to_code(config):
|
|||
hub = None
|
||||
for hub in get_variable(config[CONF_ESP32_BLE_ID]):
|
||||
yield
|
||||
rhs = hub.make_mijia_sensor(config[CONF_TEMPERATURE][CONF_NAME],
|
||||
config[CONF_HUMIDITY][CONF_NAME],
|
||||
make_address_array(config[CONF_MAC_ADDRESS]))
|
||||
rhs = hub.make_xiaomi_device(make_address_array(config[CONF_MAC_ADDRESS]))
|
||||
dev = Pvariable(config[CONF_MAKE_ID], rhs)
|
||||
sensor.register_sensor(dev.Pget_temperature_sensor(), config[CONF_TEMPERATURE])
|
||||
sensor.register_sensor(dev.Pget_humidity_sensor(), config[CONF_HUMIDITY])
|
||||
if CONF_TEMPERATURE in config:
|
||||
conf = config[CONF_TEMPERATURE]
|
||||
sensor.register_sensor(dev.Pmake_temperature_sensor(conf[CONF_NAME]), conf)
|
||||
if CONF_HUMIDITY in config:
|
||||
conf = config[CONF_HUMIDITY]
|
||||
sensor.register_sensor(dev.Pmake_humidity_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)
|
||||
|
|
Loading…
Reference in a new issue