Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions components/crow_alarm_panel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ button:

### `switch`

Output control or standalone bypass toggle.
Output control, standalone bypass toggle, or raw-frame log toggle.

```yaml
switch:
Expand All @@ -215,14 +215,24 @@ switch:
type: bypass
zone: 3
name: "Bypass Back Door"

- platform: crow_alarm_panel
type: log_raw_frames
name: "Raw Frame Logging"
```

| Variable | Required | Description |
|----------|----------|-------------|
| `type` | yes | `output` — panel output relay; `bypass` — zone bypass toggle |
| `type` | yes | `output` — panel output relay; `bypass` — zone bypass toggle; `log_raw_frames` — runtime raw-frame log toggle |
| `output` | if `type: output` | Output number |
| `zone` | if `type: bypass` | Zone number (1–16) |

The `log_raw_frames` switch is a pure software toggle — no bus traffic, no restored state
across reboots (always starts off). While on, it forces the raw-frame log line ("Received raw
frame [...]") to also log at `INFO` instead of requiring `VERBOSE`, so raw traffic can be
inspected at runtime without recompiling with a higher logger level. Defaults to the
`mdi:text-box-search-outline` icon; set `icon:` to override.

---

## Logging
Expand Down
6 changes: 5 additions & 1 deletion components/crow_alarm_panel/crow_alarm_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,11 @@ void CrowAlarmPanel::loop() {
this->store_.data_length = 0;
}

ESP_LOGV(TAG, "Received raw frame [%02x.%s]", type, format_hex_pretty(data).c_str());
if (this->raw_frame_logging_enabled_) {
ESP_LOGI(TAG, "Received raw frame [%02x.%s]", type, format_hex_pretty(data).c_str());
} else {
ESP_LOGV(TAG, "Received raw frame [%02x.%s]", type, format_hex_pretty(data).c_str());
}

switch (type) {
case CONTROLLER_STATUS: {
Expand Down
6 changes: 6 additions & 0 deletions components/crow_alarm_panel/crow_alarm_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ class CrowAlarmPanel : public Component {

void keypress(uint8_t key);

// Forces the raw-frame log line (normally VERBOSE-only) to also log at INFO, so it can
// be toggled at runtime without recompiling with a higher logger level.
void set_raw_frame_logging_enabled(bool enabled) { this->raw_frame_logging_enabled_ = enabled; }

protected:
CrowAlarmPanelKeypad find_keypad_(uint8_t address);
bool is_bus_idle_();
Expand Down Expand Up @@ -293,6 +297,8 @@ class CrowAlarmPanel : public Component {
uint8_t arm_disarm_digit_ack_byte_{0};
bool arm_disarm_digit_ack_byte_set_{false};

bool raw_frame_logging_enabled_{false};

CrowAlarmPanelStore store_;
InternalGPIOPin *clock_pin_{nullptr};
InternalGPIOPin *data_pin_{nullptr};
Expand Down
14 changes: 13 additions & 1 deletion components/crow_alarm_panel/switch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import switch
from esphome.const import CONF_ID, CONF_TYPE, CONF_OUTPUT
from esphome.const import CONF_ICON, CONF_ID, CONF_TYPE, CONF_OUTPUT
from .. import (
crow_alarm_panel_ns,
CrowAlarmPanel,
Expand All @@ -13,13 +13,17 @@
DEPENDENCIES = ["crow_alarm_panel"]

CONF_BYPASS = "bypass"
CONF_LOG_RAW_FRAMES = "log_raw_frames"

CrowAlarmPanelSwitch = crow_alarm_panel_ns.class_(
"CrowAlarmPanelSwitch", switch.Switch, cg.Component
)
CrowAlarmPanelOutputSwitch = crow_alarm_panel_ns.class_(
"CrowAlarmPanelOutputSwitch", CrowAlarmPanelSwitch
)
CrowAlarmPanelRawLogSwitch = crow_alarm_panel_ns.class_(
"CrowAlarmPanelRawLogSwitch", CrowAlarmPanelSwitch
)


CROW_SWITCH_SCHEMA = switch.switch_schema(CrowAlarmPanelSwitch).extend(
Expand All @@ -43,6 +47,12 @@
cv.Required(CONF_ZONE): cv.int_range(min=1, max=16),
}
),
CONF_LOG_RAW_FRAMES: CROW_SWITCH_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(CrowAlarmPanelRawLogSwitch),
cv.Optional(CONF_ICON, default="mdi:text-box-search-outline"): cv.icon,
}
),
}
)

Expand All @@ -59,6 +69,8 @@ async def to_code(config):
cg.add(var.set_parent(paren))
cg.add(var.set_zone_number(config[CONF_ZONE]))
cg.add(paren.register_zone_bypass_switch(var, config[CONF_ZONE]))
elif type == CONF_LOG_RAW_FRAMES:
cg.add(var.set_crow_alarm_panel_parent(paren))

await switch.register_switch(var, config)
await cg.register_component(var, config)
13 changes: 13 additions & 0 deletions components/crow_alarm_panel/switch/crow_alarm_panel_switch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,18 @@ void CrowAlarmPanelOutputSwitch::dump_config() {
ESP_LOGCONFIG(TAG, " Output number %d", this->output_number_);
}

void CrowAlarmPanelRawLogSwitch::write_state(bool state) {
if (this->parent_ == nullptr) {
ESP_LOGE(TAG, "Parent not set, ignoring raw log switch command");
return;
}
this->parent_->set_raw_frame_logging_enabled(state);
this->publish_state(state);
}

void CrowAlarmPanelRawLogSwitch::dump_config() {
LOG_SWITCH("", "Crow Alarm Panel Raw Log Switch", this);
}

} // namespace crow_alarm_panel
} // namespace esphome
10 changes: 10 additions & 0 deletions components/crow_alarm_panel/switch/crow_alarm_panel_switch.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,15 @@ class CrowAlarmPanelOutputSwitch : public CrowAlarmPanelSwitch {
uint8_t output_number_{0};
};

// Pure software toggle: no bus traffic, just forces the parent's raw-frame log line to also
// log at INFO regardless of the configured logger level. State isn't restored on boot since
// it's a debug aid, not panel state.
class CrowAlarmPanelRawLogSwitch : public CrowAlarmPanelSwitch {
public:
void dump_config() override;
protected:
void write_state(bool state) override;
};

} // namespace crow_alarm_panel
} // namespace esphome
4 changes: 4 additions & 0 deletions crow_alarm_panel_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,7 @@ switch:
type: bypass
zone: 3
name: "Zone 3 Bypass"
# Toggles raw-frame logging to INFO at runtime, without a VERBOSE logger level.
- platform: crow_alarm_panel
type: log_raw_frames
name: "Raw Frame Logging"