Skip to content

Commit 9556b9c

Browse files
Antonio ...claude
andcommitted
diag: v2.2.2 — console logging for charging detection
Banner/tile can show "not charging" while a charging-power sensor reads charging. Add browser-console diagnostics to pinpoint the break: - setConfig one-shot: prints charging_power_entity / _entities / charger_status_entity / phase_mode actually present in the card config (reveals a stale auto-dashboard config that never received the sensor). - _isDrawingNow throttled live log: per-change dump of each mapped entity's raw state + unit_of_measurement + computed watts, the summed total, the 200 W floor, basis (measured vs status fallback), and the drawing_now verdict. Purely additive logging; no behaviour change. Backend chain verified correct (reconfigure merges CONF_CHARGING_POWER; dashboard_manager maps it). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 370380b commit 9556b9c

4 files changed

Lines changed: 81 additions & 8 deletions

File tree

‎CLAUDE.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,23 @@ async def _set_amperage(self, target_amperage: int):
756756

757757
## Version History
758758

759+
### v2.2.2 (2026-06-01)
760+
**DIAGNOSTIC: console logging for charging detection (banner/tile stuck on "not charging")**
761+
762+
**Problem**: a user mapped a charging-power sensor that was clearly reporting charging, yet the dashboard's green banner and the "Charging Power" tile both showed "not charging". Frontend-only, so the chain (config → card config → `_isDrawingNow`) had to be inspected live.
763+
764+
**Added** ([frontend/ev-smart-charger-dashboard.js](custom_components/ev_smart_charger/frontend/ev-smart-charger-dashboard.js)):
765+
- **One-shot config dump** in `setConfig` — `[EVSC Dashboard] charging detection config:` prints `charging_power_entity` / `charging_power_entities` / `charger_status_entity` / `phase_mode`. If these read `(missing)` the card config is stale (reload the Lovelace page; if still missing, restart HA — the auto-dashboard card config is rewritten on setup).
766+
- **Throttled live diagnostic** from `_isDrawingNow` — `[EVSC Dashboard] charging detection:` prints, per change, the mapped entity/entities, each **raw state + unit_of_measurement + computed watts**, the summed `measured_total_watts`, the 200 W `floor_watts`, the `basis` (measured-power vs status-fallback), the `charger_status_state`, and the final `drawing_now`. Logs only when something changes (no console spam).
767+
768+
This makes the two most likely causes self-evident: (a) the sensor not reaching the card config (stale dashboard), or (b) a unit/value issue — e.g. a kW sensor with no `unit_of_measurement` attribute read as watts (3.7 W < the 200 W floor → "not charging").
769+
770+
**Backend verified** unchanged and correct: the reconfigure flow merges `CONF_CHARGING_POWER` into `entry.data` (`_merge_entry_data`), and `dashboard_manager._build_card_config` maps it to `charging_power_entity` (+ per-phase `charging_power_entities`). No behaviour change — purely additive console logging. **Files**: `frontend/ev-smart-charger-dashboard.js`, `const.py`, `manifest.json`. `VERSION = "2.2.2"`.
771+
772+
**Upgrade priority**: 🟢 RECOMMENDED if your charging banner/tile is stuck on "not charging" with a power sensor mapped — open the browser console (DevTools) after reloading the dashboard and read the two `[EVSC Dashboard] charging detection…` lines.
773+
774+
---
775+
759776
### v2.2.1 (2026-06-01)
760777
**FIX: Touch scroll stuck on dashboard cards (could only scroll on empty gaps)**
761778

‎custom_components/ev_smart_charger/const.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# ========== INTEGRATION METADATA ==========
44
DOMAIN = "ev_smart_charger"
5-
VERSION = "2.2.1"
5+
VERSION = "2.2.2"
66
DEFAULT_NAME = "EV Smart Charger"
77
FRONTEND_URL_BASE = "/api/ev_smart_charger/frontend"
88
FRONTEND_CARD_FILENAME = "ev-smart-charger-dashboard.js"

‎custom_components/ev_smart_charger/frontend/ev-smart-charger-dashboard.js‎

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,19 @@ class EvSmartChargerDashboard extends HTMLElement {
10371037
home_battery_soc_entity_in_card_config: config?.home_battery_soc_entity || "(missing)",
10381038
}
10391039
);
1040+
// v2.2.1: one-shot charging-detection diagnostic. Instantly answers
1041+
// "did my charging-power sensor reach the card config?" — if these read
1042+
// "(missing)" the auto-dashboard config is stale: reload the Lovelace page,
1043+
// and if still missing restart HA (the card config is rewritten on setup).
1044+
console.info(
1045+
"[EVSC Dashboard] charging detection config:",
1046+
{
1047+
charging_power_entity: config?.charging_power_entity || "(missing)",
1048+
charging_power_entities_3phase: config?.charging_power_entities || "(missing / single-phase)",
1049+
charger_status_entity_fallback: config?.charger_status_entity || "(missing)",
1050+
phase_mode: config?.phase_mode || "single",
1051+
}
1052+
);
10401053
}
10411054

10421055
// Reset discovery and render caches — the configured prefix may have changed.
@@ -1535,13 +1548,56 @@ class EvSmartChargerDashboard extends HTMLElement {
15351548
*/
15361549
_isDrawingNow() {
15371550
const w = this._measuredChargingW();
1538-
if (w != null) return w > CHARGING_POWER_DRAWING_FLOOR_W;
1539-
const status = this._stateObj(this._config.charger_status_entity)?.state;
1540-
if (status == null || status === "unknown" || status === "unavailable") {
1541-
return false;
1551+
let result;
1552+
if (w != null) {
1553+
result = w > CHARGING_POWER_DRAWING_FLOOR_W;
1554+
} else {
1555+
const status = this._stateObj(this._config.charger_status_entity)?.state;
1556+
if (status == null || status === "unknown" || status === "unavailable") {
1557+
result = false;
1558+
} else {
1559+
const IDLE_STATUSES = new Set(["charger_free", "charger_end", "charger_wait"]);
1560+
result = !IDLE_STATUSES.has(status);
1561+
}
15421562
}
1543-
const IDLE_STATUSES = new Set(["charger_free", "charger_end", "charger_wait"]);
1544-
return !IDLE_STATUSES.has(status);
1563+
this._logChargingState(w, result);
1564+
return result;
1565+
}
1566+
1567+
/**
1568+
* v2.2.1: live charging-detection diagnostic. Logs to the browser console the
1569+
* mapped charging-power entity/entities, each raw state + unit, the watts the
1570+
* card computed, the 200 W floor comparison, and the final verdict — so a user
1571+
* whose banner/tile say "not charging" while the sensor reads charging can see
1572+
* exactly where the chain breaks. Throttled: logs only when something changes.
1573+
*/
1574+
_logChargingState(measuredW, drawingNow) {
1575+
if (typeof console === "undefined") return;
1576+
const single = this._config.charging_power_entity;
1577+
const arr = this._config.charging_power_entities;
1578+
const ids = Array.isArray(arr) && arr.length ? arr : (single ? [single] : []);
1579+
const perEntity = ids.map((id) => {
1580+
const obj = this._stateObj(id);
1581+
return {
1582+
entity: id,
1583+
state: obj ? obj.state : "(entity not found in hass)",
1584+
unit: obj?.attributes?.unit_of_measurement ?? "(no unit)",
1585+
watts: this._powerW(id),
1586+
};
1587+
});
1588+
const statusState = this._stateObj(this._config.charger_status_entity)?.state;
1589+
const snapshot = {
1590+
mapped_charging_power: ids.length ? perEntity : "(no charging-power sensor in card config)",
1591+
measured_total_watts: measuredW,
1592+
floor_watts: CHARGING_POWER_DRAWING_FLOOR_W,
1593+
basis: measuredW != null ? "measured-power" : "status-fallback",
1594+
charger_status_state: statusState ?? "(not mapped)",
1595+
drawing_now: drawingNow,
1596+
};
1597+
const sig = JSON.stringify(snapshot);
1598+
if (sig === this._lastChargeDbgSig) return; // throttle: only on change
1599+
this._lastChargeDbgSig = sig;
1600+
console.info("[EVSC Dashboard] charging detection:", snapshot);
15451601
}
15461602

15471603
_computeChargingPowerKw() {

‎custom_components/ev_smart_charger/manifest.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
"iot_class": "local_push",
1212
"issue_tracker": "https://github.com/antbald/ha-ev-smart-charger/issues",
1313
"requirements": [],
14-
"version": "2.2.1"
14+
"version": "2.2.2"
1515
}

0 commit comments

Comments
 (0)