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: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

## [Unreleased]

### zaptec_cloud 0.2.2

A refused stand-down now returns `false`. Before, `driver_default_mode`
returned nothing, which Core reads as "stood down", so a charger that kept
charging after a failed 0 A write and a failed pause looked held, and Core
unblocked control and stopped retrying. The driver now returns `true` only
when the 0 A write or the pause held, or when FTW wrote nothing in this run,
and it retries a refused stand-down once a minute instead of every five.
When the pause held but the 0 A write did not, a later resume offers 6 A
instead of the current the charger had before.

`docs/WRITING-A-DRIVER.md` now says that "report held after giving up" is for
a device FTW never steered, not for a charger it commanded.

### alfen 1.1.0

The driver can now steer the charger. It emits `ev` with `DRIVER.capabilities
Expand Down
4 changes: 2 additions & 2 deletions SUPPORT_STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Catalog source is not proof that a target can install or run a driver.
| wallbox | 1.0.3 | blixt-l1 | not_assessed | — | not_recorded | not_assessed |
| zap | 3.1.3 | ftw-core | not_assessed | — | not_recorded | not_assessed |
| zap | 3.1.3 | blixt-l1 | not_assessed | — | not_recorded | not_assessed |
| zaptec_cloud | 0.2.1 | ftw-core | not_assessed | — | not_recorded | not_assessed |
| zaptec_cloud | 0.2.1 | blixt-l1 | not_assessed | — | not_recorded | not_assessed |
| zaptec_cloud | 0.2.2 | ftw-core | not_assessed | — | not_recorded | not_assessed |
| zaptec_cloud | 0.2.2 | blixt-l1 | not_assessed | — | not_recorded | not_assessed |
| zuidwijk_p1 | 1.1.2 | ftw-core | not_assessed | — | not_recorded | not_assessed |
| zuidwijk_p1 | 1.1.2 | blixt-l1 | not_assessed | — | not_recorded | not_assessed |
2 changes: 1 addition & 1 deletion devices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2114,7 +2114,7 @@ manufacturers:
protocols:
- protocol: http
driver: "zaptec_cloud"
version: "0.2.1"
version: "0.2.2"
ders: [ev]
control: true
firmware_versions: ""
Expand Down
11 changes: 11 additions & 0 deletions docs/WRITING-A-DRIVER.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ Once it has given up, report the default as held rather than failed. A
permanent `false` has the watchdog escalate against a device that was never
under control.

That last rule is for a device FTW never steered: a register that is not
there, a block another EMS owns. It does not hold for a device FTW did
command in this run, such as a charger it set to 16 A. Core reads `true` (or
nothing) from `driver_default_mode` as "stood down": it unblocks control and
stops retrying. So once the driver has written, a stand-down the device
refuses returns `false`, and the driver tries the write again no more than
once a minute, returning `false` in between. The write rate stays bounded,
the first write that holds returns `true`, and until then Core keeps the
device marked as out of its hands.
`zaptec_cloud` is the worked example.

```bash
make refused-write-report ID=example
```
Expand Down
37 changes: 24 additions & 13 deletions drivers/lua/zaptec_cloud.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ DRIVER = {
id = "zaptec_cloud",
name = "Zaptec Cloud",
manufacturer = "Zaptec",
version = "0.2.1",
version = "0.2.2",
protocols = { "http" },
capabilities = { "ev" },
description = "Zaptec Go / Go 2 / Pro via Zaptec Cloud. Email + password; optional charger serial. FTW sets the charging current and pauses or resumes.",
Expand Down Expand Up @@ -102,7 +102,7 @@ local REFRESH_MS = 300000
local SMALL_RISE_A = 0.5
local SMALL_RISE_HOLD_MS = 60000
-- After a failed stand-down, try again no sooner than this.
local STAND_DOWN_RETRY_MS = 300000
local STAND_DOWN_RETRY_MS = 60000
-- A positive order on a paused charger resends resume no more often than this.
local RESUME_RETRY_MS = 30000

Expand Down Expand Up @@ -615,25 +615,36 @@ function driver_command(action, power_w, cmd)
end

function driver_default_mode()
-- Stand down when FTW can no longer steer: 0 A and pause. Settles: once
-- done it does nothing until a new order, and a failed try waits before
-- the next one. Core runs this at every start too, and maxChargeCurrent is
-- stored on the charger, so it acts only after FTW wrote a current in this
-- run. A charger FTW never steered keeps the owner's own setting.
if not charger_id or not email or not password then return end
if last_written_a == nil then return end
if stood_down then return end
-- Stand down when FTW can no longer steer: 0 A and pause. Core runs this at
-- every start too, and maxChargeCurrent is stored on the charger, so it acts
-- only after FTW wrote a current in this run; a charger FTW never steered
-- keeps the owner's own setting.
--
-- The return value is what Core believes. true means stood down (or nothing
-- of FTW's to hand back); false keeps Core's control blocked and its
-- recovery retrying. A refused stand-down is false, and the write is tried
-- again no more than once a minute, so it settles without lying.
if not charger_id or not email or not password then return true end
if last_written_a == nil then return true end
if stood_down then return true end
local now = host.millis()
if stand_down_try_ms and now - stand_down_try_ms < STAND_DOWN_RETRY_MS then return end
if stand_down_try_ms and now - stand_down_try_ms < STAND_DOWN_RETRY_MS then return false end
stand_down_try_ms = now
if not ensure_auth() then return end
if not ensure_auth() then return false end
local wrote = write_current(0)
local _, applied = send_command(CMD_PAUSE)
if applied then paused = true end
if wrote then
-- Either holds the car: below 6 A Zaptec allocates nothing, and a paused
-- charger draws nothing.
if wrote or applied then
-- A pause that held over a refused 0 A write leaves the charger's
-- current unknown, so a later resume offers the minimum, not the old one.
if not wrote then last_written_a = nil end
stood_down = true
stand_down_try_ms = nil
return true
end
return false
end

function driver_cleanup()
Expand Down
29 changes: 23 additions & 6 deletions drivers/tests/lua_harness/test_zaptec_cloud_control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -292,24 +292,41 @@ assert(#current_writes() == writes, "the stand-down did not settle")
assert(order(11040, THREE))
driver_default_mode()
assert(last_current() == 0, "a new order must re-arm the stand-down")
-- A refused stand-down waits before it tries again.
-- A refused stand-down says so, waits a minute before it tries again, and
-- says so again until it holds.
boot()
poll(CONNECTED)
assert(order(11040, THREE))
post_fail["/update"] = "HTTP 503: down"
driver_default_mode()
post_fail["/sendCommand/506"] = 'HTTP 500: {"Code":520}'
assert(driver_default_mode() == false, "a refused stand-down must not report held")
local tries = count("/update")
for _ = 1, 5 do driver_default_mode() end
for _ = 1, 5 do assert(driver_default_mode() == false) end
assert(count("/update") == tries, "a refused stand-down retried at once")
later(301000)
driver_default_mode()
later(61000)
assert(driver_default_mode() == false)
assert(count("/update") == tries + 1, "the stand-down never retried")
post_fail = {}
later(61000)
assert(driver_default_mode() == true, "a stand-down that held must report it")
assert(driver_default_mode() == true and count("/update") == tries + 2, "a held stand-down wrote again")
-- A pause that held is enough even when the 0 A write failed.
boot()
poll(CONNECTED)
assert(order(11040, THREE))
post_fail["/update"] = "HTTP 503: down"
assert(driver_default_mode() == true, "a held pause is a stand-down")
post_fail = {}
-- ...and a resume after it offers the minimum, not the old 16 A.
local n_before = #current_writes()
assert(driver_command("ev_resume", 0, nil))
assert(#current_writes() == n_before + 1 and last_current() == 6, "resume after a held pause offered a stale current")

-- Core runs the stand-down at every start: a charger FTW never steered in
-- this run keeps the owner's setting.
boot()
poll(CONNECTED)
for _ = 1, 3 do driver_default_mode() end
for _ = 1, 3 do assert(driver_default_mode() == true) end
assert(#current_writes() == 0 and count("/sendCommand/506") == 0,
"the stand-down touched a charger FTW never steered")

Expand Down
6 changes: 3 additions & 3 deletions index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -826,15 +826,15 @@ drivers:
size_bytes: 30379
sha256: "b11198e45d761599939b8201c0969514bbbbc6c2571dcf56d12959cf9ade2b5d"
- name: "zaptec_cloud"
version: "0.2.1"
version: "0.2.2"
tier: community
protocol: http
connectivity: cloud
setup: [vendor_portal]
ders: [ev]
control: true
size_bytes: 22491
sha256: "ea8157aaef601ad0d00ccdbc917eac4cc77de84e97729cc670ab2ac352d01a7c"
size_bytes: 23059
sha256: "a438e7b2c28c17be1d0eca6511e2e67157dbc1510966ef95ceebe872e24aff58"
- name: "zuidwijk_p1"
version: "1.1.2"
tier: core
Expand Down
6 changes: 3 additions & 3 deletions manifests/zaptec_cloud.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "zaptec_cloud"
version: "0.2.1"
version: "0.2.2"
tier: community
author: "Sourceful Labs AB"
protocol: http
Expand All @@ -16,9 +16,9 @@ tested_devices:
notes: "Zaptec Go / Go 2 / Pro via Zaptec Cloud REST API. Email + password; optional charger serial. Control written from Zaptec's API docs; not yet confirmed on hardware."
min_driver_version: "0.1.0"
min_host_version: "2.0.0"
size_bytes: 22491
size_bytes: 23059
dkb_id: "zaptec_cloud"
sha256: "ea8157aaef601ad0d00ccdbc917eac4cc77de84e97729cc670ab2ac352d01a7c"
sha256: "a438e7b2c28c17be1d0eca6511e2e67157dbc1510966ef95ceebe872e24aff58"
signature: ""

bytecode_sha256: ""
Expand Down
2 changes: 1 addition & 1 deletion support-status.json
Original file line number Diff line number Diff line change
Expand Up @@ -1871,7 +1871,7 @@
},
{
"catalog_source": true,
"catalog_version": "0.2.1",
"catalog_version": "0.2.2",
"driver_id": "zaptec_cloud",
"targets": {
"blixt-l1": {
Expand Down