-
Notifications
You must be signed in to change notification settings - Fork 75
Add an approach for determining if a dataclass field is supported #740
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
Changes from 1 commit
718646f
88f0ef9
fda76b4
afc9f81
c5fe198
deadd70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||
| import datetime | ||||||
| import logging | ||||||
| from dataclasses import dataclass | ||||||
| from dataclasses import dataclass, field | ||||||
| from enum import Enum | ||||||
| from typing import Any | ||||||
|
|
||||||
| from roborock.const import ( | ||||||
|
|
@@ -91,12 +92,35 @@ | |||||
| _LOGGER = logging.getLogger(__name__) | ||||||
|
|
||||||
|
|
||||||
| class FieldNameBase(str, Enum): | ||||||
|
allenporter marked this conversation as resolved.
Outdated
|
||||||
| """A base enum class that represents a field name in a RoborockBase dataclass.""" | ||||||
|
|
||||||
|
|
||||||
| class StatusField(FieldNameBase): | ||||||
| """An enum that represents a field in the `Status` class. | ||||||
|
|
||||||
| This is used with `roborock.devices.traits.v1.status.DeviceFeaturesTrait` | ||||||
|
||||||
| This is used with `roborock.devices.traits.v1.status.DeviceFeaturesTrait` | |
| This is used with `roborock.devices.traits.v1.device_features.DeviceFeaturesTrait` |
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.
So I know this was my suggestion and very similar to how I did it in device features. I wonder if a wrapper around field though that makes it easier to set the metadata would be worthwhile as this gets more complicated.
i.e. OurSubClassField(requires_schema_code=StatusField.BATTERY) or still just "battery" if that makes more sense. May help us avoid making any mistakes with typos in the metadata field name
The init of the field could create the metadata and everything else could stay the same but would likely lower the burden of contributing for other users.
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.
I did this though made a few alterations, PTAL.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # serializer version: 1 | ||
| # name: test_is_attribute_supported[home_data_device_s5e.json] | ||
| dict({ | ||
| 'battery': True, | ||
| 'charge_status': True, | ||
| 'dry_status': True, | ||
| 'fan_power': True, | ||
| 'state': True, | ||
| 'water_box_mode': True, | ||
| }) | ||
| # --- | ||
| # name: test_is_attribute_supported[home_data_device_s7_maxv.json] | ||
| dict({ | ||
| 'battery': True, | ||
| 'charge_status': True, | ||
| 'dry_status': True, | ||
| 'fan_power': True, | ||
| 'state': True, | ||
| 'water_box_mode': True, | ||
| }) | ||
| # --- | ||
| # name: test_is_attribute_supported[home_data_device_saros_10r.json] | ||
| dict({ | ||
| 'battery': True, | ||
| 'charge_status': True, | ||
| 'dry_status': True, | ||
| 'fan_power': True, | ||
| 'state': True, | ||
| 'water_box_mode': True, | ||
| }) | ||
| # --- |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||
| """Tests for the DeviceFeaturesTrait related functionality.""" | ||||||
|
|
||||||
| import pytest | ||||||
| from syrupy import SnapshotAssertion | ||||||
|
|
||||||
| from roborock.data import HomeDataDevice | ||||||
| from roborock.data.v1.v1_containers import StatusField | ||||||
| from roborock.devices.device import RoborockDevice | ||||||
| from roborock.devices.traits.v1.status import StatusTrait | ||||||
| from tests import mock_data | ||||||
|
|
||||||
| V1_DEVICES = { | ||||||
| k: HomeDataDevice.from_dict(device) | ||||||
| for k, device in mock_data.DEVICES.items() | ||||||
| if device.get("pv") == "1.0" | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| @pytest.mark.parametrize( | ||||||
| ("device_info"), | ||||||
|
||||||
| ("device_info"), | |
| "device_info", |
Uh oh!
There was an error while loading. Please reload this page.