-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add conversion to reuse wifi_strength in 'system' #487
Conversation
WalkthroughThe pull request introduces a new attribute Changes
Sequence DiagramsequenceDiagram
participant Model as System Model
participant Deserializer as __post_deserialize__
participant RSSI as wifi_rssi_db
RSSI->>Deserializer: Provide RSSI value
Deserializer->>Model: Calculate wifi_strength_pct
alt RSSI <= -100 or RSSI = 0
Deserializer-->>Model: Set wifi_strength_pct = 0
else RSSI >= -50
Deserializer-->>Model: Set wifi_strength_pct = 100
else
Deserializer-->>Model: Calculate percentage based on RSSI
end
Possibly related PRs
Suggested labels
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #487 +/- ##
==========================================
- Coverage 99.46% 99.13% -0.34%
==========================================
Files 9 9
Lines 565 576 +11
Branches 41 44 +3
==========================================
+ Hits 562 571 +9
- Misses 2 3 +1
- Partials 1 2 +1 ☔ View full report in Codecov by Sentry. |
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
tests/v1/__snapshots__/test_v1_homewizard_energy.ambr (1)
150-150
: Consider adding test cases for wifi_rssi_db conversion.While the test snapshots cover the wifi_strength_pct field, they all have wifi_rssi_db set to None. Consider adding test cases that verify the conversion from RSSI values to strength percentages.
Also applies to: 153-153, 156-156, 159-159, 162-162, 165-165, 168-168
homewizard_energy/models.py (2)
549-550
: Consider maintaining consistent attribute ordering.The new
wifi_strength_pct
attribute should be placed in alphabetical order with other attributes in theSystem
class to maintain consistency.Apply this diff to reorder the attributes:
@dataclass(kw_only=True) class System(BaseModel): """Represent System config.""" - wifi_strength_pct: int | None = None - wifi_ssid: str | None = field(default=None) wifi_rssi_db: int | None = field(default=None) cloud_enabled: bool | None = field(default=None) uptime_s: int | None = field(default=None) status_led_brightness_pct: int | None = field(default=None) + wifi_strength_pct: int | None = None api_v1_enabled: bool | None = field(default=None)
558-572
: LGTM! Consider documenting the RSSI to percentage conversion formula.The code correctly implements the RSSI to percentage conversion with appropriate edge cases. Consider adding a docstring to explain the conversion formula:
Apply this diff to add documentation:
@classmethod def __post_deserialize__(cls, obj: System) -> System: - _ = cls # Unused + """Post deserialize hook for System object. + + Calculates wifi_strength_pct based on wifi_rssi_db using the following formula: + - RSSI <= -100 dBm or RSSI == 0 -> 0% (very poor or no signal) + - RSSI >= -50 dBm -> 100% (excellent signal) + - Otherwise -> 2 * (RSSI + 100) to linearly map [-100, -50] to [0, 100] + """ + _ = cls # Unused if obj.wifi_rssi_db is not None: obj.wifi_strength_pct = ( 0 if obj.wifi_rssi_db <= -100 or obj.wifi_rssi_db == 0 else 100 if obj.wifi_rssi_db >= -50 else 2 * (obj.wifi_rssi_db + 100) ) return obj
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
homewizard_energy/models.py
(2 hunks)tests/v1/__snapshots__/test_v1_homewizard_energy.ambr
(2 hunks)tests/v1/__snapshots__/test_v1_models.ambr
(2 hunks)tests/v2/__snapshots__/test_v2_homewizard_energy.ambr
(2 hunks)tests/v2/__snapshots__/test_v2_models.ambr
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Scanning
🔇 Additional comments (6)
tests/v1/__snapshots__/test_v1_homewizard_energy.ambr (1)
3-3
: LGTM! The wifi strength values are consistently mapped across all device types.The test snapshots show that the wifi_strength values from Measurement are correctly mapped to wifi_strength_pct in System across all device types:
- Single-phase meters (HWE-KWH1, SDM230-wifi): 74%
- Three-phase meters (HWE-KWH3, SDM630-wifi): 84%
- P1 meters, sockets, and water meters: 100%
Also applies to: 6-6, 9-9, 12-12, 15-15, 18-18, 21-21, 24-24, 27-27, 30-30, 33-33, 36-36, 39-39, 42-42
homewizard_energy/models.py (1)
88-92
: LGTM! Backward compatibility is maintained.The code correctly handles the migration of
wifi_strength
frommeasurement
tosystem.wifi_strength_pct
, ensuring backward compatibility by creating a newSystem
instance if needed.tests/v2/__snapshots__/test_v2_models.ambr (2)
24-24
: LGTM! The RSSI to percentage conversion is correct.The test snapshot correctly verifies that an RSSI value of -77 dBm maps to 46% signal strength.
27-27
: LGTM! Test coverage is extended to different device types.The test snapshot verifies that the RSSI to percentage conversion works consistently across different device types.
tests/v2/__snapshots__/test_v2_homewizard_energy.ambr (1)
24-24
: Test snapshots are consistent with test_v2_models.ambr.The changes in this file mirror those in
test_v2_models.ambr
, providing consistent test coverage.tests/v1/__snapshots__/test_v1_models.ambr (1)
78-96
: Test snapshots are consistent with v2 test files.The changes in this file follow the same pattern as the v2 test snapshots, ensuring consistent test coverage across API versions.
Move measurement.wifi_strength to system.wifi_strength, and add a conversion for wifi_rssi_db to wifi_strength.
Summary by CodeRabbit
New Features
Improvements
Changes
wifi_ssid
withwifi_strength_pct
in system model