-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f09f5f
commit 985d3f9
Showing
11 changed files
with
82 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Coordinator to trigger entity updates.""" | ||
from __future__ import annotations | ||
|
||
from collections.abc import Callable | ||
from typing import Any, Callable | ||
|
||
from homeassistant.core import CALLBACK_TYPE, callback | ||
from homeassistant.helpers.update_coordinator import BaseDataUpdateCoordinatorProtocol | ||
|
||
|
||
class HacsUpdateCoordinator(BaseDataUpdateCoordinatorProtocol): | ||
"""Dispatch updates to update entities.""" | ||
|
||
def __init__(self) -> None: | ||
"""Initialize.""" | ||
self._listeners: dict[CALLBACK_TYPE, tuple[CALLBACK_TYPE, object | None]] = {} | ||
|
||
@callback | ||
def async_add_listener( | ||
self, update_callback: CALLBACK_TYPE, context: Any = None | ||
) -> Callable[[], None]: | ||
"""Listen for data updates.""" | ||
|
||
@callback | ||
def remove_listener() -> None: | ||
"""Remove update listener.""" | ||
self._listeners.pop(remove_listener) | ||
|
||
self._listeners[remove_listener] = (update_callback, context) | ||
|
||
return remove_listener | ||
|
||
@callback | ||
def async_update_listeners(self) -> None: | ||
"""Update all registered listeners.""" | ||
for update_callback, _ in list(self._listeners.values()): | ||
update_callback() |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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