Skip to content
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 battery-state binary_sensors, translate battery-low message to a state-change #604

Merged
merged 50 commits into from
Aug 13, 2024

Conversation

bouwew
Copy link
Contributor

@bouwew bouwew commented Aug 12, 2024

Summary by CodeRabbit

  • New Features

    • Introduced binary_sensors to track battery state for multiple devices, enhancing monitoring capabilities.
    • Updated item counts across various configurations to reflect the increased number of devices managed.
    • Enhanced device management functionality with integrated low battery detection.
  • Bug Fixes

    • Addressed potential inaccuracies in device battery monitoring with newly implemented checks.
  • Tests

    • Expanded test suite for improved coverage of device interactions, ensuring reliability with the latest changes.
  • Documentation

    • Added XML notifications for low battery status, enhancing user awareness of device health.
  • Changelog

    • Updated to reflect new version v1.1.0 and introduced battery state notifications for battery-powered devices.

Copy link
Member

@CoMPaTech CoMPaTech left a comment

Choose a reason for hiding this comment

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

Looks okay code wise so far - lets check actions in the morning why some fail

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bc9601e and a7c4ad3.

Files selected for processing (1)
  • plugwise/data.py (2 hunks)
Additional comments not posted (1)
plugwise/data.py (1)

57-68: Verify the correctness of MAC address logic.

Ensure that the MAC addresses are correctly identified and that the battery_state is updated only when appropriate. Consider edge cases where the MAC address might not be present in the notification or the binary_sensors dictionary.

Verification successful

MAC address logic and battery state update are correctly implemented.

The logic for detecting MAC addresses and updating the battery_state in the binary_sensors dictionary is consistent with the intended functionality. The code correctly checks for the presence of a MAC address in the list and updates the battery state accordingly.

  • The binary_sensors dictionary is used to store various sensor states, including battery_state.
  • The zigbee_mac_address is used to identify devices and is correctly checked against the MAC address list.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the logic for MAC address detection and battery state update.

# Test: Search for usage and definition of `binary_sensors` and `zigbee_mac_address`.
rg --type python -A 5 $'binary_sensors' 
rg --type python -A 5 $'zigbee_mac_address'

Length of output: 143


Script:

#!/bin/bash
# Description: Verify the logic for MAC address detection and battery state update.

# Test: Search for usage and definition of `binary_sensors` and `zigbee_mac_address` with correct file type.
rg --type py -A 5 $'binary_sensors' 
rg --type py -A 5 $'zigbee_mac_address'

Length of output: 20144

plugwise/data.py Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a7c4ad3 and b88d1ac.

Files selected for processing (1)
  • plugwise/data.py (2 hunks)
Additional comments not posted (2)
plugwise/data.py (2)

73-91: Consider existing error handling suggestions.

The existing comment suggests adding error handling for cases where re.findall might return an empty list. This is a valid point and should be addressed to handle potential edge cases gracefully.


57-70: Verify logic for updating battery states.

The logic for updating the battery_state in binary_sensors based on MAC addresses seems correct. However, ensure that the zigbee_mac_address is always present and valid in the device dictionary to avoid potential KeyErrors.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b88d1ac and da05526.

Files selected for processing (1)
  • plugwise/data.py (2 hunks)

plugwise/data.py Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between da05526 and 9486b6a.

Files selected for processing (6)
  • fixtures/adam_plus_anna_new/all_data.json (4 hunks)
  • fixtures/m_adam_cooling/all_data.json (4 hunks)
  • fixtures/m_adam_heating/all_data.json (4 hunks)
  • plugwise/data.py (2 hunks)
  • tests/data/adam/adam_plus_anna_new.json (2 hunks)
  • userdata/adam_plus_anna_new/core.domain_objects.xml (2 hunks)
Files skipped from review as they are similar to previous changes (5)
  • fixtures/adam_plus_anna_new/all_data.json
  • fixtures/m_adam_cooling/all_data.json
  • fixtures/m_adam_heating/all_data.json
  • tests/data/adam/adam_plus_anna_new.json
  • userdata/adam_plus_anna_new/core.domain_objects.xml
Additional comments not posted (1)
plugwise/data.py (1)

57-73: Verify the integration and logic for low battery detection.

The addition of low battery detection logic in _update_gw_devices appears correct. Ensure that the _detect_low_batteries method is functioning as expected and that the conditions for updating binary_sensors are met correctly.

Verification successful

Integration and logic for low battery detection are correctly implemented.

The _detect_low_batteries method is properly integrated into _update_gw_devices, and its output is used correctly to update the battery state in binary_sensors. The logic for detecting low battery conditions appears sound.

  • _detect_low_batteries is defined and used correctly.
  • The method's output is utilized to update the mac_list, which is then used to update the battery state.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration and logic for low battery detection in `_update_gw_devices`.

# Test: Check for the usage of `_detect_low_batteries` and ensure its output is handled correctly.
rg --type python '_detect_low_batteries' -A 5

Length of output: 76


Script:

#!/bin/bash
# Description: Verify the integration and logic for low battery detection in `_update_gw_devices`.

# Test: Check for the usage of `_detect_low_batteries` and ensure its output is handled correctly.
rg --type py '_detect_low_batteries' -A 5

Length of output: 744

plugwise/data.py Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9486b6a and f2276fc.

Files selected for processing (1)
  • plugwise/data.py (2 hunks)
Additional comments not posted (2)
plugwise/data.py (2)

57-74: Acknowledge implemented improvements and suggest further refactoring.

The integration of low battery detection logic in _update_gw_devices is well-structured. Previous suggestions regarding readability and performance have been addressed. Consider further refactoring to enhance clarity by extracting the inline condition into a separate method or variable, as previously suggested.


79-95: Acknowledge implemented improvements and suggest further optimization.

The _detect_low_batteries method is well-implemented, with previous suggestions for error handling and performance optimization addressed. Consider compiling the regular expression pattern outside the method if it is used frequently elsewhere to further enhance performance.

Copy link

sonarcloud bot commented Aug 13, 2024

@bouwew bouwew marked this pull request as ready for review August 13, 2024 18:29
@bouwew bouwew requested a review from a team as a code owner August 13, 2024 18:29
@bouwew
Copy link
Contributor Author

bouwew commented Aug 13, 2024

Let's release to v1.1.0a0 for testing purposes.

@bouwew bouwew merged commit 67ba9a2 into main Aug 13, 2024
16 checks passed
@bouwew bouwew deleted the bin_sens_battery branch August 13, 2024 18:29
This was referenced Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants