From 77feba19a20d3733a3d300415d0edcf121c6ed2c Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Sun, 22 Oct 2023 22:57:47 +0100 Subject: [PATCH] Text sensor update --- components/BalboaGL/sensor/BalboaGLSesnor.h | 23 ++++++++++ components/BalboaGL/sensor/__init__.py | 48 +++++++++++++++++++++ components/BalboaGL/sensor/text_sensor.py | 40 ----------------- 3 files changed, 71 insertions(+), 40 deletions(-) create mode 100644 components/BalboaGL/sensor/BalboaGLSesnor.h delete mode 100644 components/BalboaGL/sensor/text_sensor.py diff --git a/components/BalboaGL/sensor/BalboaGLSesnor.h b/components/BalboaGL/sensor/BalboaGLSesnor.h new file mode 100644 index 0000000..c45370d --- /dev/null +++ b/components/BalboaGL/sensor/BalboaGLSesnor.h @@ -0,0 +1,23 @@ +#pragma once + +#include "esphom.h" + +#include "balboaGL.h" + +namespace esphome { + namespace balboa_sensor { + + class BalboaGLStateSensor : public Component, public TextSensor { + public: + void setSpa(balboaGL* spa) { + this->spa = spa; + } + void update() override { + publish_state(status.state.c_ctr()); + } + private: + balboaGL* spa; + + }; + +} \ No newline at end of file diff --git a/components/BalboaGL/sensor/__init__.py b/components/BalboaGL/sensor/__init__.py index e69de29..1777328 100644 --- a/components/BalboaGL/sensor/__init__.py +++ b/components/BalboaGL/sensor/__init__.py @@ -0,0 +1,48 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import text_sensor +from esphome.const import CONF_ID +from esphome.core import coroutine + +from .. import balboagl_ns, CONF_BALBOA_ID, BalboaGL + +AUTO_LOAD = ["text_sensor"] + +DEPENDENCIES = ["BalboaGL"] + +CONF_STATE = "state" +CONF_RAW = "raw" +CONF_LCD = "lcd" + + +balboa_sensor_ns = cg.esphome_ns.namespace('balboa_sensor') +StateInfo = balboa_sensor_ns.class_('BalboaGLStateSensor', text_sensor.TextSensor, cg.Component) +# RawInfo = balboa_sensor_ns.class_('BalboaGLRawSensor', text_sensor.TextSensor, cg.Component) +# LCDInfo = balboa_sensor_ns.class_('BalboaGLLCDSensor', text_sensor.TextSensor, cg.Component) + +CONFIG_SCHEMA = text_sensor.TEXT_SENSOR_SCHEMA.extend( + { + + cv.GenerateID(): cv.declare_id(StateInfo), + cv.GenerateID(CONF_BALBOA_ID): cv.use_id(BalboaGL), + + # cv.Optional(CONF_RAW): text_sensor.TEXT_SENSOR_SCHEMA.extend({ + # cv.GenerateID(): cv.declare_id(RawInfo), + # }), + # cv.Optional(CONF_LCD): text_sensor.TEXT_SENSOR_SCHEMA.extend({ + # cv.GenerateID(): cv.declare_id(LCDInfo), + # }), +}) + +@coroutine +def setup_conf(config, key): + if key in config: + conf = config[key] + var = cg.new_Pvariable(conf[CONF_ID]) + yield cg.register_component(var, conf) + yield text_sensor.register_text_sensor(var, conf) + +def to_code(config): + yield setup_conf(config, CONF_STATE) + # yield setup_conf(config, CONF_RAW) + # yield setup_conf(config, CONF_LCD) diff --git a/components/BalboaGL/sensor/text_sensor.py b/components/BalboaGL/sensor/text_sensor.py deleted file mode 100644 index ad3b4b9..0000000 --- a/components/BalboaGL/sensor/text_sensor.py +++ /dev/null @@ -1,40 +0,0 @@ -import esphome.codegen as cg -import esphome.config_validation as cv -from esphome.components import text_sensor -from esphome.const import CONF_ID -from esphome.core import coroutine - -CONF_STATE = "state" -CONF_RAW = "raw" -CONF_LCD = "lcd" - - -balboa_sensor_ns = cg.esphome_ns.namespace('balboa_sensor') -StateInfo = balboa_sensor_ns.class_('BalboaGLStateSensor', text_sensor.TextSensor, cg.Component) -RawInfo = balboa_sensor_ns.class_('BalboaGLRawSensor', text_sensor.TextSensor, cg.Component) -LCDInfo = balboa_sensor_ns.class_('BalboaGLLCDSensor', text_sensor.TextSensor, cg.Component) - -CONFIG_SCHEMA = cv.Schema({ - cv.Optional(CONF_STATE): text_sensor.TEXT_SENSOR_SCHEMA.extend({ - cv.GenerateID(): cv.declare_id(StateInfo), - }), - cv.Optional(CONF_RAW): text_sensor.TEXT_SENSOR_SCHEMA.extend({ - cv.GenerateID(): cv.declare_id(RawInfo), - }), - cv.Optional(CONF_LCD): text_sensor.TEXT_SENSOR_SCHEMA.extend({ - cv.GenerateID(): cv.declare_id(LCDInfo), - }), -}) - -@coroutine -def setup_conf(config, key): - if key in config: - conf = config[key] - var = cg.new_Pvariable(conf[CONF_ID]) - yield cg.register_component(var, conf) - yield text_sensor.register_text_sensor(var, conf) - -def to_code(config): - yield setup_conf(config, CONF_STATE) - yield setup_conf(config, CONF_RAW) - yield setup_conf(config, CONF_LCD)