Commit c6702d0
fix(gateway): pin EV charger entity ids to the charge point id (#4489)
* fix(gateway): pin EV entity ids to the charge point id
_ev_suffix() returned a bare "ev" when a single charger was visible and
"ev_<id>" only when several were, so the suffix depended on how many chargers
happened to be in one status message. Entity ids therefore moved under the user:
a site with one charger produced sensor.predbat_gateway_ev_power, but the moment
a second charger appeared — or the same charger was briefly seen twice across a
reconnect — everything silently renamed to sensor.predbat_gateway_ev_<id>_power,
orphaning the old entities and every dashboard and automation bound to them.
Seen in production: one hub accumulated both a predbat_gateway_ev_536212_* set
and a predbat_gateway_ev_* set for the same physical charger.
Always identify the charger by the last 6 chars of its charge point id, falling
back to "ev" only when the charger has not reported one yet (no BootNotification).
Renames entities on single-charger sites from sensor.predbat_gateway_ev_* to
sensor.predbat_gateway_ev_<id>_*. These entities only exist on PredBat Gateway
hubs running an OCPP charger; at the time of writing that is two hubs (one of
them a test rig), so no migration is warranted — but any dashboard bound to the
unsuffixed names needs repointing, and the old entities are left orphaned.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* fix(gateway): harden EV entity naming and suppress stale offline telemetry
Follow-up to the entity-id pinning, from an adversarial review of that change.
- Slugify the charge point id before truncating. An OCPP chargePointSerialNumber
is an arbitrary vendor string and may contain spaces, dots, slashes, dashes or
non-ASCII, none of which are legal in a Home Assistant entity id, and nothing
downstream sanitised it. `CP/AB-123` previously produced
sensor.predbat_gateway_ev_ab-123_power, which HA rejects — while auto-config
still pointed car_charging_* at that nonexistent namespace.
- Suppress live-session fields while a charger is disconnected. Only the derived
`connected` sensor was gated on ev.connected; session_active, power, session
energy and the SoC fallback were published straight from the payload. Since
car_charging_now is wired to session_active and PredBat plans whenever it is
true, a disconnected charger carrying a stale session_active would schedule a
charging slot for a charger that is not there. Gateway firmware now zeroes
these, but PredBat and firmware version independently, so gate here too.
- Prefer a connected charger in _register_ev_car() instead of blindly taking
chargers[0]. The gateway now reports known-but-offline chargers rather than
omitting them, so slot 0 can be a stale entry; a site with an old disconnected
charger listed first would have bound all car_charging_* args to it and ignored
the live one. Falls back to the first entry so a charger that is merely offline
right now still registers.
- Update docs/car-charging.md, which still listed all ten entities under the old
unsuffixed names.
Known limitation, documented in the docstring: a 6-char tail is not
collision-proof — two chargers whose slugified ids share a tail map to one
namespace. Identity stability was the priority; anything collision-proof either
depends on which other chargers are present (the churn this fixes) or is an
opaque digest.
Tests: 269 pass, including slugification cases and assertions that a
disconnected charger's session_active/power/session_energy are forced idle.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
* Update car-charging.md for clarity on EV charger entities
Clarified entity naming and registration details for GivEnergy Gateway OCPP EV charger in documentation.
* [pre-commit.ci lite] apply automatic fixes
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Trefor Southwell <48591903+springfall2008@users.noreply.github.com>
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>1 parent 85975ef commit c6702d0
4 files changed
Lines changed: 182 additions & 34 deletions
File tree
- .cspell
- apps/predbat
- tests
- docs
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
442 | 442 | | |
443 | 443 | | |
444 | 444 | | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
445 | 449 | | |
446 | 450 | | |
447 | 451 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
946 | 946 | | |
947 | 947 | | |
948 | 948 | | |
949 | | - | |
950 | | - | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
951 | 976 | | |
952 | 977 | | |
953 | 978 | | |
954 | | - | |
| 979 | + | |
| 980 | + | |
955 | 981 | | |
956 | 982 | | |
957 | | - | |
| 983 | + | |
| 984 | + | |
958 | 985 | | |
959 | | - | |
960 | | - | |
961 | 986 | | |
962 | | - | |
| 987 | + | |
| 988 | + | |
963 | 989 | | |
964 | 990 | | |
965 | 991 | | |
| |||
994 | 1020 | | |
995 | 1021 | | |
996 | 1022 | | |
997 | | - | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
998 | 1034 | | |
999 | 1035 | | |
1000 | | - | |
1001 | | - | |
| 1036 | + | |
| 1037 | + | |
1002 | 1038 | | |
1003 | 1039 | | |
1004 | 1040 | | |
| |||
1011 | 1047 | | |
1012 | 1048 | | |
1013 | 1049 | | |
1014 | | - | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
1015 | 1053 | | |
1016 | 1054 | | |
1017 | 1055 | | |
| |||
1305 | 1343 | | |
1306 | 1344 | | |
1307 | 1345 | | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
1308 | 1351 | | |
1309 | 1352 | | |
1310 | 1353 | | |
1311 | 1354 | | |
1312 | 1355 | | |
1313 | | - | |
| 1356 | + | |
1314 | 1357 | | |
1315 | 1358 | | |
1316 | 1359 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3945 | 3945 | | |
3946 | 3946 | | |
3947 | 3947 | | |
3948 | | - | |
| 3948 | + | |
3949 | 3949 | | |
3950 | 3950 | | |
3951 | 3951 | | |
| |||
3961 | 3961 | | |
3962 | 3962 | | |
3963 | 3963 | | |
| 3964 | + | |
| 3965 | + | |
| 3966 | + | |
| 3967 | + | |
| 3968 | + | |
| 3969 | + | |
| 3970 | + | |
| 3971 | + | |
| 3972 | + | |
| 3973 | + | |
| 3974 | + | |
| 3975 | + | |
| 3976 | + | |
| 3977 | + | |
| 3978 | + | |
| 3979 | + | |
| 3980 | + | |
| 3981 | + | |
| 3982 | + | |
| 3983 | + | |
| 3984 | + | |
| 3985 | + | |
| 3986 | + | |
| 3987 | + | |
| 3988 | + | |
| 3989 | + | |
| 3990 | + | |
| 3991 | + | |
| 3992 | + | |
| 3993 | + | |
| 3994 | + | |
| 3995 | + | |
| 3996 | + | |
| 3997 | + | |
| 3998 | + | |
| 3999 | + | |
| 4000 | + | |
| 4001 | + | |
| 4002 | + | |
| 4003 | + | |
| 4004 | + | |
| 4005 | + | |
| 4006 | + | |
| 4007 | + | |
| 4008 | + | |
| 4009 | + | |
| 4010 | + | |
| 4011 | + | |
| 4012 | + | |
| 4013 | + | |
| 4014 | + | |
| 4015 | + | |
| 4016 | + | |
| 4017 | + | |
| 4018 | + | |
| 4019 | + | |
| 4020 | + | |
| 4021 | + | |
| 4022 | + | |
| 4023 | + | |
| 4024 | + | |
| 4025 | + | |
| 4026 | + | |
| 4027 | + | |
| 4028 | + | |
3964 | 4029 | | |
3965 | 4030 | | |
3966 | 4031 | | |
3967 | 4032 | | |
3968 | 4033 | | |
3969 | 4034 | | |
3970 | | - | |
| 4035 | + | |
3971 | 4036 | | |
3972 | 4037 | | |
3973 | 4038 | | |
| |||
3977 | 4042 | | |
3978 | 4043 | | |
3979 | 4044 | | |
3980 | | - | |
| 4045 | + | |
3981 | 4046 | | |
3982 | 4047 | | |
3983 | 4048 | | |
| |||
3997 | 4062 | | |
3998 | 4063 | | |
3999 | 4064 | | |
4000 | | - | |
| 4065 | + | |
4001 | 4066 | | |
4002 | 4067 | | |
4003 | 4068 | | |
4004 | 4069 | | |
4005 | 4070 | | |
4006 | 4071 | | |
4007 | | - | |
| 4072 | + | |
4008 | 4073 | | |
4009 | 4074 | | |
4010 | 4075 | | |
| |||
4067 | 4132 | | |
4068 | 4133 | | |
4069 | 4134 | | |
| 4135 | + | |
| 4136 | + | |
| 4137 | + | |
| 4138 | + | |
| 4139 | + | |
| 4140 | + | |
| 4141 | + | |
| 4142 | + | |
| 4143 | + | |
| 4144 | + | |
| 4145 | + | |
| 4146 | + | |
| 4147 | + | |
| 4148 | + | |
| 4149 | + | |
| 4150 | + | |
| 4151 | + | |
| 4152 | + | |
| 4153 | + | |
| 4154 | + | |
| 4155 | + | |
| 4156 | + | |
| 4157 | + | |
| 4158 | + | |
| 4159 | + | |
| 4160 | + | |
| 4161 | + | |
| 4162 | + | |
| 4163 | + | |
| 4164 | + | |
| 4165 | + | |
| 4166 | + | |
4070 | 4167 | | |
4071 | 4168 | | |
4072 | 4169 | | |
4073 | 4170 | | |
4074 | 4171 | | |
4075 | 4172 | | |
4076 | | - | |
4077 | | - | |
4078 | | - | |
| 4173 | + | |
| 4174 | + | |
| 4175 | + | |
4079 | 4176 | | |
4080 | 4177 | | |
4081 | 4178 | | |
4082 | 4179 | | |
4083 | | - | |
| 4180 | + | |
4084 | 4181 | | |
4085 | 4182 | | |
4086 | 4183 | | |
| |||
4102 | 4199 | | |
4103 | 4200 | | |
4104 | 4201 | | |
4105 | | - | |
| 4202 | + | |
4106 | 4203 | | |
4107 | 4204 | | |
4108 | 4205 | | |
| |||
0 commit comments