app_status: Initial commit
This commit is contained in:
27
components/app_status/README.md
Normal file
27
components/app_status/README.md
Normal file
@@ -0,0 +1,27 @@
|
||||
This should simply return app status.
|
||||
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
binary_sensor:
|
||||
- platform: app_status
|
||||
name: App warning state
|
||||
detect_status: warning
|
||||
|
||||
- platform: app_status
|
||||
name: App error state
|
||||
detect_status: error
|
||||
|
||||
- platform: app_status
|
||||
name: App error or warning state
|
||||
detect_status:
|
||||
- warning
|
||||
- error
|
||||
|
||||
- platform: app_status
|
||||
name: App ok
|
||||
detect_status:
|
||||
- warning
|
||||
- error
|
||||
inverted: true
|
||||
```
|
||||
26
components/app_status/app_status.cpp
Normal file
26
components/app_status/app_status.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "esphome/core/log.h"
|
||||
#include "app_status.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace app_status {
|
||||
|
||||
static const char *TAG = "app_status.binary_sensor";
|
||||
|
||||
void AppStatusBinarySensor::setup() {
|
||||
|
||||
}
|
||||
|
||||
void AppStatusBinarySensor::update() {
|
||||
ESP_LOGV(TAG, "update() called; inverted = %s", TRUEFALSE(this->inverted_));
|
||||
this->publish_state(this->inverted_); // XXX
|
||||
}
|
||||
|
||||
void AppStatusBinarySensor::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "App status binary sensor");
|
||||
ESP_LOGCONFIG(TAG, " inverted = %s", TRUEFALSE(this->inverted_));
|
||||
}
|
||||
|
||||
} // namespace app_status
|
||||
} // namespace esphome
|
||||
|
||||
// vim:set sw=2:
|
||||
28
components/app_status/app_status.h
Normal file
28
components/app_status/app_status.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/component/binary_sensor/binary_sensor.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace app_status {
|
||||
|
||||
class AppStatusBinarySensor : public binary_sensor_::BinarySensor, public PollingComponent {
|
||||
public:
|
||||
//void loop() override;
|
||||
void setup() override;
|
||||
void update() override;
|
||||
void dump_config() override;
|
||||
|
||||
//float get_loop_priority() const override { return 50.0f; }
|
||||
|
||||
void set_inverted(bool value) { this->inverted = value; }
|
||||
|
||||
protected:
|
||||
uint8_t last_app_state_(0xFF);
|
||||
bool inverted_(false);
|
||||
};
|
||||
|
||||
} // namespace app_status
|
||||
} // namespace esphome
|
||||
|
||||
// vim:set sw=2:
|
||||
29
components/app_status/binary_sensor.py
Normal file
29
components/app_status/binary_sensor.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# dlitz 2025
|
||||
# Ref: https://github.com/esphome/starter-components/blob/main/components/empty_binary_sensor/binary_sensor.py
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import binary_sensor
|
||||
from esphome.const import CONF_ID
|
||||
|
||||
from enum import IntEnum
|
||||
class DetectStatusEnum(IntEnum):
|
||||
warning = 1
|
||||
error = 2
|
||||
|
||||
CONF_DETECT_STATUS = "detect_status"
|
||||
CONF_INVERTED = "inverted"
|
||||
|
||||
app_status_ns = cg.esphome_ns.namespace("app_status")
|
||||
AppStatusBinarySensor = app_status_ns.class_("AppStatusBinarySensor", binary_sensor.BinarySensor, cg.PollingComponent)
|
||||
|
||||
#CONFIG_SCHEMA = binary_sensor.binary_sensor_schema(AppStatusBinarySensor).extend({cv.GenerateID(): cv.declare_id(AppStatusBinarySensor)}).extend(cv.COMPONENT_SCHEMA)
|
||||
CONFIG_SCHEMA = binary_sensor.binary_sensor_schema(AppStatusBinarySensor).extend({
|
||||
cv.GenerateID(): cv.declare_id(AppStatusBinarySensor),
|
||||
#cv.Optional(CONF_DETECT_STATUS, default=["warning", "error"]): cv.ensure_list(cv.enum({e.name: e.value for e in DetectStatusEnum})),
|
||||
cv.Optional(CONF_INVERTED, default=False): cv.boolean,
|
||||
}).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
async def to_code(config):
|
||||
var = await binary_sensor.new_binary_sensor(config)
|
||||
await cg.register_component(var, config)
|
||||
cg.add(var.set_inverted(config[CONF_INVERTED]))
|
||||
Reference in New Issue
Block a user