1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-20 17:48:17 +00:00

40 lines
1.9 KiB
Python
Raw Normal View History

🏗 Merge C++ into python codebase (#504) ## Description: Move esphome-core codebase into esphome (and a bunch of other refactors). See https://github.com/esphome/feature-requests/issues/97 Yes this is a shit ton of work and no there's no way to automate it :( But it will be worth it 👍 Progress: - Core support (file copy etc): 80% - Base Abstractions (light, switch): ~50% - Integrations: ~10% - Working? Yes, (but only with ported components). Other refactors: - Moves all codegen related stuff into a single class: `esphome.codegen` (imported as `cg`) - Rework coroutine syntax - Move from `component/platform.py` to `domain/component.py` structure as with HA - Move all defaults out of C++ and into config validation. - Remove `make_...` helpers from Application class. Reason: Merge conflicts with every single new integration. - Pointer Variables are stored globally instead of locally in setup(). Reason: stack size limit. Future work: - Rework const.py - Move all `CONF_...` into a conf class (usage `conf.UPDATE_INTERVAL` vs `CONF_UPDATE_INTERVAL`). Reason: Less convoluted import block - Enable loading from `custom_components` folder. **Related issue (if applicable):** https://github.com/esphome/feature-requests/issues/97 **Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs#<esphome-docs PR number goes here> ## Checklist: - [ ] The code change is tested and works locally. - [ ] Tests have been added to verify that the new code works (under `tests/` folder). If user exposed functionality or configuration variables are added/changed: - [ ] Documentation added/updated in [esphomedocs](https://github.com/OttoWinter/esphomedocs).
2019-04-17 12:06:00 +02:00
import esphome.codegen as cg
import esphome.config_validation as cv
2019-05-08 09:58:03 +02:00
from esphome.components import sensor, esp32_ble_tracker
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
from esphome.const import CONF_SERVICE_UUID, CONF_MAC_ADDRESS, CONF_ID, \
DEVICE_CLASS_SIGNAL_STRENGTH, UNIT_DECIBEL, ICON_EMPTY
🏗 Merge C++ into python codebase (#504) ## Description: Move esphome-core codebase into esphome (and a bunch of other refactors). See https://github.com/esphome/feature-requests/issues/97 Yes this is a shit ton of work and no there's no way to automate it :( But it will be worth it 👍 Progress: - Core support (file copy etc): 80% - Base Abstractions (light, switch): ~50% - Integrations: ~10% - Working? Yes, (but only with ported components). Other refactors: - Moves all codegen related stuff into a single class: `esphome.codegen` (imported as `cg`) - Rework coroutine syntax - Move from `component/platform.py` to `domain/component.py` structure as with HA - Move all defaults out of C++ and into config validation. - Remove `make_...` helpers from Application class. Reason: Merge conflicts with every single new integration. - Pointer Variables are stored globally instead of locally in setup(). Reason: stack size limit. Future work: - Rework const.py - Move all `CONF_...` into a conf class (usage `conf.UPDATE_INTERVAL` vs `CONF_UPDATE_INTERVAL`). Reason: Less convoluted import block - Enable loading from `custom_components` folder. **Related issue (if applicable):** https://github.com/esphome/feature-requests/issues/97 **Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs#<esphome-docs PR number goes here> ## Checklist: - [ ] The code change is tested and works locally. - [ ] Tests have been added to verify that the new code works (under `tests/` folder). If user exposed functionality or configuration variables are added/changed: - [ ] Documentation added/updated in [esphomedocs](https://github.com/OttoWinter/esphomedocs).
2019-04-17 12:06:00 +02:00
DEPENDENCIES = ['esp32_ble_tracker']
ble_rssi_ns = cg.esphome_ns.namespace('ble_rssi')
BLERSSISensor = ble_rssi_ns.class_('BLERSSISensor', sensor.Sensor, cg.Component,
2019-05-08 09:58:03 +02:00
esp32_ble_tracker.ESPBTDeviceListener)
🏗 Merge C++ into python codebase (#504) ## Description: Move esphome-core codebase into esphome (and a bunch of other refactors). See https://github.com/esphome/feature-requests/issues/97 Yes this is a shit ton of work and no there's no way to automate it :( But it will be worth it 👍 Progress: - Core support (file copy etc): 80% - Base Abstractions (light, switch): ~50% - Integrations: ~10% - Working? Yes, (but only with ported components). Other refactors: - Moves all codegen related stuff into a single class: `esphome.codegen` (imported as `cg`) - Rework coroutine syntax - Move from `component/platform.py` to `domain/component.py` structure as with HA - Move all defaults out of C++ and into config validation. - Remove `make_...` helpers from Application class. Reason: Merge conflicts with every single new integration. - Pointer Variables are stored globally instead of locally in setup(). Reason: stack size limit. Future work: - Rework const.py - Move all `CONF_...` into a conf class (usage `conf.UPDATE_INTERVAL` vs `CONF_UPDATE_INTERVAL`). Reason: Less convoluted import block - Enable loading from `custom_components` folder. **Related issue (if applicable):** https://github.com/esphome/feature-requests/issues/97 **Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs#<esphome-docs PR number goes here> ## Checklist: - [ ] The code change is tested and works locally. - [ ] Tests have been added to verify that the new code works (under `tests/` folder). If user exposed functionality or configuration variables are added/changed: - [ ] Documentation added/updated in [esphomedocs](https://github.com/OttoWinter/esphomedocs).
2019-04-17 12:06:00 +02:00
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
CONFIG_SCHEMA = cv.All(
sensor.sensor_schema(UNIT_DECIBEL, ICON_EMPTY, 0, DEVICE_CLASS_SIGNAL_STRENGTH).extend({
cv.GenerateID(): cv.declare_id(BLERSSISensor),
cv.Optional(CONF_MAC_ADDRESS): cv.mac_address,
cv.Optional(CONF_SERVICE_UUID): esp32_ble_tracker.bt_uuid,
}).extend(
esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA
).extend(cv.COMPONENT_SCHEMA), cv.has_exactly_one_key(CONF_MAC_ADDRESS, CONF_SERVICE_UUID))
🏗 Merge C++ into python codebase (#504) ## Description: Move esphome-core codebase into esphome (and a bunch of other refactors). See https://github.com/esphome/feature-requests/issues/97 Yes this is a shit ton of work and no there's no way to automate it :( But it will be worth it 👍 Progress: - Core support (file copy etc): 80% - Base Abstractions (light, switch): ~50% - Integrations: ~10% - Working? Yes, (but only with ported components). Other refactors: - Moves all codegen related stuff into a single class: `esphome.codegen` (imported as `cg`) - Rework coroutine syntax - Move from `component/platform.py` to `domain/component.py` structure as with HA - Move all defaults out of C++ and into config validation. - Remove `make_...` helpers from Application class. Reason: Merge conflicts with every single new integration. - Pointer Variables are stored globally instead of locally in setup(). Reason: stack size limit. Future work: - Rework const.py - Move all `CONF_...` into a conf class (usage `conf.UPDATE_INTERVAL` vs `CONF_UPDATE_INTERVAL`). Reason: Less convoluted import block - Enable loading from `custom_components` folder. **Related issue (if applicable):** https://github.com/esphome/feature-requests/issues/97 **Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs#<esphome-docs PR number goes here> ## Checklist: - [ ] The code change is tested and works locally. - [ ] Tests have been added to verify that the new code works (under `tests/` folder). If user exposed functionality or configuration variables are added/changed: - [ ] Documentation added/updated in [esphomedocs](https://github.com/OttoWinter/esphomedocs).
2019-04-17 12:06:00 +02:00
def to_code(config):
2019-05-08 09:58:03 +02:00
var = cg.new_Pvariable(config[CONF_ID])
🏗 Merge C++ into python codebase (#504) ## Description: Move esphome-core codebase into esphome (and a bunch of other refactors). See https://github.com/esphome/feature-requests/issues/97 Yes this is a shit ton of work and no there's no way to automate it :( But it will be worth it 👍 Progress: - Core support (file copy etc): 80% - Base Abstractions (light, switch): ~50% - Integrations: ~10% - Working? Yes, (but only with ported components). Other refactors: - Moves all codegen related stuff into a single class: `esphome.codegen` (imported as `cg`) - Rework coroutine syntax - Move from `component/platform.py` to `domain/component.py` structure as with HA - Move all defaults out of C++ and into config validation. - Remove `make_...` helpers from Application class. Reason: Merge conflicts with every single new integration. - Pointer Variables are stored globally instead of locally in setup(). Reason: stack size limit. Future work: - Rework const.py - Move all `CONF_...` into a conf class (usage `conf.UPDATE_INTERVAL` vs `CONF_UPDATE_INTERVAL`). Reason: Less convoluted import block - Enable loading from `custom_components` folder. **Related issue (if applicable):** https://github.com/esphome/feature-requests/issues/97 **Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs#<esphome-docs PR number goes here> ## Checklist: - [ ] The code change is tested and works locally. - [ ] Tests have been added to verify that the new code works (under `tests/` folder). If user exposed functionality or configuration variables are added/changed: - [ ] Documentation added/updated in [esphomedocs](https://github.com/OttoWinter/esphomedocs).
2019-04-17 12:06:00 +02:00
yield cg.register_component(var, config)
2019-05-08 09:58:03 +02:00
yield esp32_ble_tracker.register_ble_device(var, config)
🏗 Merge C++ into python codebase (#504) ## Description: Move esphome-core codebase into esphome (and a bunch of other refactors). See https://github.com/esphome/feature-requests/issues/97 Yes this is a shit ton of work and no there's no way to automate it :( But it will be worth it 👍 Progress: - Core support (file copy etc): 80% - Base Abstractions (light, switch): ~50% - Integrations: ~10% - Working? Yes, (but only with ported components). Other refactors: - Moves all codegen related stuff into a single class: `esphome.codegen` (imported as `cg`) - Rework coroutine syntax - Move from `component/platform.py` to `domain/component.py` structure as with HA - Move all defaults out of C++ and into config validation. - Remove `make_...` helpers from Application class. Reason: Merge conflicts with every single new integration. - Pointer Variables are stored globally instead of locally in setup(). Reason: stack size limit. Future work: - Rework const.py - Move all `CONF_...` into a conf class (usage `conf.UPDATE_INTERVAL` vs `CONF_UPDATE_INTERVAL`). Reason: Less convoluted import block - Enable loading from `custom_components` folder. **Related issue (if applicable):** https://github.com/esphome/feature-requests/issues/97 **Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs#<esphome-docs PR number goes here> ## Checklist: - [ ] The code change is tested and works locally. - [ ] Tests have been added to verify that the new code works (under `tests/` folder). If user exposed functionality or configuration variables are added/changed: - [ ] Documentation added/updated in [esphomedocs](https://github.com/OttoWinter/esphomedocs).
2019-04-17 12:06:00 +02:00
yield sensor.register_sensor(var, config)
2019-05-08 09:58:03 +02:00
if CONF_MAC_ADDRESS in config:
cg.add(var.set_address(config[CONF_MAC_ADDRESS].as_hex))
if CONF_SERVICE_UUID in config:
if len(config[CONF_SERVICE_UUID]) == len(esp32_ble_tracker.bt_uuid16_format):
cg.add(var.set_service_uuid16(esp32_ble_tracker.as_hex(config[CONF_SERVICE_UUID])))
elif len(config[CONF_SERVICE_UUID]) == len(esp32_ble_tracker.bt_uuid32_format):
cg.add(var.set_service_uuid32(esp32_ble_tracker.as_hex(config[CONF_SERVICE_UUID])))
elif len(config[CONF_SERVICE_UUID]) == len(esp32_ble_tracker.bt_uuid128_format):
uuid128 = esp32_ble_tracker.as_hex_array(config[CONF_SERVICE_UUID])
cg.add(var.set_service_uuid128(uuid128))