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
Make Withings bed presence sensor dynamic #102058
Make Withings bed presence sensor dynamic #102058
Conversation
Hey there @vangorra, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
): | ||
_async_add_bed_presence_entity() | ||
else: | ||
coordinator.async_add_listener(_async_add_bed_presence_entity) |
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.
One problem I am experiencing with this setup is that this is fired at every update, thus creating more entities. I can't really find a nice way to remove this listener after we added the sensor
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.
Gave it a shot, curious if this is what we want
if ent_reg.async_get_entity_id( | ||
Platform.BINARY_SENSOR, DOMAIN, f"withings_{entry.unique_id}_in_bed" | ||
): | ||
_async_add_bed_presence_entity() | ||
else: | ||
callback = coordinator.async_add_listener(_async_add_bed_presence_entity) |
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.
You have this pattern in a few other places, it might be possible to make it a function
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'll look into this for a follow up
Co-authored-by: J. Nick Koston <nick@koston.org>
|
||
assert hass.states.get(entity_id).state == STATE_UNKNOWN | ||
assert ( | ||
"Platform withings does not generate unique IDs. ID withings_12345_in_bed already exists - ignoring binary_sensor.henk_in_bed" |
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.
Please break long strings around max 88 characters per line.
Proposed change
Make Withings bed presence sensor dynamic.
Currently, the sensor is available for everyone, except not everyone has a sleeping mat. With this change I want to disable it until the first time we receive a webhook request providing a state for the entity. When someone ever had this sensor enabled, it will be enabled so it doesn't stay unavailable until the next update everytime.
Type of change
Additional information
Checklist
black --fast 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
..coveragerc
.To help with the load of incoming pull requests: