Repository navigation
Leave out a recipient's mobile devices nobody is using (#299) - #336
Merged
Merged
Conversation
…tics#299) A person's mobile devices are each sent a push, whether anyone is using them or not: a sleeping Mac shows a pile of stale alerts on wake, a watch on the bedside table buzzes. Each Companion App device's in-use sensor is now found in the entity registry - macOS `active` and Wear OS `on_body` - and a device whose sensor is plainly `off` is left out as the person's targets are resolved. - No sensor, or `unknown`/`unavailable`: notified as before - `critical` goes to every device - If all of a person's devices are idle, none is left out - A mobile_app_id given directly in the notification is always notified - `in_use_entity` on a `mobile_devices` entry gives or overrides the sensor, e.g. `is_interactive` for an Android tablet, not taken by default since it's off for a phone in a pocket - `send_when_idle` on a device, also on the recipient form, and `include_idle_devices` on a notification, notify it regardless - Left-out devices are in the debug trace as `idle_mobile_devices` - The recipient form keeps per-device settings it doesn't show, where it rebuilt `mobile_devices` from just the id and enabled flag Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xb3AAKXSWfYfHnCk6Vm3kh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #299
What
A recipient's mobile devices that nobody is using are left out of a notification, as discussed in #299: a sleeping Mac no longer shows a pile of stale alerts on wake, and a watch on the bedside table doesn't buzz.
Supernotify finds each Companion App device's in-use sensor in the entity registry, from the sensor's own id (the part of the unique id after the webhook id), so nothing has to be configured:
activeon_bodyAs agreed in the issue:
off. No sensor (iPhone, iPad), orunknown/unavailable, and it's notified as todaysend_when_idleper device (YAML, and Notify even when not in use on the recipient form), andinclude_idle_devices: trueon a single notificationidle_mobile_devicesdebug artefact, with the sensor that said somobile_app_idgiven directly as a target of the notification is always notified - only the devices reached through a recipient are filteredOne change from my proposal in the issue
I'd listed Android's
interactiveamong the default sensors. Checking the Companion app source, it'sis_interactive, and only means screen on: a phone in a pocket is "idle" nearly all the time, so with a tablet on and the phone in a pocket, the phone would have been the one skipped. So it isn't auto-mapped. Insteadin_use_entityon amobile_devicesentry gives or overrides a device's sensor, which covers an Android tablet (binary_sensor.<tablet>_is_interactive) or an iPad with a template binary sensor:Where
hass_api.py:build_mobile_app_cache()picks up the in-use sensor next to the device tracker;TrackedDeviceDetails.in_use_entity;companion_sensor_id()people.py:Recipient.idle_mobile_app_ids()- the state check,send_when_idleand the all-idle safety netnotification.py: applied inresolve_indirect_targets(), right after the mobile snooze filter, so it's the same point where a person's devices first appearschema.py/const.py:in_use_entityandsend_when_idleinMOBILE_DEVICE_SCHEMA,include_idle_devicesas an action fieldconfig_flow.py: the Notify even when not in use field. The details step also used to rebuildmobile_devicesfrom just the id andenabled, which would have droppedin_use_entity; it now keeps whatever else is set for a deviceservices.yaml, translations (11 languages),docs/transports/mobile_push.mdClasses of device and a fallback order are left for a later step, as discussed.
Tests
tests/components/supernotify/test_idle_mobile_devices.py(15 tests): discovery ofactive/on_body(notis_interactive, not a disabled sensor), configured sensor winning over the discovered one, off/on/unknown/unavailable/missing,send_when_idle, critical,include_idle_devices, explicit targets, all-idle, trace, and the recipient form round trip.pytest-homeassistant)🤖 Generated with Claude Code
https://claude.ai/code/session_01Xb3AAKXSWfYfHnCk6Vm3kh