|
| 1 | +dofile("drivers/tests/lua_harness/host_mock.lua") |
| 2 | +-- A charger with no car draws nothing. Easee records TotalPower only on |
| 3 | +-- change, so after a start with no car the cloud may hold none for hours; |
| 4 | +-- op_mode 1 from a vouched read is then the power reading: 0 W (#289). |
| 5 | +local function start() |
| 6 | + host.reset() |
| 7 | + host._millis_step = 0 |
| 8 | + host._http_responses["/accounts/login"] = '{"accessToken":"test","expiresIn":3600}' |
| 9 | + host._http_responses["/config"] = '{"maxChargerCurrent":16}' |
| 10 | + host._http_responses["/sessions/ongoing"] = '{}' |
| 11 | + dofile("drivers/lua/easee_cloud.lua") |
| 12 | + driver_init({ email="[email protected]", password="test", serial="TEST123"}) |
| 13 | +end |
| 14 | +local function poll(mode, mode_at, w, stamp) |
| 15 | + local list = {{id=109,value=mode,timestamp=mode_at},{id=121,value=12.5,timestamp=mode_at}} |
| 16 | + if w ~= nil then table.insert(list, {id=120,value=w,timestamp=stamp}) end |
| 17 | + host._http_responses["/observations?ids="] = host.json_encode(list) |
| 18 | + host._millis_counter = host._millis_counter + 5000 |
| 19 | + driver_poll() |
| 20 | + local rows=host._emitted.ev or {} |
| 21 | + return #rows, rows[#rows] |
| 22 | +end |
| 23 | +local function idle(row, at, why) |
| 24 | + assert(row.w==0 and row.connected==false and row.is_online,why..": not an empty, online charger") |
| 25 | + assert(row.control_power_available and row.control_power_confirmed,why..": 0 W not known") |
| 26 | + assert(row.control_power_observed_at==at,why..": wrong source time "..tostring(row.control_power_observed_at)) |
| 27 | + assert(row.power_observed_at==nil,why..": power_observed_at "..tostring(row.power_observed_at)) |
| 28 | + assert(row.power_max_age_s==180,why..": power_max_age_s changed") |
| 29 | +end |
| 30 | + |
| 31 | +-- 1. A start with no car, and no TotalPower in the cloud. |
| 32 | +start() |
| 33 | +local count, row = poll(1,"2026-11-28T06:00:00Z") |
| 34 | +assert(count==1,"a disconnected charger emitted nothing") |
| 35 | +idle(row,"2026-11-28T06:00:00Z","start with no car") |
| 36 | +count, row = poll(1,"2026-11-28T06:00:00Z") |
| 37 | +assert(count==2,"a steady disconnected charger stopped emitting") |
| 38 | +idle(row,"2026-11-28T06:00:00Z","unchanged disconnect") |
| 39 | +-- An unreadable op_mode time leaves power unknown, as before. |
| 40 | +count, row = poll(1,"invalid") |
| 41 | +assert(count==3 and row.w==0,"no sample for a disconnected charger") |
| 42 | +assert(not row.control_power_available and not row.control_power_confirmed, |
| 43 | + "power known without a source time") |
| 44 | + |
| 45 | +-- 2. Charging, then disconnect. A stale TotalPower from the session the |
| 46 | +-- cloud still holds does not leak through: no car, no power. |
| 47 | +start() |
| 48 | +count, row = poll(3,"2026-11-28T07:00:00Z",7.2,"2026-11-28T07:00:05Z") |
| 49 | +assert(count==1 and row.w==7200 and row.control_power_confirmed,"charging power missing") |
| 50 | +count, row = poll(1,"2026-11-28T08:00:00Z",7.2,"2026-11-28T07:00:05Z") |
| 51 | +assert(count==2,"the disconnect emitted nothing") |
| 52 | +idle(row,"2026-11-28T08:00:00Z","charging then disconnect") |
| 53 | + |
| 54 | +-- 3. Reconnect and charge: TotalPower takes over again, with its own time, |
| 55 | +-- and older power is still refused while the car is connected. |
| 56 | +count, row = poll(3,"2026-11-28T09:00:00Z",6.9,"2026-11-28T09:00:10Z") |
| 57 | +assert(count==3 and row.w==6900 and row.connected and row.charging,"reconnected power missing") |
| 58 | +assert(row.control_power_observed_at=="2026-11-28T09:00:10Z" and row.control_power_confirmed, |
| 59 | + "reconnected power lost its source time") |
| 60 | +assert(row.power_observed_at=="2026-11-28T09:00:10Z","a new value lost power_observed_at") |
| 61 | +local n = poll(3,"2026-11-28T09:00:00Z",0,"2026-11-28T09:00:05Z") |
| 62 | +assert(n==count,"older power replaced newer power after a reconnect") |
| 63 | +n = poll(3,"2026-11-28T09:00:00Z",0,"2026-11-28T09:00:10Z") |
| 64 | +assert(n==count,"conflicting power at one source time was accepted") |
| 65 | +n, row = poll(3,"2026-11-28T09:00:00Z",6.9,"2026-11-28T09:00:10Z") |
| 66 | +assert(n==count+1 and row.w==6900 and row.power_observed_at==nil and row.control_power_confirmed, |
| 67 | + "unchanged power was not confirmed") |
| 68 | +count = n |
| 69 | +n, row = poll(3,"2026-11-28T09:00:00Z",5.1,"2026-11-28T09:01:00Z") |
| 70 | +assert(n==count+1 and row.w==5100,"newer power after a reconnect was refused") |
| 71 | +print("Easee idle power: passed") |
0 commit comments