Public Access
refactor: rename component from nut_ups to ups_hid
Signed-off-by: bullshit <coding@ow-software.pl>
This commit is contained in:
24 files changed
+1077
-1000
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import text_sensor
|
||||
from esphome.const import (
|
||||
CONF_TYPE,
|
||||
)
|
||||
|
||||
from . import ups_hid_ns, UpsHidComponent, CONF_UPS_HID_ID
|
||||
|
||||
DEPENDENCIES = ["ups_hid"]
|
||||
|
||||
UpsHidTextSensor = ups_hid_ns.class_(
|
||||
"UpsHidTextSensor", text_sensor.TextSensor, cg.Component
|
||||
)
|
||||
|
||||
TEXT_SENSOR_TYPES = [
|
||||
"model",
|
||||
"manufacturer",
|
||||
"status",
|
||||
"protocol",
|
||||
"serial_number",
|
||||
"firmware_version",
|
||||
]
|
||||
|
||||
|
||||
CONFIG_SCHEMA = text_sensor.text_sensor_schema(UpsHidTextSensor).extend(
|
||||
{
|
||||
cv.GenerateID(CONF_UPS_HID_ID): cv.use_id(UpsHidComponent),
|
||||
cv.Required(CONF_TYPE): cv.one_of(*TEXT_SENSOR_TYPES, lower=True),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
parent = await cg.get_variable(config[CONF_UPS_HID_ID])
|
||||
var = await text_sensor.new_text_sensor(config)
|
||||
await cg.register_component(var, config)
|
||||
|
||||
sensor_type = config[CONF_TYPE]
|
||||
cg.add(var.set_sensor_type(sensor_type))
|
||||
cg.add(parent.register_text_sensor(var, sensor_type))
|
||||
Reference in new issue
Block a user