Reduce unifiprotect update overhead (#96626)

This commit is contained in:
J. Nick Koston 2023-07-16 06:24:27 -10:00 committed by GitHub
parent cde1903e8b
commit f2556df7db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 73 additions and 111 deletions

View file

@ -3,7 +3,6 @@ from __future__ import annotations
from collections.abc import Callable, Coroutine
from dataclasses import dataclass
from datetime import timedelta
from enum import Enum
import logging
from typing import Any, Generic, TypeVar, cast
@ -77,10 +76,8 @@ class ProtectEventMixin(ProtectRequiredKeysMixin[T]):
return cast(Event, get_nested_attr(obj, self.ufp_event_obj))
return None
def get_is_on(self, obj: T) -> bool:
def get_is_on(self, event: Event | None) -> bool:
"""Return value if event is active."""
event = self.get_event_obj(obj)
if event is None:
return False
@ -88,17 +85,7 @@ class ProtectEventMixin(ProtectRequiredKeysMixin[T]):
value = now > event.start
if value and event.end is not None and now > event.end:
value = False
# only log if the recent ended recently
if event.end + timedelta(seconds=10) < now:
_LOGGER.debug(
"%s (%s): end ended at %s",
self.name,
obj.mac,
event.end.isoformat(),
)
if value:
_LOGGER.debug("%s (%s): value is on", self.name, obj.mac)
return value