esphome/esphome/components/xiaomi_lywsd03mmc/sensor.py

48 lines
2.2 KiB
Python
Raw Normal View History

import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import sensor, esp32_ble_tracker
from esphome.const import CONF_BATTERY_LEVEL, CONF_HUMIDITY, CONF_MAC_ADDRESS, CONF_TEMPERATURE, \
Add default device classes to sensor components (#1533) * Add device_class arg to homeassistant sensor_schema call * Add device_class arg to mqtt_subscribe sensor_schema call * Add device_class arg to dht sensor_schema call * Add device_class arg to dht12 sensor_schema call * Add device_class arg to am2320 sensor_schema call * Add device_class arg to atc_mithermometer sensor_schema call * Add device_class arg to atm90e32 sensor_schema call * Add device_class arg to bh1750 sensor_schema call * Add device_class arg to ble_rssi sensor_schema call * Add device_class arg to bme280 sensor_schema call * Add device_class arg to bme680 sensor_schema call * Add device_class arg to bmp085 sensor_schema call * Add device_class arg to bmp280 sensor_schema call * Add device_class arg to binary_sensor_map sensor_schema call * Add device_class arg to apds9960 sensor_schema call * Add device_class arg to as3935 sensor_schema call * Add device_class arg to ccs811 sensor_schema call * Add device_class arg to cse7766 sensor_schema call * Add device_class arg to ct_clamp sensor_schema call * Add device_class arg to dallas sensor_schema call * Add device_class arg to duty_cycle sensor_schema call * Add device_class arg to esp32_hall sensor_schema call * Add device_class arg to hdc1080 sensor_schema call * Add device_class arg to hlw8012 sensor_schema call * Add device_class arg to hm3301 sensor_schema call * Add device_class arg to hmc5883l sensor_schema call * Add device_class arg to htu21d sensor_schema call * Add device_class arg to hx711 sensor_schema call * Add device_class arg to ina219 sensor_schema call * Add device_class arg to ina226 sensor_schema call * Add device_class arg to ina3221 sensor_schema call * Add device_class arg to ibsth1 sensor_schema call * Add device_class arg to max31855 sensor_schema call * Add device_class arg to max31856 sensor_schema call * Add device_class arg to max31865 sensor_schema call * Add device_class arg to mhz19 sensor_schema call * Add device_class arg to max6675 sensor_schema call * Add device_class arg to mpu6050 sensor_schema call * Add device_class arg to ms5611 sensor_schema call * Add device_class arg to mcp9808 sensor_schema call * Add device_class arg to ntc sensor_schema call * Add device_class arg to pid sensor_schema call * Add device_class arg to pmsx003 sensor_schema call * Add device_class arg to pulse_counter sensor_schema call * Add device_class arg to pulse_width sensor_schema call * Add device_class arg to pzem004t sensor_schema call * Add device_class arg to pzemac sensor_schema call * Add device_class arg to pzemdc sensor_schema call * Add device_class arg to qmc5883l sensor_schema call * Add device_class arg to resistance sensor_schema call * Add device_class arg to rotary_encoder sensor_schema call * Add device_class arg to ruuvitag sensor_schema call * Add device_class arg to scd30 sensor_schema call * Add device_class arg to sds011 sensor_schema call * Add device_class arg to senseair sensor_schema call * Add device_class arg to sgp30 sensor_schema call * Add device_class arg to sht3xd sensor_schema call * Add device_class arg to shtcx sensor_schema call * Add device_class arg to sps30 sensor_schema call * Add device_class arg to sts3x sensor_schema call * Add device_class arg to sun sensor_schema call * Add device_class arg to tcs34725 sensor_schema call * Add device_class arg to teleinfo sensor_schema call * Add device_class arg to template sensor_schema call * Add device_class arg to tmp102 sensor_schema call * Add device_class arg to tmp117 sensor_schema call * Add device_class arg to tsl2561 sensor_schema call * Add device_class arg to tx20 sensor_schema call * Add device_class arg to ultrasonic sensor_schema call * Add device_class arg to uptime sensor_schema call * Add device_class arg to vl53l0x sensor_schema call * Add device_class arg to wifi_signal sensor_schema call * Add device_class arg to xiaomi_cgd1 sensor_schema call * Add device_class arg to xiaomi_cgg1 sensor_schema call * Add device_class arg to xiaomi_gcls002 sensor_schema call * Add device_class arg to xiaomi_hhccjcy01 sensor_schema call * Add device_class arg to xiaomi_hhccpot002 sensor_schema call * Add device_class arg to xiaomi_jqjcy01ym sensor_schema call * Add device_class arg to xiaomi_lywsd02 sensor_schema call * Add device_class arg to xiaomi_lywsd03mmc sensor_schema call * Add device_class arg to xiaomi_lywsdcgq sensor_schema call * Add device_class arg to xiaomi_mhoc401 sensor_schema call * Add device_class arg to xiaomi_mjyd02yla sensor_schema call * Add device_class arg to xiaomi_wx08zm sensor_schema call * Add device_class arg to zyaura sensor_schema call * Add device_class arg to ads1115 sensor_schema call * Add device_class arg to adc sensor_schema call * Add device_class arg to ade7953 sensor_schema call * Add device_class arg to aht10 sensor_schema call * Make args of sensor_schema required * lint Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
2021-02-27 23:28:06 +01:00
UNIT_CELSIUS, ICON_EMPTY, UNIT_PERCENT, DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_HUMIDITY, \
CONF_ID, CONF_BINDKEY, DEVICE_CLASS_BATTERY
Add support for ATC_MiThermometer (#1291) * Add support for additional Xiaomi BLE sensors (#1027) * Revert "Add support for additional Xiaomi BLE sensors (#1027)" This reverts commit b2723830f4ed1e29611e3688a2c9323c1071bc23. * initial ATC Mithermometer component * removed references to xiaomi_ble * temp, humi and batt in % working, todo: battery in mV * report battery level in volt * report battery level again in percent * Add files via upload * add ATC Mithermometer component * remove some comments * fix travis ci build issues * mark codeowner, make functions protected * add newlines, remove spaces * two lines after function or class definition * update codeowners * Bump flake8 from 3.8.3 to 3.8.4 Bumps [flake8](https://gitlab.com/pycqa/flake8) from 3.8.3 to 3.8.4. - [Release notes](https://gitlab.com/pycqa/flake8/tags) - [Commits](https://gitlab.com/pycqa/flake8/compare/3.8.3...3.8.4) Signed-off-by: dependabot[bot] <support@github.com> * Add files via upload * Bump pytest from 6.0.2 to 6.1.1 Bumps [pytest](https://github.com/pytest-dev/pytest) from 6.0.2 to 6.1.1. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/master/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/6.0.2...6.1.1) Signed-off-by: dependabot[bot] <support@github.com> * add ATC battery voltage to test2.yaml * fix lint-python * Bump colorlog from 4.2.1 to 4.4.0 Bumps [colorlog](https://github.com/borntyping/python-colorlog) from 4.2.1 to 4.4.0. - [Release notes](https://github.com/borntyping/python-colorlog/releases) - [Commits](https://github.com/borntyping/python-colorlog/compare/v4.2.1...v4.4.0) Signed-off-by: dependabot[bot] <support@github.com> * Bump voluptuous from 0.11.7 to 0.12.0 Bumps [voluptuous](https://github.com/alecthomas/voluptuous) from 0.11.7 to 0.12.0. - [Release notes](https://github.com/alecthomas/voluptuous/releases) - [Changelog](https://github.com/alecthomas/voluptuous/blob/master/CHANGELOG.md) - [Commits](https://github.com/alecthomas/voluptuous/commits/v0.12.0) Signed-off-by: dependabot[bot] <support@github.com> * restore requirements * move codeowner above dependencies * Revert "restore requirements" This reverts commit 3c9fd8b42183ff251c68404ae5e75d72ded00006. * Revert "Bump voluptuous from 0.11.7 to 0.12.0" This reverts commit 8eb0dba1c3f2fdcad28f6970381021a04a4051e7. * Revert "Bump flake8 from 3.8.3 to 3.8.4" This reverts commit 20952632dba032f70b97c86cac5daa84521c1840. * Revert "Bump colorlog from 4.2.1 to 4.4.0" This reverts commit 87bbf95d860a3213e5c9a909cbf6325f00e9094e. * Revert "Bump pytest from 6.0.2 to 6.1.1" This reverts commit 1b6ed8043137d8e8f38de32824cfa113dbc5a0ec. Co-authored-by: vevsvevs <v-v@mail.ru> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-11-03 18:36:11 +01:00
CODEOWNERS = ['@ahpohl']
DEPENDENCIES = ['esp32_ble_tracker']
AUTO_LOAD = ['xiaomi_ble']
xiaomi_lywsd03mmc_ns = cg.esphome_ns.namespace('xiaomi_lywsd03mmc')
XiaomiLYWSD03MMC = xiaomi_lywsd03mmc_ns.class_('XiaomiLYWSD03MMC',
esp32_ble_tracker.ESPBTDeviceListener,
cg.Component)
CONFIG_SCHEMA = cv.Schema({
cv.GenerateID(): cv.declare_id(XiaomiLYWSD03MMC),
cv.Required(CONF_BINDKEY): cv.bind_key,
cv.Required(CONF_MAC_ADDRESS): cv.mac_address,
Add default device classes to sensor components (#1533) * Add device_class arg to homeassistant sensor_schema call * Add device_class arg to mqtt_subscribe sensor_schema call * Add device_class arg to dht sensor_schema call * Add device_class arg to dht12 sensor_schema call * Add device_class arg to am2320 sensor_schema call * Add device_class arg to atc_mithermometer sensor_schema call * Add device_class arg to atm90e32 sensor_schema call * Add device_class arg to bh1750 sensor_schema call * Add device_class arg to ble_rssi sensor_schema call * Add device_class arg to bme280 sensor_schema call * Add device_class arg to bme680 sensor_schema call * Add device_class arg to bmp085 sensor_schema call * Add device_class arg to bmp280 sensor_schema call * Add device_class arg to binary_sensor_map sensor_schema call * Add device_class arg to apds9960 sensor_schema call * Add device_class arg to as3935 sensor_schema call * Add device_class arg to ccs811 sensor_schema call * Add device_class arg to cse7766 sensor_schema call * Add device_class arg to ct_clamp sensor_schema call * Add device_class arg to dallas sensor_schema call * Add device_class arg to duty_cycle sensor_schema call * Add device_class arg to esp32_hall sensor_schema call * Add device_class arg to hdc1080 sensor_schema call * Add device_class arg to hlw8012 sensor_schema call * Add device_class arg to hm3301 sensor_schema call * Add device_class arg to hmc5883l sensor_schema call * Add device_class arg to htu21d sensor_schema call * Add device_class arg to hx711 sensor_schema call * Add device_class arg to ina219 sensor_schema call * Add device_class arg to ina226 sensor_schema call * Add device_class arg to ina3221 sensor_schema call * Add device_class arg to ibsth1 sensor_schema call * Add device_class arg to max31855 sensor_schema call * Add device_class arg to max31856 sensor_schema call * Add device_class arg to max31865 sensor_schema call * Add device_class arg to mhz19 sensor_schema call * Add device_class arg to max6675 sensor_schema call * Add device_class arg to mpu6050 sensor_schema call * Add device_class arg to ms5611 sensor_schema call * Add device_class arg to mcp9808 sensor_schema call * Add device_class arg to ntc sensor_schema call * Add device_class arg to pid sensor_schema call * Add device_class arg to pmsx003 sensor_schema call * Add device_class arg to pulse_counter sensor_schema call * Add device_class arg to pulse_width sensor_schema call * Add device_class arg to pzem004t sensor_schema call * Add device_class arg to pzemac sensor_schema call * Add device_class arg to pzemdc sensor_schema call * Add device_class arg to qmc5883l sensor_schema call * Add device_class arg to resistance sensor_schema call * Add device_class arg to rotary_encoder sensor_schema call * Add device_class arg to ruuvitag sensor_schema call * Add device_class arg to scd30 sensor_schema call * Add device_class arg to sds011 sensor_schema call * Add device_class arg to senseair sensor_schema call * Add device_class arg to sgp30 sensor_schema call * Add device_class arg to sht3xd sensor_schema call * Add device_class arg to shtcx sensor_schema call * Add device_class arg to sps30 sensor_schema call * Add device_class arg to sts3x sensor_schema call * Add device_class arg to sun sensor_schema call * Add device_class arg to tcs34725 sensor_schema call * Add device_class arg to teleinfo sensor_schema call * Add device_class arg to template sensor_schema call * Add device_class arg to tmp102 sensor_schema call * Add device_class arg to tmp117 sensor_schema call * Add device_class arg to tsl2561 sensor_schema call * Add device_class arg to tx20 sensor_schema call * Add device_class arg to ultrasonic sensor_schema call * Add device_class arg to uptime sensor_schema call * Add device_class arg to vl53l0x sensor_schema call * Add device_class arg to wifi_signal sensor_schema call * Add device_class arg to xiaomi_cgd1 sensor_schema call * Add device_class arg to xiaomi_cgg1 sensor_schema call * Add device_class arg to xiaomi_gcls002 sensor_schema call * Add device_class arg to xiaomi_hhccjcy01 sensor_schema call * Add device_class arg to xiaomi_hhccpot002 sensor_schema call * Add device_class arg to xiaomi_jqjcy01ym sensor_schema call * Add device_class arg to xiaomi_lywsd02 sensor_schema call * Add device_class arg to xiaomi_lywsd03mmc sensor_schema call * Add device_class arg to xiaomi_lywsdcgq sensor_schema call * Add device_class arg to xiaomi_mhoc401 sensor_schema call * Add device_class arg to xiaomi_mjyd02yla sensor_schema call * Add device_class arg to xiaomi_wx08zm sensor_schema call * Add device_class arg to zyaura sensor_schema call * Add device_class arg to ads1115 sensor_schema call * Add device_class arg to adc sensor_schema call * Add device_class arg to ade7953 sensor_schema call * Add device_class arg to aht10 sensor_schema call * Make args of sensor_schema required * lint Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
2021-02-27 23:28:06 +01:00
cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema(UNIT_CELSIUS, ICON_EMPTY, 1,
DEVICE_CLASS_TEMPERATURE),
cv.Optional(CONF_HUMIDITY): sensor.sensor_schema(UNIT_PERCENT, ICON_EMPTY, 0,
DEVICE_CLASS_HUMIDITY),
cv.Optional(CONF_BATTERY_LEVEL): sensor.sensor_schema(UNIT_PERCENT, ICON_EMPTY, 0,
DEVICE_CLASS_BATTERY),
}).extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA).extend(cv.COMPONENT_SCHEMA)
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield cg.register_component(var, config)
yield esp32_ble_tracker.register_ble_device(var, config)
cg.add(var.set_address(config[CONF_MAC_ADDRESS].as_hex))
cg.add(var.set_bindkey(config[CONF_BINDKEY]))
if CONF_TEMPERATURE in config:
sens = yield sensor.new_sensor(config[CONF_TEMPERATURE])
cg.add(var.set_temperature(sens))
if CONF_HUMIDITY in config:
sens = yield sensor.new_sensor(config[CONF_HUMIDITY])
cg.add(var.set_humidity(sens))
if CONF_BATTERY_LEVEL in config:
sens = yield sensor.new_sensor(config[CONF_BATTERY_LEVEL])
cg.add(var.set_battery_level(sens))