Home Assistant Unofficial Reference
2024.12.1
coordinator.py
Go to the documentation of this file.
1
"""The Flux LED/MagicLight integration coordinator."""
2
3
from
__future__
import
annotations
4
5
from
datetime
import
timedelta
6
import
logging
7
from
typing
import
Final
8
9
from
flux_led.aio
import
AIOWifiLedBulb
10
11
from
homeassistant.config_entries
import
ConfigEntry
12
from
homeassistant.core
import
HomeAssistant
13
from
homeassistant.helpers.debounce
import
Debouncer
14
from
homeassistant.helpers.update_coordinator
import
DataUpdateCoordinator, UpdateFailed
15
16
from
.const
import
FLUX_LED_EXCEPTIONS
17
18
_LOGGER = logging.getLogger(__name__)
19
20
21
REQUEST_REFRESH_DELAY: Final = 2.0
22
23
24
class
FluxLedUpdateCoordinator
(
DataUpdateCoordinator
[
None
]):
25
"""DataUpdateCoordinator to gather data for a specific flux_led device."""
26
27
def
__init__
(
28
self, hass: HomeAssistant, device: AIOWifiLedBulb, entry: ConfigEntry
29
) ->
None
:
30
"""Initialize DataUpdateCoordinator to gather data for specific device."""
31
self.
device
device = device
32
self.
title
title = entry.title
33
self.
entry
entry = entry
34
self.
force_next_update
force_next_update =
False
35
super().
__init__
(
36
hass,
37
_LOGGER,
38
name=self.
device
device.ipaddr,
39
update_interval=
timedelta
(seconds=10),
40
# We don't want an immediate refresh since the device
41
# takes a moment to reflect the state change
42
request_refresh_debouncer=
Debouncer
(
43
hass, _LOGGER, cooldown=REQUEST_REFRESH_DELAY, immediate=
False
44
),
45
always_update=
False
,
46
)
47
48
async
def
_async_update_data
(self) -> None:
49
"""Fetch all device and sensor data from api."""
50
try
:
51
await self.
device
device.
async_update
(force=self.
force_next_update
force_next_update)
52
except
FLUX_LED_EXCEPTIONS
as
ex:
53
raise
UpdateFailed
(ex)
from
ex
54
finally
:
55
self.
force_next_update
force_next_update =
False
homeassistant.components.flux_led.coordinator.FluxLedUpdateCoordinator
Definition:
coordinator.py:24
homeassistant.components.flux_led.coordinator.FluxLedUpdateCoordinator.force_next_update
force_next_update
Definition:
coordinator.py:34
homeassistant.components.flux_led.coordinator.FluxLedUpdateCoordinator.entry
entry
Definition:
coordinator.py:33
homeassistant.components.flux_led.coordinator.FluxLedUpdateCoordinator.__init__
None __init__(self, HomeAssistant hass, AIOWifiLedBulb device, ConfigEntry entry)
Definition:
coordinator.py:29
homeassistant.components.flux_led.coordinator.FluxLedUpdateCoordinator.title
title
Definition:
coordinator.py:32
homeassistant.components.flux_led.coordinator.FluxLedUpdateCoordinator._async_update_data
None _async_update_data(self)
Definition:
coordinator.py:48
homeassistant.components.flux_led.coordinator.FluxLedUpdateCoordinator.device
device
Definition:
coordinator.py:31
homeassistant.helpers.debounce.Debouncer
Definition:
debounce.py:12
homeassistant.helpers.update_coordinator.DataUpdateCoordinator
Definition:
update_coordinator.py:61
homeassistant.helpers.update_coordinator.UpdateFailed
Definition:
update_coordinator.py:47
homeassistant.components.blebox.entity.async_update
None async_update(self)
Definition:
entity.py:34
homeassistant.components.nina.const.timedelta
timedelta
Definition:
const.py:11
homeassistant.config_entries
Definition:
config_entries.py:1
homeassistant.core
Definition:
core.py:1
homeassistant.helpers.debounce
Definition:
debounce.py:1
homeassistant.helpers.update_coordinator
Definition:
update_coordinator.py:1
core
homeassistant
components
flux_led
coordinator.py
Generated by
1.9.1