universal_notifier icon indicating copy to clipboard operation
universal_notifier copied to clipboard

sensor.py UNotifierVolumeSensor ignores weekend_days, always uses weekday time_slots

Open jokerigno opened this issue 5 months ago • 3 comments

Bug

In sensor.py, UNotifierVolumeSensor.native_value and extra_state_attributes call get_current_slot_info() without passing now_weekday / weekend_days:

# sensor.py, native_value (~line 33-34)
now_time = dt_util.now().time()
_, vol = get_current_slot_info(self._slots, now_time)
# sensor.py, extra_state_attributes (~line 51-52)
now_time = dt_util.now().time()
slot_name, vol = get_current_slot_info(self._slots, now_time)

Since now_weekday and weekend_days default to None in get_current_slot_info() (utils.py), the function always falls back to the "weekday" group:

if (weekend_days is not None and now_weekday is not None
        and now_weekday in weekend_days):
    group = slots_conf.get("weekend", slots_conf)
else:
    group = slots_conf.get("weekday", slots_conf)

This means sensor.universal_notifier_volume (state + current_slot attribute) never reflects weekend-specific time_slots, even when the user has configured separate weekday/weekend slots via the config flow.

Note: the actual notification dispatch logic in __init__.py (around line 249-251) correctly passes now_weekday and weekend_days:

now_weekday = now.weekday()
slot_key, slot_volume = get_current_slot_info(
    time_slots_conf, now_time, now_weekday, weekend_days
)

So the actual TTS volume sent during notifications is correct — only the sensor display is wrong on weekend days. This could mislead users who rely on the sensor (e.g. in automations or dashboards) to reflect the real configured weekend volume.

Fix

Pass the same weekday/weekend context to get_current_slot_info() in sensor.py as is already done in __init__.py, e.g.:

now = dt_util.now()
now_weekday = now.weekday()
weekend_days = self._weekend_days  # stored from conf.get("weekend_days", ["5","6"]) in __init__
_, vol = get_current_slot_info(self._slots, now.time(), now_weekday, weekend_days)

Context

Found while migrating from a locally-patched v0.7.0 to dev_improvment and refactoring a local automation to consume sensor.universal_notifier_volume instead of a custom command_line sensor. Our own time_slots config is flat (no weekday/weekend split), so this didnt affect us directly — found by code review while validating the migration.

Tested against dev_improvment branch.

jokerigno avatar Jun 16 '26 11:06 jokerigno

The agent encountered an error and was unable to start working on this issue: You don't have sufficient GitHub AI Credits to start a session. Review your usage and budgets in your Copilot settings, then try again. (Request id: 4304:34F56:53A6C97:5073C8A:6A315638)

Copilot avatar Jun 16 '26 13:06 Copilot

Still not fixed in v0.8.1 (released 2026-06-14).

Checked sensor.py in the v0.8.1 tag: get_current_slot_info() is still called without now_weekday/weekend_days on both native_value (line 34) and extra_state_attributes (line 52). The file is byte-for-byte identical to v0.8.0.

I am running with a local workaround (flat volume config with no weekday/weekend split), so this does not impact me — but the bug is still present for users who configure different weekend slots.

jokerigno avatar Jun 16 '26 21:06 jokerigno

FIXED. Please wait for version 0.8.2

jumping2000 avatar Jun 16 '26 23:06 jumping2000