Commit e0a8a80
committed
Improve Device model (#1930)
## Breaking
- The Device class no longer includes the `id` property, and the
following fields have been moved into `device.identifier.{}`:
`protocol`, `gateway_id`, `device_address`, and `subsystem_id`.
- Device.data_properties has been removed, as it was a non-existent
value.
## Enhancement
- Device class now has helper methods for retrieving the state value,
commands and definition.
- Device class now has an `identifier` property with protocol,
gateway_id, device_address, subsystem_id and base_device_url fields.
- The Device class now includes additional fields (data_properties,
ui_profiles, ui_classifiers, attributes) under device.definition.
## Full changelog
Fixes #1923
This pull request refactors and enhances the device modeling logic in
`pyoverkiz/models.py`, introducing a new `DeviceIdentifier` class to
encapsulate device URL parsing and related properties. It also adds
several helper methods to the `Device`, `States`, `Definition`, and
`CommandDefinitions` classes, improving code clarity and testability.
Extensive new tests are added to ensure the correctness of these helpers
and the new identifier logic.
**Device identifier and URL parsing improvements:**
* Introduced a new `DeviceIdentifier` class to encapsulate parsing and
properties of device URLs, replacing scattered parsing logic and related
fields in the `Device` class. Device URL parsing now raises a
`ValueError` for invalid formats. (`pyoverkiz/models.py`)
* Refactored the `Device` class to use the new `identifier` property
instead of separate protocol, gateway_id, device_address, and
subsystem_id fields. (`pyoverkiz/models.py`)
[[1]](diffhunk://#diff-abae13362160dc5f0aff1ba910ffe223a87f52dfda3a77f160ad13a6a9dbc92cL186-L194)
[[2]](diffhunk://#diff-abae13362160dc5f0aff1ba910ffe223a87f52dfda3a77f160ad13a6a9dbc92cL207-R299)
**Helper methods and API enhancements:**
* Added helper methods to `Device`, `States`, `Definition`, and
`CommandDefinitions` classes (e.g., `get_supported_command_name`,
`has_supported_command`, `get_state_value`, `get_state_definition`,
`select`, `has_any`) to simplify common queries and checks.
(`pyoverkiz/models.py`)
[[1]](diffhunk://#diff-abae13362160dc5f0aff1ba910ffe223a87f52dfda3a77f160ad13a6a9dbc92cL207-R299)
[[2]](diffhunk://#diff-abae13362160dc5f0aff1ba910ffe223a87f52dfda3a77f160ad13a6a9dbc92cR355-R366)
[[3]](diffhunk://#diff-abae13362160dc5f0aff1ba910ffe223a87f52dfda3a77f160ad13a6a9dbc92cR409-R418)
[[4]](diffhunk://#diff-abae13362160dc5f0aff1ba910ffe223a87f52dfda3a77f160ad13a6a9dbc92cR557-R573)
**Testing improvements:**
* Updated and expanded tests to cover the new `DeviceIdentifier` logic,
helper methods, and error handling for invalid device URLs. Added new
test cases for the helper methods in `Device`, `States`, `Definition`,
and `CommandDefinitions`. (`tests/test_client.py`,
`tests/test_models.py`)
[[1]](diffhunk://#diff-0d92063e88430a02df61616c5f16b148b64ac4539d9cb9b8d883d5a23351b110L279-R281)
[[2]](diffhunk://#diff-0adb667cd397bd56edce10eec11e1b10821740a10d72bd148b09645fc9108968L9-R15)
[[3]](diffhunk://#diff-0adb667cd397bd56edce10eec11e1b10821740a10d72bd148b09645fc9108968L154-L170)
[[4]](diffhunk://#diff-0adb667cd397bd56edce10eec11e1b10821740a10d72bd148b09645fc9108968L190-R194)
[[5]](diffhunk://#diff-0adb667cd397bd56edce10eec11e1b10821740a10d72bd148b09645fc9108968R203-R241)
[[6]](diffhunk://#diff-0adb667cd397bd56edce10eec11e1b10821740a10d72bd148b09645fc9108968R273-R374)
**Code cleanup:**
* Removed legacy or redundant fields and parsing logic from the `Device`
class, and improved fallback logic for `ui_class` and `widget`
properties. (`pyoverkiz/models.py`)
[[1]](diffhunk://#diff-abae13362160dc5f0aff1ba910ffe223a87f52dfda3a77f160ad13a6a9dbc92cL186-L194)
[[2]](diffhunk://#diff-abae13362160dc5f0aff1ba910ffe223a87f52dfda3a77f160ad13a6a9dbc92cL207-R299)
These changes improve the maintainability and usability of the device
modeling code, making it easier to work with device URLs and query
device capabilities in a robust and testable way.1 parent 7de3c3d commit e0a8a80
File tree
4 files changed
+525
-61
lines changed- docs
- pyoverkiz
- tests
4 files changed
+525
-61
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
35 | 122 | | |
36 | 123 | | |
37 | 124 | | |
| |||
0 commit comments