Skip to content

Improve Device model#1930

Merged
iMicknl merged 8 commits intov2/mainfrom
v2/device
Jan 31, 2026
Merged

Improve Device model#1930
iMicknl merged 8 commits intov2/mainfrom
v2/device

Conversation

@iMicknl
Copy link
Owner

@iMicknl iMicknl commented Jan 29, 2026

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] [2]

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] [2] [3] [4]

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] [2] [3] [4] [5] [6]

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] [2]

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors device modeling around a new DeviceIdentifier type and enriches the models API with helpers for querying device states, commands, and definitions, along with corresponding tests.

Changes:

  • Introduces DeviceIdentifier to encapsulate device URL parsing and identifier fields, and updates Device to use identifier instead of protocol, gateway_id, device_address, and subsystem_id (removing id as well).
  • Adds helper methods on Device, States, Definition, and CommandDefinitions (e.g., get_supported_command_name, has_supported_command, select, select_value, has_any, get_state_value, get_state_definition, get_attribute_value) and improves ui_class / widget resolution.
  • Extends and updates tests in tests/test_models.py and tests/test_client.py to validate the new identifier parsing behaviour, helper methods, and client setup parsing.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
pyoverkiz/models.py Adds DeviceIdentifier, refactors Device to use identifier, introduces new helper methods on Device, Definition, CommandDefinitions, and States, and tightens ui_class/widget resolution.
tests/test_models.py Expands model tests to cover DeviceIdentifier parsing, new Device helpers, and the added helper methods on States, CommandDefinitions, and Definition.
tests/test_client.py Adjusts setup tests to assert device identifiers via the new device.identifier API rather than the removed flat fields.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@iMicknl
Copy link
Owner Author

iMicknl commented Jan 29, 2026

TODO:
Type the dataproperties:

    "dataProperties": [
      {
        "value": "5000",
        "qualifiedName": "core:identifyInterval"
      }
    ]

python3 -c "import json; data = json.load(open('tests/fixtures/setup/setup_tahoma_1.json')); device = data['devices'][0]; print(json.dumps(device, indent=2)[:2000])"

@iMicknl iMicknl merged commit bf67bd1 into v2/main Jan 31, 2026
8 checks passed
@iMicknl iMicknl deleted the v2/device branch January 31, 2026 14:55
@iMicknl iMicknl mentioned this pull request Jan 31, 2026
iMicknl added a commit that referenced this pull request Jan 31, 2026
## 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.
@iMicknl iMicknl linked an issue Jan 31, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add command and state helper functions

1 participant