-
Notifications
You must be signed in to change notification settings - Fork 7
Add battery_state binary_sensor for battery powered devices #702
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
Conversation
WalkthroughThe recent changes introduce a new battery-state binary sensor for Plugwise devices, enhancing functionality and monitoring capabilities. This update includes versioning revisions, expanded translation files, and modifications across various configuration and testing files, ensuring users can effectively track battery levels and improve overall integration performance. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant PlugwiseSystem
participant Sensor
User->>PlugwiseSystem: Request device status
PlugwiseSystem->>Sensor: Fetch current sensor data
Sensor-->>PlugwiseSystem: Return battery state
PlugwiseSystem-->>User: Display battery state
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 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 as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
|
|
|
||
| # Binary Sensor constants | ||
| BINARY_SENSORS: Final = "binary_sensors" | ||
| BATTERY_STATE: Final = "low_battery" |
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.
Just wondering if we should just make it BATTERY_LOW or LOW_BAT..?
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 don't think so, it will only cause confusion.
The name of the binary_sensor in HA should be battery_state, that fits best to the values of the device_class.
So let's "hide" the different name in the backend-output as best as we can = in the constant definition.
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
Outside diff range, codebase verification and nitpick comments (1)
tests/components/plugwise/fixtures/m_adam_jip/all_data.json (1)
313-313: Discrepancy initem_countvalueThe
item_countin the JSON file is set to 217, but the actual count of items under.devicesis 11. This discrepancy suggests an error or misrepresentation in theitem_countvalue.
- File:
tests/components/plugwise/fixtures/m_adam_jip/all_data.json- Line: 313
Please verify and correct the
item_countto accurately reflect the total number of items.Analysis chain
Update
item_countto 217: Verify accuracy.The
item_counthas been updated to 217, reflecting the addition of new items. Ensure this count accurately represents the total number of items in the configuration.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the accuracy of the updated `item_count`. # Test: Count the total number of items and ensure it matches the updated `item_count`. jq '.devices | length' tests/components/plugwise/fixtures/m_adam_jip/all_data.jsonLength of output: 87
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (13)
- CHANGELOG.md (1 hunks)
- custom_components/plugwise/binary_sensor.py (3 hunks)
- custom_components/plugwise/const.py (1 hunks)
- custom_components/plugwise/manifest.json (1 hunks)
- custom_components/plugwise/strings.json (1 hunks)
- custom_components/plugwise/translations/en.json (8 hunks)
- custom_components/plugwise/translations/nl.json (1 hunks)
- tests/components/plugwise/fixtures/m_adam_cooling/all_data.json (4 hunks)
- tests/components/plugwise/fixtures/m_adam_heating/all_data.json (4 hunks)
- tests/components/plugwise/fixtures/m_adam_jip/all_data.json (5 hunks)
- tests/components/plugwise/fixtures/m_adam_multiple_devices_per_zone/all_data.json (9 hunks)
- tests/components/plugwise/snapshots/test_diagnostics.ambr (9 hunks)
- tests/components/plugwise/test_init.py (4 hunks)
Files skipped from review due to trivial changes (2)
- CHANGELOG.md
- custom_components/plugwise/const.py
Additional comments not posted (38)
custom_components/plugwise/manifest.json (2)
11-11: Version bump to Plugwise library.The requirement update to
plugwise==1.1.0reflects an update in the library. Ensure that the integration is compatible with this new library version.
12-12: Version bump of the integration.The version update to
0.52.0indicates new features or fixes. Ensure that this aligns with the changes made in the integration.tests/components/plugwise/fixtures/m_adam_cooling/all_data.json (4)
31-33: Addition of binary sensor for low battery status.The addition of the
low_batterybinary sensor for the device1772a4ea304041adb83f357b751341ffis consistent with the new feature for monitoring battery state.
122-124: Addition of binary sensor for low battery status in zone thermostat.The addition of the
low_batterybinary sensor for the zone thermostat device is consistent with the new feature for monitoring battery state.
136-136: Update of battery level.The battery level change from
38to14reflects a significant drop, aligning with the low battery status. Ensure this is correctly handled in the tests.
172-172: Update of item count.The item count update from
147to149reflects the addition of new items. Ensure this is consistent with the changes in the test data.tests/components/plugwise/fixtures/m_adam_heating/all_data.json (4)
36-38: Addition of binary sensor for low battery status.The addition of the
low_batterybinary sensor for the device1772a4ea304041adb83f357b751341ffis consistent with the new feature for monitoring battery state.
121-123: Addition of binary sensor for low battery status in zone thermostat.The addition of the
low_batterybinary sensor for the zone thermostat device is consistent with the new feature for monitoring battery state.
135-135: Update of battery level.The battery level change from
38to14reflects a significant drop, aligning with the low battery status. Ensure this is correctly handled in the tests.
171-171: Update of item count.The item count update from
147to149reflects the addition of new items. Ensure this is consistent with the changes in the test data.custom_components/plugwise/binary_sensor.py (1)
50-55: Addition of Battery State Sensor is Correct.The new
BATTERY_STATEentry inPLUGWISE_BINARY_SENSORSis consistent with existing entries, correctly utilizing attributes likekey,translation_key,device_class, andentity_category.custom_components/plugwise/strings.json (1)
50-52: Addition of Low Battery Entry is Correct.The new
low_batteryentry underbinary_sensorwith the name "Battery state" is consistent with the existing structure and enhances the functionality.custom_components/plugwise/translations/nl.json (1)
50-52: Addition of Low Battery Entry for Dutch Language is Correct.The new
low_batteryentry underbinary_sensorwith the name "Batterij status" is consistent with the existing structure and enhances localization support.tests/components/plugwise/test_init.py (3)
262-262: Revert expected entity count to 31 after removal.The expected entity count is reverted to 31 after removing a device, which is consistent with the test scenario. Ensure that this aligns with the expected behavior of the integration.
Line range hint
228-243:
Update expected entity and device counts intest_update_device.The changes in expected counts from 29 to 31 and 34 to 37 reflect the addition of new sensors. Ensure these updated counts align with the actual number of entities and devices managed by the integration.
Verification successful
Verification of Updated Counts in
test_update_deviceThe addition of the
TOMdevice, a thermo sensor, justifies the increase in device and entity counts in the test. The updated expected counts are consistent with the changes made to the test setup.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the expected counts of entities and devices in test cases. # Test: Ensure the updated counts match the actual number of entities and devices. rg --type py 'async_entries_for_config_entry'Length of output: 946
Script:
#!/bin/bash # Description: Gather more context about the setup of `data.devices` and related logic in the test file. # Find where `data.devices` is defined or updated in the test file. rg --type py 'data\.devices' -A 5 # Check for any setup or fixture that might affect the number of entities and devices. rg --type py 'def ' -A 5 tests/components/plugwise/test_init.pyLength of output: 13131
Script:
#!/bin/bash # Description: Find the definition or initialization of `TOM` to understand its impact on device and entity counts. # Search for `TOM` in the test file and related files to understand its structure and contents. rg --type py 'TOM' -A 5Length of output: 909
46-48: Addition ofbinary_sensors: Ensure completeness of test data.The addition of the
binary_sensorsdictionary with alow_batterysensor is consistent with the objective of testing battery state monitoring. Ensure that all relevant scenarios are covered in the test cases.Verification successful
Test Coverage for
binary_sensorsis ComprehensiveThe test cases in
test_climate.pyeffectively cover various scenarios forbinary_sensors, such ascooling_stateandheating_state, by simulating different conditions. This ensures that the functionality related to battery state monitoring is thoroughly tested.
test_climate.py: Tests different states ofbinary_sensorslikecooling_stateandheating_state.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of `binary_sensors` across test cases. # Test: Search for the usage of `binary_sensors` in test files. Expect: Consistent usage across test cases. rg --type py 'binary_sensors'Length of output: 1354
Script:
#!/bin/bash # Search for test functions in test_init.py and test_climate.py that involve binary_sensors rg --type py -A 5 'def ' tests/components/plugwise/test_init.py rg --type py -A 5 'def ' tests/components/plugwise/test_climate.pyLength of output: 3841
Script:
#!/bin/bash # Search within the test functions for any references to binary_sensors rg --type py 'binary_sensors' tests/components/plugwise/test_init.py rg --type py 'binary_sensors' tests/components/plugwise/test_climate.pyLength of output: 456
Script:
#!/bin/bash # Review the lines in test_climate.py where binary_sensors is used to determine scenario coverage rg --type py -A 3 -B 3 'binary_sensors' tests/components/plugwise/test_climate.pyLength of output: 922
tests/components/plugwise/fixtures/m_adam_jip/all_data.json (1)
6-8: Addition ofbinary_sensors: Ensure consistency in device entries.The addition of the
binary_sensorsdictionary withlow_batteryset tofalseis consistent across multiple device entries. Verify that this addition is applied consistently to all relevant devices.Also applies to: 103-105, 161-163, 275-277
Verification successful
Consistency of
binary_sensorsAddition VerifiedThe
binary_sensorsentry is consistently added across multiple device entries in the relevant JSON files. This includes the specific entries inm_adam_jip/all_data.jsonas well as other related fixture files. No inconsistencies were found.
- Lines 6, 103, 161, 194, 239, and 275 in
tests/components/plugwise/fixtures/m_adam_jip/all_data.jsonall containbinary_sensors.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the consistency of `binary_sensors` addition across device entries. # Test: Ensure `binary_sensors` is present in all relevant device entries. rg --json 'binary_sensors'Length of output: 23041
custom_components/plugwise/translations/en.json (3)
2-16: Addition ofoptionssection: Ensure clarity and completeness.The new
optionssection provides configurable settings for Smile/Stretch devices. Ensure that descriptions are clear and accurately reflect the available options.
Line range hint
50-76:
Addition of new entities: Verify naming and descriptions.The addition of new entities enhances monitoring capabilities. Ensure that naming conventions and descriptions are consistent and clear for users.
Also applies to: 102-104, 129-135, 145-281
301-302: Reorganization of existing entries: Maintain clarity and consistency.The reorganization of entries aims to streamline the structure. Ensure that this reorganization maintains clarity and consistency across the translation file.
tests/components/plugwise/fixtures/m_adam_multiple_devices_per_zone/all_data.json (9)
85-87: Consistent addition ofbinary_sensors.The addition of the
binary_sensorsproperty withlow_batteryset tofalseis consistent across multiple entries. Ensure that this reflects the intended state for all devices.
121-123: Consistent addition ofbinary_sensors.The
binary_sensorsproperty withlow_batteryset tofalseis consistently added. Verify that this is the intended default state for these devices.
208-210: Consistent addition ofbinary_sensors.The
binary_sensorsproperty withlow_batteryset tofalseis consistently added. Ensure that this aligns with the device's actual state.
267-269: Consistent addition ofbinary_sensors.The
binary_sensorsproperty withlow_batteryset tofalseis consistently added. Confirm that this is the correct state for these devices.
321-323: Consistent addition ofbinary_sensors.The
binary_sensorsproperty withlow_batteryset tofalseis consistently added. Verify that this is appropriate for these devices.
357-359: Consistent addition ofbinary_sensors.The
binary_sensorsproperty withlow_batteryset tofalseis consistently added. Ensure that this reflects the intended state for these devices.
392-394: Consistent addition ofbinary_sensors.The
binary_sensorsproperty withlow_batteryset tofalseis consistently added. Confirm that this is the correct state for these devices.
436-438: Consistent addition ofbinary_sensors.The
binary_sensorsproperty withlow_batteryset tofalseis consistently added. Verify that this is appropriate for these devices.
491-491: Updateitem_countto reflect new entries.The
item_counthas been updated from315to323, which reflects the addition of new entries. Ensure that this count accurately represents all items.tests/components/plugwise/snapshots/test_diagnostics.ambr (9)
87-89: Consistent addition ofbinary_sensors.The addition of the
binary_sensorsproperty withlow_batteryset toFalseis consistent across multiple entries. Ensure that this reflects the intended state for all devices.
123-125: Consistent addition ofbinary_sensors.The
binary_sensorsproperty withlow_batteryset toFalseis consistently added. Verify that this is the intended default state for these devices.
216-218: Consistent addition ofbinary_sensors.The
binary_sensorsproperty withlow_batteryset toFalseis consistently added. Ensure that this aligns with the device's actual state.
275-277: Consistent addition ofbinary_sensors.The
binary_sensorsproperty withlow_batteryset toFalseis consistently added. Confirm that this is the correct state for these devices.
335-337: Consistent addition ofbinary_sensors.The
binary_sensorsproperty withlow_batteryset toFalseis consistently added. Verify that this is appropriate for these devices.
371-373: Consistent addition ofbinary_sensors.The
binary_sensorsproperty withlow_batteryset toFalseis consistently added. Ensure that this reflects the intended state for these devices.
412-414: Consistent addition ofbinary_sensors.The
binary_sensorsproperty withlow_batteryset toFalseis consistently added. Confirm that this is the correct state for these devices.
462-464: Consistent addition ofbinary_sensors.The
binary_sensorsproperty withlow_batteryset toFalseis consistently added. Verify that this is appropriate for these devices.
523-523: Updateitem_countto reflect new entries.The
item_counthas been updated from315to323, which reflects the addition of new entries. Ensure that this count accurately represents all items.



Summary by CodeRabbit
New Features
Bug Fixes
Documentation