Skip to content

Added binary sensor for battery status to the PTDevices integration#169862

Draft
frogman85978 wants to merge 6 commits intohome-assistant:devfrom
ParemTech-Inc:ptdevices-binary-battery-sensor
Draft

Added binary sensor for battery status to the PTDevices integration#169862
frogman85978 wants to merge 6 commits intohome-assistant:devfrom
ParemTech-Inc:ptdevices-binary-battery-sensor

Conversation

@frogman85978
Copy link
Copy Markdown
Contributor

@frogman85978 frogman85978 commented May 5, 2026

Proposed change

This PR adds a binary sensor for the battery status, (either Normal or Low). Along with snapshot testing for the binary sensors. No changes to dependencies are required.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented May 5, 2026

Hey there @ParemTech-Inc, mind taking a look at this pull request as it has been labeled with an integration (ptdevices) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of ptdevices can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign ptdevices Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copy link
Copy Markdown
Contributor

Copilot AI left a 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 extends the ptdevices integration by adding a new battery-status binary sensor entity and introducing snapshot-based test coverage for the binary sensor platform.

Changes:

  • Added a binary_sensor platform that exposes a low-battery binary sensor based on the device’s reported battery_status.
  • Registered Platform.BINARY_SENSOR for the integration and added translation strings for the new entity.
  • Added snapshot tests + snapshots for PTDevices binary sensors.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
homeassistant/components/ptdevices/__init__.py Registers the new binary sensor platform for setup.
homeassistant/components/ptdevices/binary_sensor.py Implements the battery-status binary sensor entity and setup logic.
homeassistant/components/ptdevices/strings.json Adds entity translation string for the new binary sensor.
tests/components/ptdevices/test_binary_sensor.py Adds snapshot test covering binary sensor entities.
tests/components/ptdevices/snapshots/test_binary_sensor.ambr Stores the expected entity-registry + state snapshots for the new binary sensor.

Comment thread homeassistant/components/ptdevices/binary_sensor.py
Comment thread homeassistant/components/ptdevices/binary_sensor.py Outdated
Comment thread homeassistant/components/ptdevices/strings.json
Copilot AI review requested due to automatic review settings May 5, 2026 17:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread homeassistant/components/ptdevices/binary_sensor.py Outdated
Comment thread homeassistant/components/ptdevices/binary_sensor.py
Copilot AI review requested due to automatic review settings May 5, 2026 18:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread tests/components/ptdevices/test_binary_sensor.py Outdated
@frogman85978 frogman85978 marked this pull request as ready for review May 5, 2026 18:22
Copilot AI review requested due to automatic review settings May 5, 2026 18:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Comment thread homeassistant/components/ptdevices/binary_sensor.py
Comment on lines +23 to +26
class PTDevicesBinarySensors(StrEnum):
"""Store keys for PTDevices binary sensors."""

DEVICE_BATTERY_STATUS = "battery_status"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you expect this to be extended later on? Else, I don't think a StrEnum is not needed here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. This will be extended in future updates.

class PTDevicesBinarySensorEntityDescription(BinarySensorEntityDescription):
"""Description for PTDevices binary sensor entities."""

is_on_fn: Callable[[dict[str, str | int | float | None]], bool]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's a lot of types in the dict. Are you mimicing the StateType here? If so, you can put it in directly.

Comment thread homeassistant/components/ptdevices/binary_sensor.py
Comment thread tests/components/ptdevices/test_binary_sensor.py
Comment thread tests/components/ptdevices/test_binary_sensor.py
"""Setup PTDevices binary sensors based on config entry."""
coordinator = config_entry.runtime_data

known_sensors: set[tuple[str, str]] = set()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since you're growing with sensors, or better devices, I think the coordinator should be responsible of adding or removing devices and not per platform. Check the Portainer integration for an example, but I think that way we can reduce potential duplicate code when adding new platforms. :)

@home-assistant home-assistant Bot marked this pull request as draft May 6, 2026 21:03
@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented May 6, 2026

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants