-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
Fixed pushbullet handling of fields longer than 255 characters #146993
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
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.
Hi @eseverson
It seems you haven't yet signed a CLA. Please do so here.
Once you do that we will be able to review and accept this pull request.
Thanks!
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Hey there @engrbm87, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
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.
Pull Request Overview
This PR ensures sensor values from Pushbullet are truncated to Home Assistant’s maximum state length while retaining full data in attributes.
- Imported and used
MAX_LENGTH_STATE_STATE
to limit string length inasync_update_callback
. - Applied ellipsis truncation for overly long string values.
- Added comprehensive tests covering truncation, non-string handling, and missing-key scenarios.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
homeassistant/components/pushbullet/sensor.py | Imported MAX_LENGTH_STATE_STATE and implemented string truncation with ellipsis in update logic. |
tests/components/pushbullet/test_sensor.py | Added tests for truncation behavior on body and title sensors, non-string values, and missing keys. |
Comments suppressed due to low confidence (1)
tests/components/pushbullet/test_sensor.py:168
- [nitpick] Consider adding an explicit assertion for the missing-key case to verify the expected behavior (e.g., state remains unchanged or becomes
None
), which will prevent unintended regressions.
sensor.async_update_callback()
value = self.pb_provider.data[self.entity_description.key] | ||
# Truncate state value to MAX_LENGTH_STATE_STATE while preserving full content in attributes | ||
if isinstance(value, str) and len(value) > MAX_LENGTH_STATE_STATE: | ||
self._attr_native_value = value[: MAX_LENGTH_STATE_STATE - 3] + "..." |
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.
[nitpick] Avoid the magic number 3
for the ellipsis length; define a constant such as ELLIPSIS = '...'
and use len(ELLIPSIS)
in the slice to improve readability and maintainability.
self._attr_native_value = value[: MAX_LENGTH_STATE_STATE - 3] + "..." | |
self._attr_native_value = value[: MAX_LENGTH_STATE_STATE - len(ELLIPSIS)] + ELLIPSIS |
Copilot uses AI. Check for mistakes.
value = self.pb_provider.data[self.entity_description.key] | ||
# Truncate state value to MAX_LENGTH_STATE_STATE while preserving full content in attributes | ||
if isinstance(value, str) and len(value) > MAX_LENGTH_STATE_STATE: | ||
self._attr_native_value = value[: MAX_LENGTH_STATE_STATE - 3] + "..." |
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.
PEP8 style: remove the space after the slice colon. Use value[:MAX_LENGTH_STATE_STATE - 3]
instead of value[: MAX_LENGTH_STATE_STATE - 3]
for consistency.
self._attr_native_value = value[: MAX_LENGTH_STATE_STATE - 3] + "..." | |
self._attr_native_value = value[:MAX_LENGTH_STATE_STATE - 3] + "..." |
Copilot uses AI. Check for mistakes.
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.
Thanks @eseverson 👍
Proposed change
Fixes handling of sensor values longer than 255 characters
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: