mirror of
https://github.com/nuttytree/ESPHome-Devices.git
synced 2024-08-30 18:12:19 +00:00
1b6d90d399
* Temporarily disable the heater * Shell of new garage fridge component * Core code should be mostly complete * Add power monitoring and freezer temp control * Wrap up core temperature management code * Add fixed InkBird component * The new fridge manages temp in the freezer better so we are able to greatly simplify things * Finish garage fridge * Misc changes Co-authored-by: Chris Nussbaum <chris.nussbaum@protolabs.com>
61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
from esphome.components import light, sensor
|
|
from esphome import pins
|
|
import esphome.config_validation as cv
|
|
import esphome.codegen as cg
|
|
from esphome.const import (
|
|
CONF_OUTPUT_ID,
|
|
CONF_PIN,
|
|
CONF_POWER,
|
|
UNIT_WATT,
|
|
DEVICE_CLASS_POWER,
|
|
STATE_CLASS_MEASUREMENT,
|
|
ICON_FLASH,
|
|
CONF_UPDATE_INTERVAL,
|
|
)
|
|
|
|
DEPENDENCIES = ["api"]
|
|
|
|
CONF_LIGHT_WATTAGE = "light_wattage"
|
|
|
|
light_ns = cg.esphome_ns.namespace("light")
|
|
TreoLight = light_ns.class_("TreoLedPoolLight", light.LightOutput, cg.PollingComponent)
|
|
|
|
CONFIG_SCHEMA = cv.All(
|
|
light.LIGHT_SCHEMA.extend(
|
|
{
|
|
cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(TreoLight),
|
|
cv.Required(CONF_PIN): pins.gpio_output_pin_schema,
|
|
cv.Optional(CONF_POWER): sensor.sensor_schema(
|
|
unit_of_measurement=UNIT_WATT,
|
|
accuracy_decimals=1,
|
|
device_class=DEVICE_CLASS_POWER,
|
|
state_class=STATE_CLASS_MEASUREMENT,
|
|
icon=ICON_FLASH,
|
|
).extend(
|
|
{
|
|
cv.Optional(CONF_LIGHT_WATTAGE): cv.positive_float,
|
|
cv.Optional(CONF_UPDATE_INTERVAL, default="60s"): cv.update_interval,
|
|
}
|
|
),
|
|
}
|
|
).extend(cv.COMPONENT_SCHEMA),
|
|
)
|
|
|
|
|
|
async def to_code(config):
|
|
var = cg.new_Pvariable(config[CONF_OUTPUT_ID])
|
|
await cg.register_component(var, config)
|
|
await light.register_light(var, config)
|
|
|
|
pin = await cg.gpio_pin_expression(config[CONF_PIN])
|
|
cg.add(var.set_pin(pin))
|
|
|
|
if CONF_POWER in config:
|
|
power_config = config[CONF_POWER]
|
|
power_sensor = await sensor.new_sensor(power_config)
|
|
cg.add(var.set_light_wattage(power_config[CONF_LIGHT_WATTAGE]))
|
|
cg.add(var.set_power_sensor(power_sensor))
|
|
cg.add(var.set_update_interval(power_config[CONF_UPDATE_INTERVAL]))
|
|
else:
|
|
cg.add(var.set_update_interval(4294967295)) # uint32_t max
|