1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-29 16:42:19 +01:00

Make home_assistant imported sensors internal by default (#3372)

This commit is contained in:
Jesse Hills
2022-04-11 12:45:15 +12:00
committed by GitHub
parent 9e3e34acf5
commit efa6fd03e5
4 changed files with 43 additions and 46 deletions

View File

@@ -1,12 +1,11 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import sensor
from esphome.const import (
CONF_ATTRIBUTE,
CONF_ENTITY_ID,
CONF_ID,
from .. import (
HOME_ASSISTANT_IMPORT_SCHEMA,
homeassistant_ns,
setup_home_assistant_entity,
)
from .. import homeassistant_ns
DEPENDENCIES = ["api"]
@@ -14,19 +13,12 @@ HomeassistantSensor = homeassistant_ns.class_(
"HomeassistantSensor", sensor.Sensor, cg.Component
)
CONFIG_SCHEMA = sensor.sensor_schema(HomeassistantSensor, accuracy_decimals=1,).extend(
{
cv.Required(CONF_ENTITY_ID): cv.entity_id,
cv.Optional(CONF_ATTRIBUTE): cv.string,
}
CONFIG_SCHEMA = sensor.sensor_schema(HomeassistantSensor, accuracy_decimals=1).extend(
HOME_ASSISTANT_IMPORT_SCHEMA
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
var = await sensor.new_sensor(config)
await cg.register_component(var, config)
await sensor.register_sensor(var, config)
cg.add(var.set_entity_id(config[CONF_ENTITY_ID]))
if CONF_ATTRIBUTE in config:
cg.add(var.set_attribute(config[CONF_ATTRIBUTE]))
setup_home_assistant_entity(var, config)