diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ebdf51df99..88efa3776e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -126,7 +126,7 @@ test3: - pip install -e . - pip install twine script: - - python setup.py sdist + - python setup.py sdist bdist_wheel - twine upload dist/* tags: - docker diff --git a/MANIFEST.in b/MANIFEST.in index 48ab2418e9..fce59d055c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,17 +1,6 @@ +include LICENSE include README.md -include esphome/dashboard/templates/index.html -include esphome/dashboard/templates/login.html -include esphome/dashboard/static/ace.js -include esphome/dashboard/static/esphome.css -include esphome/dashboard/static/esphome.js -include esphome/dashboard/static/favicon.ico -include esphome/dashboard/static/jquery.min.js -include esphome/dashboard/static/jquery.validate.min.js -include esphome/dashboard/static/jquery-ui.min.js -include esphome/dashboard/static/materialize.min.css -include esphome/dashboard/static/materialize.min.js -include esphome/dashboard/static/materialize-stepper.min.css -include esphome/dashboard/static/materialize-stepper.min.js -include esphome/dashboard/static/mode-yaml.js -include esphome/dashboard/static/theme-dreamweaver.js -include esphome/dashboard/static/ext-searchbox.js +include esphome/dashboard/templates/*.html +include esphome/dashboard/static/*.js +include esphome/dashboard/static/*.css +include esphome/dashboard/static/*.ico diff --git a/esphome/__main__.py b/esphome/__main__.py index ab5ebad42d..c32b9eaee9 100644 --- a/esphome/__main__.py +++ b/esphome/__main__.py @@ -1,7 +1,6 @@ from __future__ import print_function import argparse -from collections import OrderedDict from datetime import datetime import logging import os @@ -348,28 +347,6 @@ def command_clean(args, config): return 0 -def command_hass_config(args, config): - from esphome.components import mqtt as mqtt_component - - _LOGGER.info("This is what you should put in your Home Assistant YAML configuration.") - _LOGGER.info("Please note this is only necessary if you're not using MQTT discovery.") - data = mqtt_component.GenerateHassConfigData(config) - hass_config = OrderedDict() - for domain, component, conf in iter_components(config): - if not hasattr(component, 'to_hass_config'): - continue - func = getattr(component, 'to_hass_config') - ret = func(data, conf) - if not isinstance(ret, (list, tuple)): - ret = [ret] - ret = [x for x in ret if x is not None] - domain_conf = hass_config.setdefault(domain.split('.')[0], []) - domain_conf += ret - - safe_print(yaml_util.dump(hass_config)) - return 0 - - def command_dashboard(args): from esphome.dashboard import dashboard @@ -391,7 +368,6 @@ POST_CONFIG_ACTIONS = { 'clean-mqtt': command_clean_mqtt, 'mqtt-fingerprint': command_mqtt_fingerprint, 'clean': command_clean, - 'hass-config': command_hass_config, } @@ -471,10 +447,6 @@ def parse_args(argv): dashboard.add_argument("--socket", help="Make the dashboard serve under a unix socket", type=str) - subparsers.add_parser('hass-config', - help="Dump the configuration entries that should be added " - "to Home Assistant when not using MQTT discovery.") - return parser.parse_args(argv[1:]) diff --git a/esphome/api/api_pb2.py b/esphome/api/api_pb2.py index 2212db8339..c6c8741f01 100644 --- a/esphome/api/api_pb2.py +++ b/esphome/api/api_pb2.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: api.proto diff --git a/esphome/components/binary_sensor/__init__.py b/esphome/components/binary_sensor/__init__.py index 63016359e0..8d5a563120 100644 --- a/esphome/components/binary_sensor/__init__.py +++ b/esphome/components/binary_sensor/__init__.py @@ -287,16 +287,6 @@ def register_binary_sensor(var, config): CORE.add_job(setup_binary_sensor_core_, binary_sensor_var, config) -def core_to_hass_config(data, config): - ret = mqtt.build_hass_config(data, 'binary_sensor', config, - include_state=True, include_command=False) - if ret is None: - return None - if CONF_DEVICE_CLASS in config: - ret['device_class'] = config[CONF_DEVICE_CLASS] - return ret - - BUILD_FLAGS = '-DUSE_BINARY_SENSOR' CONF_BINARY_SENSOR_IS_ON = 'binary_sensor.is_on' diff --git a/esphome/components/binary_sensor/apds9960.py b/esphome/components/binary_sensor/apds9960.py index ba394f954e..915a35135d 100644 --- a/esphome/components/binary_sensor/apds9960.py +++ b/esphome/components/binary_sensor/apds9960.py @@ -30,7 +30,3 @@ def to_code(config): func = getattr(hub, DIRECTIONS[config[CONF_DIRECTION]]) rhs = func(config[CONF_NAME]) binary_sensor.register_binary_sensor(rhs, config) - - -def to_hass_config(data, config): - return binary_sensor.core_to_hass_config(data, config) diff --git a/esphome/components/binary_sensor/custom.py b/esphome/components/binary_sensor/custom.py index a2b907aaed..af87859e6e 100644 --- a/esphome/components/binary_sensor/custom.py +++ b/esphome/components/binary_sensor/custom.py @@ -33,7 +33,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_CUSTOM_BINARY_SENSOR' - - -def to_hass_config(data, config): - return [binary_sensor.core_to_hass_config(data, sens) for sens in config[CONF_BINARY_SENSORS]] diff --git a/esphome/components/binary_sensor/esp32_ble_tracker.py b/esphome/components/binary_sensor/esp32_ble_tracker.py index 6a66184b47..11df791482 100644 --- a/esphome/components/binary_sensor/esp32_ble_tracker.py +++ b/esphome/components/binary_sensor/esp32_ble_tracker.py @@ -23,7 +23,3 @@ def to_code(config): yield rhs = hub.make_presence_sensor(config[CONF_NAME], make_address_array(config[CONF_MAC_ADDRESS])) binary_sensor.register_binary_sensor(rhs, config) - - -def to_hass_config(data, config): - return binary_sensor.core_to_hass_config(data, config) diff --git a/esphome/components/binary_sensor/esp32_touch.py b/esphome/components/binary_sensor/esp32_touch.py index ecaa30605f..41ba51f956 100644 --- a/esphome/components/binary_sensor/esp32_touch.py +++ b/esphome/components/binary_sensor/esp32_touch.py @@ -56,7 +56,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_ESP32_TOUCH_BINARY_SENSOR' - - -def to_hass_config(data, config): - return binary_sensor.core_to_hass_config(data, config) diff --git a/esphome/components/binary_sensor/gpio.py b/esphome/components/binary_sensor/gpio.py index 361796fa7e..c58d49da55 100644 --- a/esphome/components/binary_sensor/gpio.py +++ b/esphome/components/binary_sensor/gpio.py @@ -29,7 +29,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_GPIO_BINARY_SENSOR' - - -def to_hass_config(data, config): - return binary_sensor.core_to_hass_config(data, config) diff --git a/esphome/components/binary_sensor/homeassistant.py b/esphome/components/binary_sensor/homeassistant.py index 4b5f78335d..1c444d318a 100644 --- a/esphome/components/binary_sensor/homeassistant.py +++ b/esphome/components/binary_sensor/homeassistant.py @@ -24,7 +24,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_HOMEASSISTANT_BINARY_SENSOR' - - -def to_hass_config(data, config): - return binary_sensor.core_to_hass_config(data, config) diff --git a/esphome/components/binary_sensor/mpr121.py b/esphome/components/binary_sensor/mpr121.py index 402d30ec38..b75fe64096 100644 --- a/esphome/components/binary_sensor/mpr121.py +++ b/esphome/components/binary_sensor/mpr121.py @@ -22,7 +22,3 @@ def to_code(config): yield rhs = MPR121Channel.new(config[CONF_NAME], config[CONF_CHANNEL]) binary_sensor.register_binary_sensor(hub.add_channel(rhs), config) - - -def to_hass_config(data, config): - return binary_sensor.core_to_hass_config(data, config) diff --git a/esphome/components/binary_sensor/nextion.py b/esphome/components/binary_sensor/nextion.py index fde96b76c2..793d15de83 100644 --- a/esphome/components/binary_sensor/nextion.py +++ b/esphome/components/binary_sensor/nextion.py @@ -27,7 +27,3 @@ def to_code(config): rhs = hub.make_touch_component(config[CONF_NAME], config[CONF_PAGE_ID], config[CONF_COMPONENT_ID]) binary_sensor.register_binary_sensor(rhs, config) - - -def to_hass_config(data, config): - return binary_sensor.core_to_hass_config(data, config) diff --git a/esphome/components/binary_sensor/pn532.py b/esphome/components/binary_sensor/pn532.py index 4f4e159e87..95cc495008 100644 --- a/esphome/components/binary_sensor/pn532.py +++ b/esphome/components/binary_sensor/pn532.py @@ -43,7 +43,3 @@ def to_code(config): addr = [HexInt(int(x, 16)) for x in config[CONF_UID].split('-')] rhs = hub.make_tag(config[CONF_NAME], addr) binary_sensor.register_binary_sensor(rhs, config) - - -def to_hass_config(data, config): - return binary_sensor.core_to_hass_config(data, config) diff --git a/esphome/components/binary_sensor/rdm6300.py b/esphome/components/binary_sensor/rdm6300.py index 0041ea6d0b..cfd4116095 100644 --- a/esphome/components/binary_sensor/rdm6300.py +++ b/esphome/components/binary_sensor/rdm6300.py @@ -24,7 +24,3 @@ def to_code(config): yield rhs = hub.make_card(config[CONF_NAME], config[CONF_UID]) binary_sensor.register_binary_sensor(rhs, config) - - -def to_hass_config(data, config): - return binary_sensor.core_to_hass_config(data, config) diff --git a/esphome/components/binary_sensor/remote_receiver.py b/esphome/components/binary_sensor/remote_receiver.py index 9d06d22fc3..158c25b7e0 100644 --- a/esphome/components/binary_sensor/remote_receiver.py +++ b/esphome/components/binary_sensor/remote_receiver.py @@ -145,7 +145,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_REMOTE_RECEIVER' - - -def to_hass_config(data, config): - return binary_sensor.core_to_hass_config(data, config) diff --git a/esphome/components/binary_sensor/status.py b/esphome/components/binary_sensor/status.py index f879d9c346..4705eba3d8 100644 --- a/esphome/components/binary_sensor/status.py +++ b/esphome/components/binary_sensor/status.py @@ -22,7 +22,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_STATUS_BINARY_SENSOR' - - -def to_hass_config(data, config): - return binary_sensor.core_to_hass_config(data, config) diff --git a/esphome/components/binary_sensor/template.py b/esphome/components/binary_sensor/template.py index 67b036a2d3..b4ec01c4d3 100644 --- a/esphome/components/binary_sensor/template.py +++ b/esphome/components/binary_sensor/template.py @@ -54,7 +54,3 @@ def binary_sensor_template_publish_to_code(config, action_id, template_arg, args yield None add(action.set_state(template_)) yield action - - -def to_hass_config(data, config): - return binary_sensor.core_to_hass_config(data, config) diff --git a/esphome/components/cover/__init__.py b/esphome/components/cover/__init__.py index 06289ed3d9..9a3c153a03 100644 --- a/esphome/components/cover/__init__.py +++ b/esphome/components/cover/__init__.py @@ -96,10 +96,3 @@ def cover_stop_to_code(config, action_id, template_arg, args): rhs = var.make_stop_action(template_arg) type = StopAction.template(template_arg) yield Pvariable(action_id, rhs, type=type) - - -def core_to_hass_config(data, config): - ret = mqtt.build_hass_config(data, 'cover', config, include_state=True, include_command=True) - if ret is None: - return None - return ret diff --git a/esphome/components/cover/template.py b/esphome/components/cover/template.py index 2cf02ab805..a7e2c19d39 100644 --- a/esphome/components/cover/template.py +++ b/esphome/components/cover/template.py @@ -77,12 +77,3 @@ def cover_template_publish_to_code(config, action_id, template_arg, args): yield None add(action.set_state(template_)) yield action - - -def to_hass_config(data, config): - ret = cover.core_to_hass_config(data, config) - if ret is None: - return None - if CONF_OPTIMISTIC in config: - ret['optimistic'] = config[CONF_OPTIMISTIC] - return ret diff --git a/esphome/components/fan/__init__.py b/esphome/components/fan/__init__.py index 32190f00d1..c8ac83cd72 100644 --- a/esphome/components/fan/__init__.py +++ b/esphome/components/fan/__init__.py @@ -4,9 +4,9 @@ from esphome.automation import ACTION_REGISTRY, maybe_simple_id from esphome.components import mqtt from esphome.components.mqtt import setup_mqtt_component import esphome.config_validation as cv -from esphome.const import CONF_ID, CONF_INTERNAL, CONF_MQTT_ID, CONF_NAME, CONF_OSCILLATING, \ - CONF_OSCILLATION_COMMAND_TOPIC, CONF_OSCILLATION_OUTPUT, CONF_OSCILLATION_STATE_TOPIC, \ - CONF_SPEED, CONF_SPEED_COMMAND_TOPIC, CONF_SPEED_STATE_TOPIC +from esphome.const import CONF_ID, CONF_INTERNAL, CONF_MQTT_ID, CONF_OSCILLATING, \ + CONF_OSCILLATION_COMMAND_TOPIC, CONF_OSCILLATION_STATE_TOPIC, CONF_SPEED, \ + CONF_SPEED_COMMAND_TOPIC, CONF_SPEED_STATE_TOPIC from esphome.core import CORE from esphome.cpp_generator import Pvariable, add, get_variable, templatable from esphome.cpp_types import Action, Application, Component, Nameable, bool_, esphome_ns @@ -130,15 +130,3 @@ def fan_turn_on_to_code(config, action_id, template_arg, args): template_ = FAN_SPEEDS[template_] add(action.set_speed(template_)) yield action - - -def core_to_hass_config(data, config): - ret = mqtt.build_hass_config(data, 'fan', config, include_state=True, include_command=True) - if ret is None: - return None - if CONF_OSCILLATION_OUTPUT in config: - default = mqtt.get_default_topic_for(data, 'fan', config[CONF_NAME], 'oscillation/state') - ret['oscillation_state_topic'] = config.get(CONF_OSCILLATION_STATE_TOPIC, default) - default = mqtt.get_default_topic_for(data, 'fan', config[CONF_NAME], 'oscillation/command') - ret['oscillation_command__topic'] = config.get(CONF_OSCILLATION_COMMAND_TOPIC, default) - return ret diff --git a/esphome/components/fan/binary.py b/esphome/components/fan/binary.py index eb880d5dfb..2b77bf587e 100644 --- a/esphome/components/fan/binary.py +++ b/esphome/components/fan/binary.py @@ -28,7 +28,3 @@ def to_code(config): fan.setup_fan(fan_struct.Pstate, config) setup_component(fan_struct.Poutput, config) - - -def to_hass_config(data, config): - return fan.core_to_hass_config(data, config) diff --git a/esphome/components/fan/speed.py b/esphome/components/fan/speed.py index 5a2bc61140..790f43d7cf 100644 --- a/esphome/components/fan/speed.py +++ b/esphome/components/fan/speed.py @@ -1,6 +1,6 @@ import voluptuous as vol -from esphome.components import fan, mqtt, output +from esphome.components import fan, output import esphome.config_validation as cv from esphome.const import CONF_HIGH, CONF_LOW, CONF_MAKE_ID, CONF_MEDIUM, CONF_NAME, \ CONF_OSCILLATION_OUTPUT, CONF_OUTPUT, CONF_SPEED, CONF_SPEED_COMMAND_TOPIC, \ @@ -42,14 +42,3 @@ def to_code(config): add(fan_struct.Poutput.set_oscillation(oscillation_output)) fan.setup_fan(fan_struct.Pstate, config) - - -def to_hass_config(data, config): - ret = fan.core_to_hass_config(data, config) - if ret is None: - return None - default = mqtt.get_default_topic_for(data, 'fan', config[CONF_NAME], 'speed/state') - ret['speed_state_topic'] = config.get(CONF_SPEED_STATE_TOPIC, default) - default = mqtt.get_default_topic_for(data, 'fan', config[CONF_NAME], 'speed/command') - ret['speed_command__topic'] = config.get(CONF_SPEED_COMMAND_TOPIC, default) - return ret diff --git a/esphome/components/light/__init__.py b/esphome/components/light/__init__.py index 92f9766113..540964980a 100644 --- a/esphome/components/light/__init__.py +++ b/esphome/components/light/__init__.py @@ -499,24 +499,3 @@ def light_turn_on_to_code(config, action_id, template_arg, args): yield None add(action.set_effect(template_)) yield action - - -def core_to_hass_config(data, config, brightness=True, rgb=True, color_temp=True, - white_value=True): - ret = mqtt.build_hass_config(data, 'light', config, include_state=True, include_command=True) - if ret is None: - return None - ret['schema'] = 'json' - if brightness: - ret['brightness'] = True - if rgb: - ret['rgb'] = True - if color_temp: - ret['color_temp'] = True - if white_value: - ret['white_value'] = True - for effect in config.get(CONF_EFFECTS, []): - ret["effect"] = True - effects = ret.setdefault("effect_list", []) - effects.append(next(x for x in effect.values())[CONF_NAME]) - return ret diff --git a/esphome/components/light/binary.py b/esphome/components/light/binary.py index 85b56ab202..522a4f082c 100644 --- a/esphome/components/light/binary.py +++ b/esphome/components/light/binary.py @@ -21,8 +21,3 @@ def to_code(config): light_struct = variable(config[CONF_MAKE_ID], rhs) light.setup_light(light_struct.Pstate, config) setup_component(light_struct.Pstate, config) - - -def to_hass_config(data, config): - return light.core_to_hass_config(data, config, brightness=False, rgb=False, color_temp=False, - white_value=False) diff --git a/esphome/components/light/cwww.py b/esphome/components/light/cwww.py index 9fb4dd0568..19447fdcab 100644 --- a/esphome/components/light/cwww.py +++ b/esphome/components/light/cwww.py @@ -35,8 +35,3 @@ def to_code(config): light_struct = variable(config[CONF_MAKE_ID], rhs) light.setup_light(light_struct.Pstate, config) setup_component(light_struct.Pstate, config) - - -def to_hass_config(data, config): - return light.core_to_hass_config(data, config, brightness=True, rgb=False, color_temp=True, - white_value=False) diff --git a/esphome/components/light/fastled_clockless.py b/esphome/components/light/fastled_clockless.py index 5e46083c3c..df872a6428 100644 --- a/esphome/components/light/fastled_clockless.py +++ b/esphome/components/light/fastled_clockless.py @@ -106,8 +106,3 @@ def to_code(config): REQUIRED_BUILD_FLAGS = '-DUSE_FAST_LED_LIGHT' LIB_DEPS = 'FastLED@3.2.0' - - -def to_hass_config(data, config): - return light.core_to_hass_config(data, config, brightness=True, rgb=True, color_temp=False, - white_value=False) diff --git a/esphome/components/light/fastled_spi.py b/esphome/components/light/fastled_spi.py index 49be646d9a..5abfce21cd 100644 --- a/esphome/components/light/fastled_spi.py +++ b/esphome/components/light/fastled_spi.py @@ -86,8 +86,3 @@ def to_code(config): REQUIRED_BUILD_FLAGS = '-DUSE_FAST_LED_LIGHT' LIB_DEPS = 'FastLED@3.2.0' - - -def to_hass_config(data, config): - return light.core_to_hass_config(data, config, brightness=True, rgb=True, color_temp=False, - white_value=False) diff --git a/esphome/components/light/monochromatic.py b/esphome/components/light/monochromatic.py index 0aecc22312..ca819dd2c8 100644 --- a/esphome/components/light/monochromatic.py +++ b/esphome/components/light/monochromatic.py @@ -24,8 +24,3 @@ def to_code(config): light_struct = variable(config[CONF_MAKE_ID], rhs) light.setup_light(light_struct.Pstate, config) setup_component(light_struct.Pstate, config) - - -def to_hass_config(data, config): - return light.core_to_hass_config(data, config, brightness=True, rgb=False, color_temp=False, - white_value=False) diff --git a/esphome/components/light/neopixelbus.py b/esphome/components/light/neopixelbus.py index 30d7ab7854..be8bc9052a 100644 --- a/esphome/components/light/neopixelbus.py +++ b/esphome/components/light/neopixelbus.py @@ -188,8 +188,3 @@ def to_code(config): REQUIRED_BUILD_FLAGS = '-DUSE_NEO_PIXEL_BUS_LIGHT' LIB_DEPS = 'NeoPixelBus@2.4.1' - - -def to_hass_config(data, config): - return light.core_to_hass_config(data, config, brightness=True, rgb=True, color_temp=False, - white_value='W' in config[CONF_TYPE]) diff --git a/esphome/components/light/partition.py b/esphome/components/light/partition.py index 0495841765..a3b8ecf7b9 100644 --- a/esphome/components/light/partition.py +++ b/esphome/components/light/partition.py @@ -46,7 +46,3 @@ def to_code(config): rhs = App.make_partition_light(config[CONF_NAME], segments) make = variable(config[CONF_MAKE_ID], rhs) light.setup_light(make.Pstate, config) - - -def to_hass_config(data, config): - return light.core_to_hass_config(data, config, brightness=True, rgb=True, color_temp=False) diff --git a/esphome/components/light/rgb.py b/esphome/components/light/rgb.py index 418f4b83c4..77791fdefd 100644 --- a/esphome/components/light/rgb.py +++ b/esphome/components/light/rgb.py @@ -30,8 +30,3 @@ def to_code(config): light_struct = variable(config[CONF_MAKE_ID], rhs) light.setup_light(light_struct.Pstate, config) setup_component(light_struct.Pstate, config) - - -def to_hass_config(data, config): - return light.core_to_hass_config(data, config, brightness=True, rgb=True, color_temp=False, - white_value=False) diff --git a/esphome/components/light/rgbw.py b/esphome/components/light/rgbw.py index 22166f2a47..d421322eb1 100644 --- a/esphome/components/light/rgbw.py +++ b/esphome/components/light/rgbw.py @@ -33,8 +33,3 @@ def to_code(config): light_struct = variable(config[CONF_MAKE_ID], rhs) light.setup_light(light_struct.Pstate, config) setup_component(light_struct.Pstate, config) - - -def to_hass_config(data, config): - return light.core_to_hass_config(data, config, brightness=True, rgb=True, color_temp=False, - white_value=True) diff --git a/esphome/components/light/rgbww.py b/esphome/components/light/rgbww.py index 6ed5556b5a..5af68cb74d 100644 --- a/esphome/components/light/rgbww.py +++ b/esphome/components/light/rgbww.py @@ -63,8 +63,3 @@ def to_code(config): light_struct = variable(config[CONF_MAKE_ID], rhs) light.setup_light(light_struct.Pstate, config) setup_component(light_struct.Pstate, config) - - -def to_hass_config(data, config): - return light.core_to_hass_config(data, config, brightness=True, rgb=True, color_temp=True, - white_value=True) diff --git a/esphome/components/mqtt.py b/esphome/components/mqtt.py index cf309eab10..4c11082531 100644 --- a/esphome/components/mqtt.py +++ b/esphome/components/mqtt.py @@ -1,4 +1,3 @@ -from collections import OrderedDict import re import voluptuous as vol @@ -9,12 +8,11 @@ from esphome.components import logger import esphome.config_validation as cv from esphome.const import CONF_AVAILABILITY, CONF_BIRTH_MESSAGE, CONF_BROKER, CONF_CLIENT_ID, \ CONF_COMMAND_TOPIC, CONF_DISCOVERY, CONF_DISCOVERY_PREFIX, CONF_DISCOVERY_RETAIN, \ - CONF_ESPHOME, CONF_ID, CONF_INTERNAL, CONF_KEEPALIVE, CONF_LEVEL, CONF_LOG_TOPIC, \ - CONF_MQTT, CONF_NAME, CONF_ON_JSON_MESSAGE, CONF_ON_MESSAGE, CONF_PASSWORD, CONF_PAYLOAD, \ - CONF_PAYLOAD_AVAILABLE, CONF_PAYLOAD_NOT_AVAILABLE, CONF_PORT, CONF_QOS, CONF_REBOOT_TIMEOUT, \ - CONF_RETAIN, CONF_SHUTDOWN_MESSAGE, CONF_SSL_FINGERPRINTS, CONF_STATE_TOPIC, CONF_TOPIC, \ - CONF_TOPIC_PREFIX, CONF_TRIGGER_ID, CONF_USERNAME, CONF_WILL_MESSAGE -from esphome.core import EsphomeError + CONF_ID, CONF_KEEPALIVE, CONF_LEVEL, CONF_LOG_TOPIC, CONF_ON_JSON_MESSAGE, CONF_ON_MESSAGE, \ + CONF_PASSWORD, CONF_PAYLOAD, CONF_PAYLOAD_AVAILABLE, CONF_PAYLOAD_NOT_AVAILABLE, CONF_PORT, \ + CONF_QOS, CONF_REBOOT_TIMEOUT, CONF_RETAIN, CONF_SHUTDOWN_MESSAGE, CONF_SSL_FINGERPRINTS, \ + CONF_STATE_TOPIC, CONF_TOPIC, CONF_TOPIC_PREFIX, CONF_TRIGGER_ID, CONF_USERNAME, \ + CONF_WILL_MESSAGE from esphome.cpp_generator import Pvariable, RawExpression, StructInitializer, TemplateArguments, \ add, get_variable, process_lambda, templatable from esphome.cpp_types import Action, App, Component, JsonObjectConstRef, JsonObjectRef, \ @@ -273,61 +271,6 @@ def get_default_topic_for(data, component_type, name, suffix): sanitized_name, suffix) -def build_hass_config(data, component_type, config, include_state=True, include_command=True): - if config.get(CONF_INTERNAL, False): - return None - ret = OrderedDict() - ret['platform'] = 'mqtt' - ret['name'] = config[CONF_NAME] - if include_state: - default = get_default_topic_for(data, component_type, config[CONF_NAME], 'state') - ret['state_topic'] = config.get(CONF_STATE_TOPIC, default) - if include_command: - default = get_default_topic_for(data, component_type, config[CONF_NAME], 'command') - ret['command_topic'] = config.get(CONF_STATE_TOPIC, default) - avail = config.get(CONF_AVAILABILITY, data.availability) - if avail: - ret['availability_topic'] = avail[CONF_TOPIC] - payload_available = avail[CONF_PAYLOAD_AVAILABLE] - if payload_available != 'online': - ret['payload_available'] = payload_available - payload_not_available = avail[CONF_PAYLOAD_NOT_AVAILABLE] - if payload_not_available != 'offline': - ret['payload_not_available'] = payload_not_available - return ret - - -class GenerateHassConfigData(object): - def __init__(self, config): - if 'mqtt' not in config: - raise EsphomeError("Cannot generate Home Assistant MQTT config if MQTT is not " - "used!") - mqtt = config[CONF_MQTT] - self.topic_prefix = mqtt.get(CONF_TOPIC_PREFIX, config[CONF_ESPHOME][CONF_NAME]) - birth_message = mqtt.get(CONF_BIRTH_MESSAGE) - if CONF_BIRTH_MESSAGE not in mqtt: - birth_message = { - CONF_TOPIC: self.topic_prefix + '/status', - CONF_PAYLOAD: 'online', - } - will_message = mqtt.get(CONF_WILL_MESSAGE) - if CONF_WILL_MESSAGE not in mqtt: - will_message = { - CONF_TOPIC: self.topic_prefix + '/status', - CONF_PAYLOAD: 'offline' - } - if not birth_message or not will_message: - self.availability = None - elif birth_message[CONF_TOPIC] != will_message[CONF_TOPIC]: - self.availability = None - else: - self.availability = { - CONF_TOPIC: birth_message[CONF_TOPIC], - CONF_PAYLOAD_AVAILABLE: birth_message[CONF_PAYLOAD], - CONF_PAYLOAD_NOT_AVAILABLE: will_message[CONF_PAYLOAD], - } - - def setup_mqtt_component(obj, config): if CONF_RETAIN in config: add(obj.set_retain(config[CONF_RETAIN])) diff --git a/esphome/components/sensor/__init__.py b/esphome/components/sensor/__init__.py index 297ed1177f..3d7371c03d 100644 --- a/esphome/components/sensor/__init__.py +++ b/esphome/components/sensor/__init__.py @@ -273,21 +273,6 @@ def sensor_in_range_to_code(config, condition_id, template_arg, args): yield cond -def core_to_hass_config(data, config): - ret = mqtt.build_hass_config(data, 'sensor', config, include_state=True, include_command=False) - if ret is None: - return None - if CONF_UNIT_OF_MEASUREMENT in config: - ret['unit_of_measurement'] = config[CONF_UNIT_OF_MEASUREMENT] - if CONF_EXPIRE_AFTER in config: - expire = config[CONF_EXPIRE_AFTER] - if expire is not None: - ret['expire_after'] = expire.total_seconds - if CONF_ICON in config: - ret['icon'] = config[CONF_ICON] - return ret - - def _mean(xs): return sum(xs) / len(xs) diff --git a/esphome/components/sensor/adc.py b/esphome/components/sensor/adc.py index aacc544215..6673d98828 100644 --- a/esphome/components/sensor/adc.py +++ b/esphome/components/sensor/adc.py @@ -56,10 +56,6 @@ def required_build_flags(config): return None -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) - - def includes(config): if config[CONF_PIN] == 'VCC': return 'ADC_MODE(ADC_VCC);' diff --git a/esphome/components/sensor/ads1115.py b/esphome/components/sensor/ads1115.py index e9c3e79452..b7aed3faf1 100644 --- a/esphome/components/sensor/ads1115.py +++ b/esphome/components/sensor/ads1115.py @@ -70,7 +70,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_ADS1115_SENSOR' - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/apds9960.py b/esphome/components/sensor/apds9960.py index 225ab8ed06..10fd832654 100644 --- a/esphome/components/sensor/apds9960.py +++ b/esphome/components/sensor/apds9960.py @@ -29,7 +29,3 @@ def to_code(config): func = getattr(hub, TYPES[config[CONF_TYPE]]) rhs = func(config[CONF_NAME]) sensor.register_sensor(rhs, config) - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/bh1750.py b/esphome/components/sensor/bh1750.py index 5a416a5d01..2b725a24d3 100644 --- a/esphome/components/sensor/bh1750.py +++ b/esphome/components/sensor/bh1750.py @@ -39,7 +39,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_BH1750' - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/ble_rssi.py b/esphome/components/sensor/ble_rssi.py index ccdc157b0e..5a67294637 100644 --- a/esphome/components/sensor/ble_rssi.py +++ b/esphome/components/sensor/ble_rssi.py @@ -24,7 +24,3 @@ def to_code(config): yield rhs = hub.make_rssi_sensor(config[CONF_NAME], make_address_array(config[CONF_MAC_ADDRESS])) sensor.register_sensor(rhs, config) - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/bme280.py b/esphome/components/sensor/bme280.py index d4b8a5e10b..99633afba7 100644 --- a/esphome/components/sensor/bme280.py +++ b/esphome/components/sensor/bme280.py @@ -85,9 +85,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_BME280' - - -def to_hass_config(data, config): - return [sensor.core_to_hass_config(data, config[CONF_TEMPERATURE]), - sensor.core_to_hass_config(data, config[CONF_PRESSURE]), - sensor.core_to_hass_config(data, config[CONF_HUMIDITY])] diff --git a/esphome/components/sensor/bme680.py b/esphome/components/sensor/bme680.py index 285e91564f..42229ddf33 100644 --- a/esphome/components/sensor/bme680.py +++ b/esphome/components/sensor/bme680.py @@ -108,10 +108,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_BME680' - - -def to_hass_config(data, config): - return [sensor.core_to_hass_config(data, config[CONF_TEMPERATURE]), - sensor.core_to_hass_config(data, config[CONF_PRESSURE]), - sensor.core_to_hass_config(data, config[CONF_HUMIDITY]), - sensor.core_to_hass_config(data, config[CONF_GAS_RESISTANCE])] diff --git a/esphome/components/sensor/bmp085.py b/esphome/components/sensor/bmp085.py index 9886ce1766..eb2bb2a303 100644 --- a/esphome/components/sensor/bmp085.py +++ b/esphome/components/sensor/bmp085.py @@ -43,8 +43,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_BMP085_SENSOR' - - -def to_hass_config(data, config): - return [sensor.core_to_hass_config(data, config[CONF_TEMPERATURE]), - sensor.core_to_hass_config(data, config[CONF_PRESSURE])] diff --git a/esphome/components/sensor/bmp280.py b/esphome/components/sensor/bmp280.py index 74deeb9501..d4dac402f2 100644 --- a/esphome/components/sensor/bmp280.py +++ b/esphome/components/sensor/bmp280.py @@ -75,8 +75,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_BMP280' - - -def to_hass_config(data, config): - return [sensor.core_to_hass_config(data, config[CONF_TEMPERATURE]), - sensor.core_to_hass_config(data, config[CONF_PRESSURE])] diff --git a/esphome/components/sensor/cse7766.py b/esphome/components/sensor/cse7766.py index d2d38b8c76..11a31309d5 100644 --- a/esphome/components/sensor/cse7766.py +++ b/esphome/components/sensor/cse7766.py @@ -57,11 +57,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_CSE7766' - - -def to_hass_config(data, config): - ret = [] - for key in (CONF_VOLTAGE, CONF_CURRENT, CONF_POWER): - if key in config: - ret.append(sensor.core_to_hass_config(data, config[key])) - return ret diff --git a/esphome/components/sensor/custom.py b/esphome/components/sensor/custom.py index 3e73ef3581..a4bb1917f1 100644 --- a/esphome/components/sensor/custom.py +++ b/esphome/components/sensor/custom.py @@ -31,7 +31,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_CUSTOM_SENSOR' - - -def to_hass_config(data, config): - return [sensor.core_to_hass_config(data, sens) for sens in config[CONF_SENSORS]] diff --git a/esphome/components/sensor/dallas.py b/esphome/components/sensor/dallas.py index aaf8603344..f798a034ea 100644 --- a/esphome/components/sensor/dallas.py +++ b/esphome/components/sensor/dallas.py @@ -32,7 +32,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_DALLAS_SENSOR' - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/dht.py b/esphome/components/sensor/dht.py index 8cc680d7cc..518960bf0b 100644 --- a/esphome/components/sensor/dht.py +++ b/esphome/components/sensor/dht.py @@ -57,8 +57,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_DHT_SENSOR' - - -def to_hass_config(data, config): - return [sensor.core_to_hass_config(data, config[CONF_TEMPERATURE]), - sensor.core_to_hass_config(data, config[CONF_HUMIDITY])] diff --git a/esphome/components/sensor/dht12.py b/esphome/components/sensor/dht12.py index c457eec803..e52deb5217 100644 --- a/esphome/components/sensor/dht12.py +++ b/esphome/components/sensor/dht12.py @@ -40,8 +40,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_DHT12_SENSOR' - - -def to_hass_config(data, config): - return [sensor.core_to_hass_config(data, config[CONF_TEMPERATURE]), - sensor.core_to_hass_config(data, config[CONF_HUMIDITY])] diff --git a/esphome/components/sensor/duty_cycle.py b/esphome/components/sensor/duty_cycle.py index ed3ae17bcd..9132e1cabb 100644 --- a/esphome/components/sensor/duty_cycle.py +++ b/esphome/components/sensor/duty_cycle.py @@ -29,7 +29,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_DUTY_CYCLE_SENSOR' - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/esp32_hall.py b/esphome/components/sensor/esp32_hall.py index 7cb31c1795..cdad0835f2 100644 --- a/esphome/components/sensor/esp32_hall.py +++ b/esphome/components/sensor/esp32_hall.py @@ -26,7 +26,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_ESP32_HALL_SENSOR' - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/hdc1080.py b/esphome/components/sensor/hdc1080.py index a85f7a1d14..f3cab8663e 100644 --- a/esphome/components/sensor/hdc1080.py +++ b/esphome/components/sensor/hdc1080.py @@ -40,8 +40,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_HDC1080_SENSOR' - - -def to_hass_config(data, config): - return [sensor.core_to_hass_config(data, config[CONF_TEMPERATURE]), - sensor.core_to_hass_config(data, config[CONF_HUMIDITY])] diff --git a/esphome/components/sensor/hlw8012.py b/esphome/components/sensor/hlw8012.py index f5a72e22af..c9e4024b86 100644 --- a/esphome/components/sensor/hlw8012.py +++ b/esphome/components/sensor/hlw8012.py @@ -66,11 +66,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_HLW8012' - - -def to_hass_config(data, config): - ret = [] - for key in (CONF_VOLTAGE, CONF_CURRENT, CONF_POWER): - if key in config: - ret.append(sensor.core_to_hass_config(data, config[key])) - return ret diff --git a/esphome/components/sensor/hmc5883l.py b/esphome/components/sensor/hmc5883l.py index 4ac7a75cf8..154c964cb5 100644 --- a/esphome/components/sensor/hmc5883l.py +++ b/esphome/components/sensor/hmc5883l.py @@ -87,11 +87,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_HMC5883L' - - -def to_hass_config(data, config): - ret = [] - for key in (CONF_FIELD_STRENGTH_X, CONF_FIELD_STRENGTH_Y, CONF_FIELD_STRENGTH_Z, CONF_HEADING): - if key in config: - ret.append(sensor.core_to_hass_config(data, config[key])) - return ret diff --git a/esphome/components/sensor/homeassistant.py b/esphome/components/sensor/homeassistant.py index e282a825c1..1affd67267 100644 --- a/esphome/components/sensor/homeassistant.py +++ b/esphome/components/sensor/homeassistant.py @@ -23,7 +23,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_HOMEASSISTANT_SENSOR' - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/htu21d.py b/esphome/components/sensor/htu21d.py index 07ee0297f1..f95b41c195 100644 --- a/esphome/components/sensor/htu21d.py +++ b/esphome/components/sensor/htu21d.py @@ -41,8 +41,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_HTU21D_SENSOR' - - -def to_hass_config(data, config): - return [sensor.core_to_hass_config(data, config[CONF_TEMPERATURE]), - sensor.core_to_hass_config(data, config[CONF_HUMIDITY])] diff --git a/esphome/components/sensor/hx711.py b/esphome/components/sensor/hx711.py index aab8fff25d..b2544fbb79 100644 --- a/esphome/components/sensor/hx711.py +++ b/esphome/components/sensor/hx711.py @@ -47,7 +47,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_HX711' - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/ina219.py b/esphome/components/sensor/ina219.py index e69057f41d..1cfbd18c48 100644 --- a/esphome/components/sensor/ina219.py +++ b/esphome/components/sensor/ina219.py @@ -66,11 +66,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_INA219' - - -def to_hass_config(data, config): - ret = [] - for key in (CONF_BUS_VOLTAGE, CONF_SHUNT_VOLTAGE, CONF_CURRENT, CONF_POWER): - if key in config: - ret.append(sensor.core_to_hass_config(data, config[key])) - return ret diff --git a/esphome/components/sensor/ina3221.py b/esphome/components/sensor/ina3221.py index 197ba8c6fc..eb19af5e18 100644 --- a/esphome/components/sensor/ina3221.py +++ b/esphome/components/sensor/ina3221.py @@ -77,15 +77,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_INA3221' - - -def to_hass_config(data, config): - ret = [] - for channel in (CONF_CHANNEL_1, CONF_CHANNEL_2, CONF_CHANNEL_3): - if channel not in config: - continue - conf = config[channel] - for key in (CONF_BUS_VOLTAGE, CONF_SHUNT_VOLTAGE, CONF_CURRENT, CONF_POWER): - if key in conf: - ret.append(sensor.core_to_hass_config(data, conf[key])) - return ret diff --git a/esphome/components/sensor/max31855.py b/esphome/components/sensor/max31855.py index 1a57fab1fc..fb03a9778b 100644 --- a/esphome/components/sensor/max31855.py +++ b/esphome/components/sensor/max31855.py @@ -33,7 +33,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_MAX31855_SENSOR' - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/max6675.py b/esphome/components/sensor/max6675.py index 0ea383d4f6..2e09bfe222 100644 --- a/esphome/components/sensor/max6675.py +++ b/esphome/components/sensor/max6675.py @@ -34,7 +34,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_MAX6675_SENSOR' - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/mhz19.py b/esphome/components/sensor/mhz19.py index e051f5b4c4..e70f3d3f8a 100644 --- a/esphome/components/sensor/mhz19.py +++ b/esphome/components/sensor/mhz19.py @@ -45,11 +45,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_MHZ19' - - -def to_hass_config(data, config): - ret = [] - for key in (CONF_CO2, CONF_TEMPERATURE): - if key in config: - ret.append(sensor.core_to_hass_config(data, config[key])) - return ret diff --git a/esphome/components/sensor/mpu6050.py b/esphome/components/sensor/mpu6050.py index 44982f140c..1d9eab7b5d 100644 --- a/esphome/components/sensor/mpu6050.py +++ b/esphome/components/sensor/mpu6050.py @@ -90,12 +90,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_MPU6050' - - -def to_hass_config(data, config): - ret = [] - for key in (CONF_ACCEL_X, CONF_ACCEL_Y, CONF_ACCEL_Z, CONF_GYRO_X, CONF_GYRO_Y, CONF_GYRO_Z, - CONF_TEMPERATURE): - if key in config: - ret.append(sensor.core_to_hass_config(data, config[key])) - return ret diff --git a/esphome/components/sensor/mqtt_subscribe.py b/esphome/components/sensor/mqtt_subscribe.py index 3516e3d627..ee239b46b9 100644 --- a/esphome/components/sensor/mqtt_subscribe.py +++ b/esphome/components/sensor/mqtt_subscribe.py @@ -30,7 +30,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_MQTT_SUBSCRIBE_SENSOR' - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/ms5611.py b/esphome/components/sensor/ms5611.py index cd10b47bb0..38f40187c3 100644 --- a/esphome/components/sensor/ms5611.py +++ b/esphome/components/sensor/ms5611.py @@ -44,8 +44,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_MS5611' - - -def to_hass_config(data, config): - return [sensor.core_to_hass_config(data, config[CONF_TEMPERATURE]), - sensor.core_to_hass_config(data, config[CONF_PRESSURE])] diff --git a/esphome/components/sensor/pmsx003.py b/esphome/components/sensor/pmsx003.py index 8556ad4594..4ad834a4f0 100644 --- a/esphome/components/sensor/pmsx003.py +++ b/esphome/components/sensor/pmsx003.py @@ -95,12 +95,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_PMSX003' - - -def to_hass_config(data, config): - ret = [] - for key in (CONF_PM_1_0, CONF_PM_2_5, CONF_PM_10_0, CONF_TEMPERATURE, CONF_HUMIDITY, - CONF_FORMALDEHYDE): - if key in config: - ret.append(sensor.core_to_hass_config(data, config[key])) - return ret diff --git a/esphome/components/sensor/pulse_counter.py b/esphome/components/sensor/pulse_counter.py index 04b7cee7d5..9488d58734 100644 --- a/esphome/components/sensor/pulse_counter.py +++ b/esphome/components/sensor/pulse_counter.py @@ -76,7 +76,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_PULSE_COUNTER_SENSOR' - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/rotary_encoder.py b/esphome/components/sensor/rotary_encoder.py index 72a5c7ccca..1df4017d8b 100644 --- a/esphome/components/sensor/rotary_encoder.py +++ b/esphome/components/sensor/rotary_encoder.py @@ -70,7 +70,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_ROTARY_ENCODER_SENSOR' - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/sds011.py b/esphome/components/sensor/sds011.py index 317f7143bd..a5436cf0c2 100644 --- a/esphome/components/sensor/sds011.py +++ b/esphome/components/sensor/sds011.py @@ -68,11 +68,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_SDS011' - - -def to_hass_config(data, config): - ret = [] - for key in (CONF_PM_2_5, CONF_PM_10_0): - if key in config: - ret.append(sensor.core_to_hass_config(data, config[key])) - return ret diff --git a/esphome/components/sensor/sht3xd.py b/esphome/components/sensor/sht3xd.py index d873f82ed6..8e3f510220 100644 --- a/esphome/components/sensor/sht3xd.py +++ b/esphome/components/sensor/sht3xd.py @@ -42,8 +42,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_SHT3XD' - - -def to_hass_config(data, config): - return [sensor.core_to_hass_config(data, config[CONF_TEMPERATURE]), - sensor.core_to_hass_config(data, config[CONF_HUMIDITY])] diff --git a/esphome/components/sensor/tcs34725.py b/esphome/components/sensor/tcs34725.py index 6989d3e691..84f289e529 100644 --- a/esphome/components/sensor/tcs34725.py +++ b/esphome/components/sensor/tcs34725.py @@ -102,12 +102,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_TCS34725' - - -def to_hass_config(data, config): - ret = [] - for key in (CONF_RED_CHANNEL, CONF_GREEN_CHANNEL, CONF_BLUE_CHANNEL, CONF_CLEAR_CHANNEL, - CONF_ILLUMINANCE, CONF_COLOR_TEMPERATURE): - if key in config: - ret.append(sensor.core_to_hass_config(data, config[key])) - return ret diff --git a/esphome/components/sensor/template.py b/esphome/components/sensor/template.py index 9a85b07f1e..f17ce680be 100644 --- a/esphome/components/sensor/template.py +++ b/esphome/components/sensor/template.py @@ -52,7 +52,3 @@ def sensor_template_publish_to_code(config, action_id, template_arg, args): yield None add(action.set_state(template_)) yield action - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/total_daily_energy.py b/esphome/components/sensor/total_daily_energy.py index f2c3d5b38b..e90a80c7de 100644 --- a/esphome/components/sensor/total_daily_energy.py +++ b/esphome/components/sensor/total_daily_energy.py @@ -32,7 +32,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_TOTAL_DAILY_ENERGY_SENSOR' - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/tsl2561.py b/esphome/components/sensor/tsl2561.py index 6e26f016ab..fc132b3218 100644 --- a/esphome/components/sensor/tsl2561.py +++ b/esphome/components/sensor/tsl2561.py @@ -63,7 +63,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_TSL2561' - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/ultrasonic.py b/esphome/components/sensor/ultrasonic.py index b7191ca3f1..2812b59989 100644 --- a/esphome/components/sensor/ultrasonic.py +++ b/esphome/components/sensor/ultrasonic.py @@ -52,7 +52,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_ULTRASONIC_SENSOR' - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/uptime.py b/esphome/components/sensor/uptime.py index 33ee717d0f..e6a340dfef 100644 --- a/esphome/components/sensor/uptime.py +++ b/esphome/components/sensor/uptime.py @@ -24,7 +24,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_UPTIME_SENSOR' - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/wifi_signal.py b/esphome/components/sensor/wifi_signal.py index cb5e5a768a..d9b86f5e4b 100644 --- a/esphome/components/sensor/wifi_signal.py +++ b/esphome/components/sensor/wifi_signal.py @@ -24,7 +24,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_WIFI_SIGNAL_SENSOR' - - -def to_hass_config(data, config): - return sensor.core_to_hass_config(data, config) diff --git a/esphome/components/sensor/xiaomi_miflora.py b/esphome/components/sensor/xiaomi_miflora.py index 64e002b9a1..8ce9d8dd52 100644 --- a/esphome/components/sensor/xiaomi_miflora.py +++ b/esphome/components/sensor/xiaomi_miflora.py @@ -42,12 +42,3 @@ def to_code(config): 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 diff --git a/esphome/components/sensor/xiaomi_mijia.py b/esphome/components/sensor/xiaomi_mijia.py index d7fdf17435..f0e2e64ae0 100644 --- a/esphome/components/sensor/xiaomi_mijia.py +++ b/esphome/components/sensor/xiaomi_mijia.py @@ -34,11 +34,3 @@ def to_code(config): 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_HUMIDITY, CONF_BATTERY_LEVEL): - if key in config: - ret.append(sensor.core_to_hass_config(data, config[key])) - return ret diff --git a/esphome/components/switch/__init__.py b/esphome/components/switch/__init__.py index 27527633af..6bcd893bde 100644 --- a/esphome/components/switch/__init__.py +++ b/esphome/components/switch/__init__.py @@ -6,7 +6,7 @@ from esphome.components import mqtt from esphome.components.mqtt import setup_mqtt_component import esphome.config_validation as cv from esphome.const import CONF_ICON, CONF_ID, CONF_INTERNAL, CONF_INVERTED, CONF_MQTT_ID, \ - CONF_ON_TURN_OFF, CONF_ON_TURN_ON, CONF_OPTIMISTIC, CONF_TRIGGER_ID + CONF_ON_TURN_OFF, CONF_ON_TURN_ON, CONF_TRIGGER_ID from esphome.core import CORE from esphome.cpp_generator import Pvariable, add, get_variable from esphome.cpp_types import Action, App, Nameable, Trigger, esphome_ns @@ -149,14 +149,3 @@ def switch_is_off_to_code(config, condition_id, template_arg, args): rhs = var.make_switch_is_off_condition(template_arg) type = SwitchCondition.template(template_arg) yield Pvariable(condition_id, rhs, type=type) - - -def core_to_hass_config(data, config): - ret = mqtt.build_hass_config(data, 'switch', config, include_state=True, include_command=True) - if ret is None: - return None - if CONF_ICON in config: - ret['icon'] = config[CONF_ICON] - if CONF_OPTIMISTIC in config: - ret['optimistic'] = config[CONF_OPTIMISTIC] - return ret diff --git a/esphome/components/switch/custom.py b/esphome/components/switch/custom.py index 1b165f2b18..4ce3fdd1c0 100644 --- a/esphome/components/switch/custom.py +++ b/esphome/components/switch/custom.py @@ -32,7 +32,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_CUSTOM_SWITCH' - - -def to_hass_config(data, config): - return [switch.core_to_hass_config(data, swi) for swi in config[CONF_SWITCHES]] diff --git a/esphome/components/switch/gpio.py b/esphome/components/switch/gpio.py index 4c46315a7e..bd5dbf079e 100644 --- a/esphome/components/switch/gpio.py +++ b/esphome/components/switch/gpio.py @@ -48,7 +48,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_GPIO_SWITCH' - - -def to_hass_config(data, config): - return switch.core_to_hass_config(data, config) diff --git a/esphome/components/switch/output.py b/esphome/components/switch/output.py index 54c5ec6554..750add0a72 100644 --- a/esphome/components/switch/output.py +++ b/esphome/components/switch/output.py @@ -26,7 +26,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_OUTPUT_SWITCH' - - -def to_hass_config(data, config): - return switch.core_to_hass_config(data, config) diff --git a/esphome/components/switch/remote_transmitter.py b/esphome/components/switch/remote_transmitter.py index ef87c8ed83..b55ed73699 100644 --- a/esphome/components/switch/remote_transmitter.py +++ b/esphome/components/switch/remote_transmitter.py @@ -164,7 +164,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_REMOTE_TRANSMITTER' - - -def to_hass_config(data, config): - return switch.core_to_hass_config(data, config) diff --git a/esphome/components/switch/restart.py b/esphome/components/switch/restart.py index 915bfcab50..6aaf52ad6f 100644 --- a/esphome/components/switch/restart.py +++ b/esphome/components/switch/restart.py @@ -21,7 +21,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_RESTART_SWITCH' - - -def to_hass_config(data, config): - return switch.core_to_hass_config(data, config) diff --git a/esphome/components/switch/shutdown.py b/esphome/components/switch/shutdown.py index 10f98a8a9f..e2931170c6 100644 --- a/esphome/components/switch/shutdown.py +++ b/esphome/components/switch/shutdown.py @@ -21,7 +21,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_SHUTDOWN_SWITCH' - - -def to_hass_config(data, config): - return switch.core_to_hass_config(data, config) diff --git a/esphome/components/switch/template.py b/esphome/components/switch/template.py index d8cf325a17..8e1cbd85af 100644 --- a/esphome/components/switch/template.py +++ b/esphome/components/switch/template.py @@ -72,7 +72,3 @@ def switch_template_publish_to_code(config, action_id, template_arg, args): yield None add(action.set_state(template_)) yield action - - -def to_hass_config(data, config): - return switch.core_to_hass_config(data, config) diff --git a/esphome/components/switch/uart.py b/esphome/components/switch/uart.py index 82c79d13d3..fe869eeb2e 100644 --- a/esphome/components/switch/uart.py +++ b/esphome/components/switch/uart.py @@ -44,7 +44,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_UART_SWITCH' - - -def to_hass_config(data, config): - return switch.core_to_hass_config(data, config) diff --git a/esphome/components/text_sensor/__init__.py b/esphome/components/text_sensor/__init__.py index ce5468346d..a4a6caec26 100644 --- a/esphome/components/text_sensor/__init__.py +++ b/esphome/components/text_sensor/__init__.py @@ -63,12 +63,3 @@ def register_text_sensor(var, config): BUILD_FLAGS = '-DUSE_TEXT_SENSOR' - - -def core_to_hass_config(data, config): - ret = mqtt.build_hass_config(data, 'sensor', config, include_state=True, include_command=False) - if ret is None: - return None - if CONF_ICON in config: - ret['icon'] = config[CONF_ICON] - return ret diff --git a/esphome/components/text_sensor/custom.py b/esphome/components/text_sensor/custom.py index 342c08d8fb..5c76cfc9d1 100644 --- a/esphome/components/text_sensor/custom.py +++ b/esphome/components/text_sensor/custom.py @@ -32,7 +32,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_CUSTOM_TEXT_SENSOR' - - -def to_hass_config(data, config): - return [text_sensor.core_to_hass_config(data, sens) for sens in config[CONF_TEXT_SENSORS]] diff --git a/esphome/components/text_sensor/homeassistant.py b/esphome/components/text_sensor/homeassistant.py index bcfe656cb0..422e81cf5e 100644 --- a/esphome/components/text_sensor/homeassistant.py +++ b/esphome/components/text_sensor/homeassistant.py @@ -24,7 +24,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_HOMEASSISTANT_TEXT_SENSOR' - - -def to_hass_config(data, config): - return text_sensor.core_to_hass_config(data, config) diff --git a/esphome/components/text_sensor/mqtt_subscribe.py b/esphome/components/text_sensor/mqtt_subscribe.py index ead467700a..43f41a8ac6 100644 --- a/esphome/components/text_sensor/mqtt_subscribe.py +++ b/esphome/components/text_sensor/mqtt_subscribe.py @@ -31,7 +31,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_MQTT_SUBSCRIBE_TEXT_SENSOR' - - -def to_hass_config(data, config): - return text_sensor.core_to_hass_config(data, config) diff --git a/esphome/components/text_sensor/template.py b/esphome/components/text_sensor/template.py index a3e0986274..d1de6205e5 100644 --- a/esphome/components/text_sensor/template.py +++ b/esphome/components/text_sensor/template.py @@ -53,7 +53,3 @@ def text_sensor_template_publish_to_code(config, action_id, template_arg, args): yield None add(action.set_state(template_)) yield action - - -def to_hass_config(data, config): - return text_sensor.core_to_hass_config(data, config) diff --git a/esphome/components/text_sensor/version.py b/esphome/components/text_sensor/version.py index 3ef73c5dbb..2b95a8c724 100644 --- a/esphome/components/text_sensor/version.py +++ b/esphome/components/text_sensor/version.py @@ -21,7 +21,3 @@ def to_code(config): BUILD_FLAGS = '-DUSE_VERSION_TEXT_SENSOR' - - -def to_hass_config(data, config): - return text_sensor.core_to_hass_config(data, config) diff --git a/esphome/dashboard/dashboard.py b/esphome/dashboard/dashboard.py index adc3a79d0d..a70fe2add2 100644 --- a/esphome/dashboard/dashboard.py +++ b/esphome/dashboard/dashboard.py @@ -3,11 +3,13 @@ from __future__ import print_function import codecs import collections +import hashlib import hmac import json import logging import multiprocessing import os +import shutil import subprocess import threading @@ -28,7 +30,7 @@ from esphome.__main__ import get_serial_ports from esphome.helpers import mkdir_p, get_bool_env, run_system_command from esphome.py_compat import IS_PY2 from esphome.storage_json import EsphomeStorageJSON, StorageJSON, \ - esphome_storage_path, ext_storage_path + esphome_storage_path, ext_storage_path, trash_storage_path from esphome.util import shlex_quote # pylint: disable=unused-import, wrong-import-order @@ -64,6 +66,27 @@ def template_args(): } +def authenticated(func): + def decorator(self, *args, **kwargs): + if not self.is_authenticated(): + self.redirect(RELATIVE_URL + 'login') + return None + return func(self, *args, **kwargs) + return decorator + + +def bind_config(func): + def decorator(self, *args, **kwargs): + configuration = self.get_argument('configuration') + if not is_allowed(configuration): + self.set_status(500) + return None + kwargs = kwargs.copy() + kwargs['configuration'] = configuration + return func(self, *args, **kwargs) + return decorator + + # pylint: disable=abstract-method class BaseHandler(tornado.web.RequestHandler): def is_authenticated(self): @@ -178,10 +201,8 @@ class EsphomeHassConfigHandler(EsphomeCommandWebSocket): class SerialPortRequestHandler(BaseHandler): + @authenticated def get(self): - if not self.is_authenticated(): - self.redirect(RELATIVE_URL + 'login') - return ports = get_serial_ports() data = [] for port, desc in ports: @@ -198,12 +219,10 @@ class SerialPortRequestHandler(BaseHandler): class WizardRequestHandler(BaseHandler): + @authenticated def post(self): from esphome import wizard - if not self.is_authenticated(): - self.redirect(RELATIVE_URL + 'login') - return kwargs = {k: ''.join(v) for k, v in self.request.arguments.items()} destination = os.path.join(CONFIG_DIR, kwargs['name'] + '.yaml') wizard.wizard_write(path=destination, **kwargs) @@ -211,13 +230,10 @@ class WizardRequestHandler(BaseHandler): class DownloadBinaryRequestHandler(BaseHandler): - def get(self): - if not self.is_authenticated(): - self.redirect(RELATIVE_URL + 'login') - return - + @authenticated + @bind_config + def get(self, configuration=None): # pylint: disable=no-value-for-parameter - configuration = self.get_argument('configuration') storage_path = ext_storage_path(CONFIG_DIR, configuration) storage_json = StorageJSON.load(storage_path) if storage_json is None: @@ -315,11 +331,8 @@ class DashboardEntry(object): class MainRequestHandler(BaseHandler): + @authenticated def get(self): - if not self.is_authenticated(): - self.redirect(RELATIVE_URL + 'login') - return - begin = bool(self.get_argument('begin', False)) entries = _list_dashboard_entries() @@ -400,11 +413,8 @@ class PingStatusThread(threading.Thread): class PingRequestHandler(BaseHandler): + @authenticated def get(self): - if not self.is_authenticated(): - self.redirect(RELATIVE_URL + 'login') - return - PING_REQUEST.set() self.write(json.dumps(PING_RESULT)) @@ -414,34 +424,52 @@ def is_allowed(configuration): class EditRequestHandler(BaseHandler): - def get(self): - if not self.is_authenticated(): - self.redirect(RELATIVE_URL + 'login') - return + @authenticated + @bind_config + def get(self, configuration=None): # pylint: disable=no-value-for-parameter - configuration = self.get_argument('configuration') - if not is_allowed(configuration): - self.set_status(401) - return - with open(os.path.join(CONFIG_DIR, configuration), 'r') as f: content = f.read() self.write(content) - def post(self): - if not self.is_authenticated(): - self.redirect(RELATIVE_URL + 'login') - return + @authenticated + @bind_config + def post(self, configuration=None): # pylint: disable=no-value-for-parameter - configuration = self.get_argument('configuration') - if not is_allowed(configuration): - self.set_status(401) - return - with open(os.path.join(CONFIG_DIR, configuration), 'wb') as f: f.write(self.request.body) self.set_status(200) - return + + +class DeleteRequestHandler(BaseHandler): + @authenticated + @bind_config + def post(self, configuration=None): + config_file = os.path.join(CONFIG_DIR, configuration) + storage_path = ext_storage_path(CONFIG_DIR, configuration) + storage_json = StorageJSON.load(storage_path) + if storage_json is None: + self.set_status(500) + return + + name = storage_json.name + trash_path = trash_storage_path(CONFIG_DIR) + mkdir_p(trash_path) + shutil.move(config_file, os.path.join(trash_path, configuration)) + + # Delete build folder (if exists) + build_folder = os.path.join(CONFIG_DIR, name) + if build_folder is not None: + shutil.rmtree(build_folder, os.path.join(trash_path, name)) + + +class UndoDeleteRequestHandler(BaseHandler): + @authenticated + @bind_config + def post(self, configuration=None): + config_file = os.path.join(CONFIG_DIR, configuration) + trash_path = trash_storage_path(CONFIG_DIR) + shutil.move(os.path.join(trash_path, configuration), config_file) PING_RESULT = {} # type: dict @@ -511,9 +539,9 @@ def get_static_file_url(name): else: path = os.path.join(static_path, name) with open(path, 'rb') as f_handle: - hash_ = hash(f_handle.read()) & (2**32-1) + hash_ = hashlib.md5(f_handle.read()).hexdigest()[:8] _STATIC_FILE_HASHES[name] = hash_ - return RELATIVE_URL + u'static/{}?hash={:08X}'.format(name, hash_) + return RELATIVE_URL + u'static/{}?hash={}'.format(name, hash_) def make_app(debug=False): @@ -561,6 +589,8 @@ def make_app(debug=False): (RELATIVE_URL + "download.bin", DownloadBinaryRequestHandler), (RELATIVE_URL + "serial-ports", SerialPortRequestHandler), (RELATIVE_URL + "ping", PingRequestHandler), + (RELATIVE_URL + "delete", DeleteRequestHandler), + (RELATIVE_URL + "undo-delete", UndoDeleteRequestHandler), (RELATIVE_URL + "wizard.html", WizardRequestHandler), (RELATIVE_URL + r"static/(.*)", StaticFileHandler, {'path': static_path}), ], **settings) diff --git a/esphome/dashboard/static/esphome.js b/esphome/dashboard/static/esphome.js index 9c04f4f69e..bd3d006080 100644 --- a/esphome/dashboard/static/esphome.js +++ b/esphome/dashboard/static/esphome.js @@ -590,51 +590,30 @@ document.querySelectorAll(".action-clean").forEach((btn) => { }); }); -const hassConfigModalElem = document.getElementById("modal-hass-config"); - -document.querySelectorAll(".action-hass-config").forEach((btn) => { +document.querySelectorAll(".action-delete").forEach((btn) => { btn.addEventListener('click', (e) => { configuration = e.target.getAttribute('data-node'); - const modalInstance = M.Modal.getInstance(hassConfigModalElem); - const log = hassConfigModalElem.querySelector(".log"); - log.innerHTML = ""; - const colorState = initializeColorState(); - const stopLogsButton = hassConfigModalElem.querySelector(".stop-logs"); - let stopped = false; - stopLogsButton.innerHTML = "Stop"; - modalInstance.open(); - const filenameField = hassConfigModalElem.querySelector('.filename'); - filenameField.innerHTML = configuration; + fetch(`${relative_url}delete?configuration=${configuration}`, { + credentials: "same-origin", + method: "POST", + }).then(res => res.text()).then(() => { + const toastHtml = `Deleted ${configuration} + `; + const toast = M.toast({html: toastHtml}); + const undoButton = toast.el.querySelector('.toast-action'); - const logSocket = new WebSocket(wsUrl + "hass-config"); - logSocket.addEventListener('message', (event) => { - const data = JSON.parse(event.data); - if (data.event === "line") { - colorReplace(log, colorState, data.data); - } else if (data.event === "exit") { - if (data.code === 0) { - M.toast({html: "Program exited successfully."}); - downloadButton.classList.remove('disabled'); - } else { - M.toast({html: `Program failed with code ${data.code}`}); - } - stopLogsButton.innerHTML = "Close"; - stopped = true; - } + document.querySelector(`.entry-row[data-node="${configuration}"]`).remove(); + + undoButton.addEventListener('click', () => { + fetch(`${relative_url}undo-delete?configuration=${configuration}`, { + credentials: "same-origin", + method: "POST", + }).then(res => res.text()).then(() => { + window.location.reload(false); + }); + }); }); - logSocket.addEventListener('open', () => { - const msg = JSON.stringify({configuration: configuration}); - logSocket.send(msg); - }); - logSocket.addEventListener('close', () => { - if (!stopped) { - M.toast({html: 'Terminated process.'}); - } - }); - modalInstance.options.onCloseStart = () => { - logSocket.close(); - }; }); }); diff --git a/esphome/dashboard/templates/index.html b/esphome/dashboard/templates/index.html index dac1c69858..af3dd7a717 100644 --- a/esphome/dashboard/templates/index.html +++ b/esphome/dashboard/templates/index.html @@ -58,7 +58,7 @@
{% for i, entry in enumerate(entries) %} -
+
@@ -422,16 +422,6 @@
- -