mirror of
https://github.com/maziggy/bambuddy.git
synced 2026-10-19 15:54:27 +02:00
Binds binary_sensor and reading-carrying sensor entities to a printer and renders their state on its card, worded by Home Assistant's device_class. Optional per-sensor alert condition drives a notification on the transition into the alert state and an opt-in interlock that holds queued prints while alerting -- a hold with a readable waiting_reason, never a failure, and only ever on a sensor that was read successfully. Sensors get their own table rather than a wider entity pattern on SmartPlug: get_smart_plug_by_printer would otherwise hand the card's power button a door contact to switch. The hold is passed to the model matcher directly rather than merged into busy_printers: _check_auto_drying reads that set as "is currently printing" and would put an idle-but-held printer down the mid-print drying path. The notification_providers migration spells its default FALSE, not 0 -- Postgres rejects an integer default for a boolean and _safe_execute swallows the error.
This commit is contained in:
@@ -279,6 +279,7 @@ async def init_db():
|
||||
print_log,
|
||||
print_queue,
|
||||
printer,
|
||||
printer_ha_sensor,
|
||||
printer_sensor_history,
|
||||
project,
|
||||
project_bom,
|
||||
@@ -3996,6 +3997,18 @@ async def run_migrations(conn):
|
||||
)
|
||||
await _migrate_backfill_variant_groups(conn)
|
||||
|
||||
# Migration: Home Assistant sensor alerts (#1148). The printer_ha_sensors
|
||||
# table itself is new, so create_all() builds it; only the provider opt-in
|
||||
# column needs adding to existing databases.
|
||||
#
|
||||
# DEFAULT FALSE, not DEFAULT 0: Postgres will not take an integer default
|
||||
# for a boolean column, and _safe_execute swallows the DatatypeMismatchError
|
||||
# — so the older "BOOLEAN DEFAULT 0" migrations above quietly do nothing on
|
||||
# Postgres and only work there because create_all() builds the column on a
|
||||
# fresh install. SQLite has understood FALSE since 3.23, so this spelling
|
||||
# is the one that actually applies on both.
|
||||
await _safe_execute(conn, "ALTER TABLE notification_providers ADD COLUMN on_ha_sensor_alert BOOLEAN DEFAULT FALSE")
|
||||
|
||||
|
||||
async def _migrate_backfill_variant_groups(conn) -> None:
|
||||
"""Build variant groups from the slice provenance already on disk (#671 / #2570).
|
||||
|
||||
Reference in New Issue
Block a user