Commit ac8e458
authored
feat(gateway): surface gateway subType 0 as None (#2111)
## Summary
Gateways such as the Rexel Energeasy Connect report `subType: 0`, which
means "no specific sub-type". Previously this structured to
`GatewaySubType.UNKNOWN` (via the `UnknownEnumMixin` fallback),
conflating "no sub-type" with "an unrecognised sub-type". This maps
`subType: 0` to `None` on `Gateway.sub_type` instead.
`GatewaySubType.UNKNOWN` stays reserved for genuinely unrecognised
**non-zero** values.
## Approach
A field `converter=` won't work: cattrs structures the raw `0` into
`GatewaySubType.UNKNOWN` *before* `__init__` runs, so the converter
couldn't tell `subType: 0` apart from a real unknown. The fix is a
cattrs **exact-type structure hook** for `GatewaySubType`, which sees
the raw value. It's registered with `register_structure_hook` (direct
dispatch) so it overrides cattrs' generic enum factory.
No enum member for `0` is added — `None` is the honest representation
and the field is already typed `GatewaySubType | None`.
## Behaviour
| `subType` | `Gateway.sub_type` |
|-----------|--------------------|
| `0` | `None` |
| `1` (known) | `GatewaySubType.TAHOMA_BASIC` |
| `99` (unknown, non-zero) | `GatewaySubType.UNKNOWN` |
| absent | `None` |
## Test plan
- New `TestGateway` class in `tests/test_models.py` covering all four
cases above, including the `setup_rexel.json` fixture.
- `pytest` → 506 passed
- `mypy pyoverkiz/converter.py` → clean1 parent e4c3e0a commit ac8e458
2 files changed
Lines changed: 60 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
67 | 78 | | |
68 | 79 | | |
69 | 80 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| |||
137 | 139 | | |
138 | 140 | | |
139 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
140 | 189 | | |
141 | 190 | | |
142 | 191 | | |
| |||
0 commit comments