mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-01 18:48:28 +02:00
Add sun_gtil2 component (for SUN-1000G2 / SUN-2000G2 grid tie inverters) (#4958)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import text_sensor
|
||||
from esphome.const import CONF_STATE
|
||||
from . import SunGTIL2Component, CONF_SUN_GTIL2_ID
|
||||
|
||||
CONF_SERIAL_NUMBER = "serial_number"
|
||||
|
||||
CONFIG_SCHEMA = cv.All(
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(CONF_SUN_GTIL2_ID): cv.use_id(SunGTIL2Component),
|
||||
cv.Optional(CONF_STATE): text_sensor.text_sensor_schema(
|
||||
text_sensor.TextSensor
|
||||
),
|
||||
cv.Optional(CONF_SERIAL_NUMBER): text_sensor.text_sensor_schema(
|
||||
text_sensor.TextSensor
|
||||
),
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
hub = await cg.get_variable(config[CONF_SUN_GTIL2_ID])
|
||||
if state_config := config.get(CONF_STATE):
|
||||
sens = await text_sensor.new_text_sensor(state_config)
|
||||
cg.add(hub.set_state(sens))
|
||||
if serial_number_config := config.get(CONF_SERIAL_NUMBER):
|
||||
sens = await text_sensor.new_text_sensor(serial_number_config)
|
||||
cg.add(hub.set_serial_number(sens))
|
||||
Reference in New Issue
Block a user