mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 16:38:16 +01:00
feature request 398 add 'hide timestamp' option for version text sensor (#1085)
Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
This commit is contained in:
parent
ed5f207eba
commit
e41ea42074
5 changed files with 20 additions and 4 deletions
|
@ -1,14 +1,15 @@
|
|||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import text_sensor
|
||||
from esphome.const import CONF_ID, CONF_ICON, ICON_NEW_BOX
|
||||
from esphome.const import CONF_ID, CONF_ICON, ICON_NEW_BOX, CONF_HIDE_TIMESTAMP
|
||||
|
||||
version_ns = cg.esphome_ns.namespace('version')
|
||||
VersionTextSensor = version_ns.class_('VersionTextSensor', text_sensor.TextSensor, cg.Component)
|
||||
|
||||
CONFIG_SCHEMA = text_sensor.TEXT_SENSOR_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_id(VersionTextSensor),
|
||||
cv.Optional(CONF_ICON, default=ICON_NEW_BOX): text_sensor.icon
|
||||
cv.Optional(CONF_ICON, default=ICON_NEW_BOX): text_sensor.icon,
|
||||
cv.Optional(CONF_HIDE_TIMESTAMP, default=False): cv.boolean
|
||||
}).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
|
@ -16,3 +17,4 @@ def to_code(config):
|
|||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield text_sensor.register_text_sensor(var, config)
|
||||
yield cg.register_component(var, config)
|
||||
cg.add(var.set_hide_timestamp(config[CONF_HIDE_TIMESTAMP]))
|
||||
|
|
|
@ -8,9 +8,15 @@ namespace version {
|
|||
|
||||
static const char *TAG = "version.text_sensor";
|
||||
|
||||
void VersionTextSensor::setup() { this->publish_state(ESPHOME_VERSION " " + App.get_compilation_time()); }
|
||||
void VersionTextSensor::setup() {
|
||||
if (this->hide_timestamp_) {
|
||||
this->publish_state(ESPHOME_VERSION);
|
||||
} else {
|
||||
this->publish_state(ESPHOME_VERSION " " + App.get_compilation_time());
|
||||
}
|
||||
}
|
||||
float VersionTextSensor::get_setup_priority() const { return setup_priority::DATA; }
|
||||
|
||||
void VersionTextSensor::set_hide_timestamp(bool hide_timestamp) { this->hide_timestamp_ = hide_timestamp; }
|
||||
std::string VersionTextSensor::unique_id() { return get_mac_address() + "-version"; }
|
||||
void VersionTextSensor::dump_config() { LOG_TEXT_SENSOR("", "Version Text Sensor", this); }
|
||||
|
||||
|
|
|
@ -8,10 +8,14 @@ namespace version {
|
|||
|
||||
class VersionTextSensor : public text_sensor::TextSensor, public Component {
|
||||
public:
|
||||
void set_hide_timestamp(bool hide_timestamp);
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
float get_setup_priority() const override;
|
||||
std::string unique_id() override;
|
||||
|
||||
protected:
|
||||
bool hide_timestamp_{false};
|
||||
};
|
||||
|
||||
} // namespace version
|
||||
|
|
|
@ -201,6 +201,7 @@ CONF_HEAT_ACTION = 'heat_action'
|
|||
CONF_HEAT_MODE = 'heat_mode'
|
||||
CONF_HEATER = 'heater'
|
||||
CONF_HIDDEN = 'hidden'
|
||||
CONF_HIDE_TIMESTAMP = 'hide_timestamp'
|
||||
CONF_HIGH = 'high'
|
||||
CONF_HIGH_VOLTAGE_REFERENCE = 'high_voltage_reference'
|
||||
CONF_HOUR = 'hour'
|
||||
|
|
|
@ -1749,6 +1749,9 @@ text_sensor:
|
|||
name: "BSSID"
|
||||
mac_address:
|
||||
name: "Mac Address"
|
||||
- platform: version
|
||||
name: "ESPHome Version No Timestamp"
|
||||
hide_timestamp: True
|
||||
|
||||
sn74hc595:
|
||||
- id: 'sn74hc595_hub'
|
||||
|
|
Loading…
Reference in a new issue