mirror of
https://github.com/esphome/esphome.git
synced 2024-11-30 02:34:12 +01:00
53e0fe8e51
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
38 lines
919 B
Python
38 lines
919 B
Python
import re
|
|
|
|
import esphome.codegen as cg
|
|
import esphome.config_validation as cv
|
|
from esphome.components import uart
|
|
from esphome.const import CONF_ID
|
|
|
|
CODEOWNERS = ["@alengwenus"]
|
|
|
|
DEPENDENCIES = ["uart"]
|
|
|
|
sml_ns = cg.esphome_ns.namespace("sml")
|
|
Sml = sml_ns.class_("Sml", cg.Component, uart.UARTDevice)
|
|
MULTI_CONF = True
|
|
|
|
CONF_SML_ID = "sml_id"
|
|
CONF_OBIS_CODE = "obis_code"
|
|
CONF_SERVER_ID = "server_id"
|
|
|
|
CONFIG_SCHEMA = cv.Schema(
|
|
{
|
|
cv.GenerateID(): cv.declare_id(Sml),
|
|
}
|
|
).extend(uart.UART_DEVICE_SCHEMA)
|
|
|
|
|
|
async def to_code(config):
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
|
await cg.register_component(var, config)
|
|
await uart.register_uart_device(var, config)
|
|
|
|
|
|
def obis_code(value):
|
|
value = cv.string(value)
|
|
match = re.match(r"^\d{1,3}-\d{1,3}:\d{1,3}\.\d{1,3}\.\d{1,3}$", value)
|
|
if match is None:
|
|
raise cv.Invalid(f"{value} is not a valid OBIS code")
|
|
return value
|