Skip to content

Commit 49b5f8a

Browse files
authored
docs: fill gaps in v2 migration guide (#2119)
## Summary Reviewed the v2 migration guide against the **actual latest v1 release (`v1.20.6`)** to find breaking changes that were missing. Three genuine gaps remain after verification; docs-only (`docs/migration-v2.md`). ### Added - **Iteration over `States` / `CommandDefinitions` / `StateDefinitions`** — these now subclass `collections.abc.Mapping`, so `for x in device.states` yields **keys (`str`)** instead of the objects. Silent change (no exception), and the Home Assistant integration relies on the old behavior (`sensor.py`, `executor.py`). Added a dedicated section with a `danger` admonition and `.values()`/`.items()` examples. - **`Command` is no longer a `dict` subclass** — `command["name"]` no longer works; use attribute access or `to_payload()`. Notes the new `type` field and `OverkizCommandParam` parameter support. - **`Event.setupoid` → `Event.setup_oid`** rename (+ new `actions`/`owner`/`source` fields), added to the parameter-renames table. ## Note My first pass mistakenly diffed against `v1.9.1` (alphabetical tag sort hid `v1.10`–`v1.20.6`). That produced several false "gaps" — `verify_ssl`, timestamp `str`→`int`, eight "new" exceptions, two `Server` enum members, and `APIType` — all of which already shipped in v1.x. Those were removed in the second commit; everything remaining is verified against `v1.20.6`.
1 parent 7c7d82e commit 49b5f8a

1 file changed

Lines changed: 65 additions & 1 deletion

File tree

docs/migration-v2.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,27 @@ The command execution API has been consolidated into a single method.
112112

113113
v2 also supports sending actions to **multiple devices** in a single call and choosing an `ExecutionMode` (`HIGH_PRIORITY`, `GEOLOCATED`, `INTERNAL`). Execution modes are only supported by the Cloud API; the local API rejects them (see [Somfy-TaHoma-Developer-Mode#227](https://github.com/Somfy-Developer/Somfy-TaHoma-Developer-Mode/issues/227)).
114114

115+
### `Command` is no longer a `dict`
116+
117+
In v1, `Command` subclassed `dict`, so you could access its fields by subscript (`command["name"]`) or unpack it. In v2 it is a plain attrs class — use attribute access instead, and call `to_payload()` if you need the serializable dict form.
118+
119+
=== "v1"
120+
121+
```python
122+
command = Command("open", [])
123+
name = command["name"] # dict access worked
124+
```
125+
126+
=== "v2"
127+
128+
```python
129+
command = Command(name="open")
130+
name = command.name # attribute access only
131+
payload = command.to_payload() # dict form, if needed
132+
```
133+
134+
`Command` also gains an optional `type` field, and `parameters` now accepts `OverkizCommandParam` values in addition to primitives.
135+
115136
## Diagnostics
116137

117138
`get_diagnostic_data()` now returns a structured dict with named sections instead of a flat setup dump.
@@ -264,6 +285,48 @@ if device.definition:
264285
...
265286
```
266287

288+
## Iterating state and command containers
289+
290+
!!! danger "Silent behavior change"
291+
`States`, `CommandDefinitions`, and `StateDefinitions` now implement
292+
`collections.abc.Mapping`. **Iterating them yields keys (`str`), not the
293+
contained objects.** This change is silent — no exception is raised, your
294+
loop variable is just a different type than before.
295+
296+
This affects `device.states`, `device.attributes`, `device.definition.states`,
297+
and `device.definition.commands`.
298+
299+
=== "v1"
300+
301+
```python
302+
# Iterating yielded the objects directly
303+
for state in device.states:
304+
print(state.name, state.value)
305+
306+
for definition in device.definition.states:
307+
print(definition.qualified_name)
308+
```
309+
310+
=== "v2"
311+
312+
```python
313+
# Iterating now yields keys (str), like any Mapping
314+
for name in device.states:
315+
state = device.states[name]
316+
print(name, state.value)
317+
318+
# Use .values() to iterate the objects
319+
for state in device.states.values():
320+
print(state.name, state.value)
321+
322+
for definition in device.definition.states.values():
323+
print(definition.qualified_name)
324+
325+
# .keys() / .items() are also available
326+
for name, state in device.states.items():
327+
...
328+
```
329+
267330
## Gateway model
268331

269332
- `Gateway.connectivity` is now `Connectivity | None` (was always set in v1).
@@ -296,8 +359,9 @@ These changes affect you if you subclass `OverkizClient` or use internal APIs:
296359
| v1 | v2 |
297360
|----|-----|
298361
| `deviceurl` | `device_url` |
362+
| `Event.setupoid` | `Event.setup_oid` |
299363

300-
Update any keyword arguments using the old spelling.
364+
Update any keyword arguments and attribute accesses using the old spelling. `Event` also gains `actions`, `owner`, and `source` fields.
301365

302366
## Model defaults
303367

0 commit comments

Comments
 (0)