-
Notifications
You must be signed in to change notification settings - Fork 34
Improve Device model #1930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v2/main
Are you sure you want to change the base?
Improve Device model #1930
Conversation
There was a problem hiding this 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
DeviceIdentifierto encapsulate device URL parsing and identifier fields, and updatesDeviceto useidentifierinstead ofprotocol,gateway_id,device_address, andsubsystem_id(removingidas well). - Adds helper methods on
Device,States,Definition, andCommandDefinitions(e.g.,get_supported_command_name,has_supported_command,select,select_value,has_any,get_state_value,get_state_definition,get_attribute_value) and improvesui_class/widgetresolution. - Extends and updates tests in
tests/test_models.pyandtests/test_client.pyto 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.
|
TODO: 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])" |
Breaking
idproperty, and the following fields have been moved intodevice.identifier.{}:protocol,gateway_id,device_address, andsubsystem_id.Enhancement
identifierproperty with protocol, gateway_id, device_address, and subsystem_id fields.Full changelog
Fixes #1923
This pull request refactors and enhances the device modeling logic in
pyoverkiz/models.py, introducing a newDeviceIdentifierclass to encapsulate device URL parsing and related properties. It also adds several helper methods to theDevice,States,Definition, andCommandDefinitionsclasses, 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:
DeviceIdentifierclass to encapsulate parsing and properties of device URLs, replacing scattered parsing logic and related fields in theDeviceclass. Device URL parsing now raises aValueErrorfor invalid formats. (pyoverkiz/models.py)Deviceclass to use the newidentifierproperty instead of separate protocol, gateway_id, device_address, and subsystem_id fields. (pyoverkiz/models.py) [1] [2]Helper methods and API enhancements:
Device,States,Definition, andCommandDefinitionsclasses (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:
DeviceIdentifierlogic, helper methods, and error handling for invalid device URLs. Added new test cases for the helper methods inDevice,States,Definition, andCommandDefinitions. (tests/test_client.py,tests/test_models.py) [1] [2] [3] [4] [5] [6]Code cleanup:
Deviceclass, and improved fallback logic forui_classandwidgetproperties. (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.