Skip to content
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

Added new missed state for alarms (#420) #428

Merged
merged 4 commits into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,14 @@ The state value shows the next timer as a timestring (i.e.: `2021-03-07T15:26:17

Both alarms and timers have a property called status. The status of the next alarm/timer (which is used as sensor state value) is also available through sensor state attributes `next_alarm_status` and `next_timer_status` respectively.

| Status | Meaning |
| --------- | ------------------------------------------------------------------ |
| `none` | Alarm or timer does not exist |
| `set` | Alarm or timer has been set |
| `ringing` | Alarm or timer is ringing right now |
| `snoozed` | Alarm was ringing and has been snoozed (only available for alarms) |
| Status | Meaning |
| ---------- | ------------------------------------------------------------------ |
| `none` | Alarm or timer does not exist |
| `set` | Alarm or timer has been set |
| `ringing` | Alarm or timer is ringing right now |
| `snoozed` | Alarm was ringing and has been snoozed (only available for alarms) |
| `inactive` | Alarm is inactive (only available for alarms) |
| `missed` | Alarm was missed (only available for alarms) |

Note that timers lack the additional `snoozed` state due to a limitation of the API. If you actually snooze a timer it will just reset itself to the state `set` again.

Expand Down
6 changes: 4 additions & 2 deletions custom_components/google_home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ def set_timers(self, timers: list[TimerJsonDict]) -> None:
]

def get_sorted_alarms(self) -> list[GoogleHomeAlarm]:
"""Returns alarms in a sorted order. Inactive alarms are in the end."""
"""Returns alarms in a sorted order. Inactive & missed alarms are at the end."""
return sorted(
self._alarms,
key=lambda k: k.fire_time
if k.status != GoogleHomeAlarmStatus.INACTIVE
if k.status
not in (GoogleHomeAlarmStatus.INACTIVE, GoogleHomeAlarmStatus.MISSED)
else k.fire_time + sys.maxsize,
)

Expand Down Expand Up @@ -195,6 +196,7 @@ class GoogleHomeAlarmStatus(Enum):
RINGING = 2
SNOOZED = 3
INACTIVE = 4
MISSED = 5


class GoogleHomeTimerStatus(Enum):
Expand Down
4 changes: 3 additions & 1 deletion custom_components/google_home/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ def state(self) -> str | None:
next_alarm = device.get_next_alarm()
return (
next_alarm.local_time_iso
if next_alarm and next_alarm.status != GoogleHomeAlarmStatus.INACTIVE
if next_alarm
and next_alarm.status != GoogleHomeAlarmStatus.INACTIVE
and next_alarm.status != GoogleHomeAlarmStatus.MISSED
williamg97 marked this conversation as resolved.
Show resolved Hide resolved
else STATE_UNAVAILABLE
)

Expand Down