mirror of
https://github.com/home-assistant/developers.home-assistant.git
synced 2025-07-27 11:16:28 +00:00
Fix Fetching Data example (#403)
This commit is contained in:
parent
f38d749f22
commit
1649c2d4d7
@ -28,9 +28,10 @@ This API will have a single method to fetch data for all the entities that you h
|
|||||||
Home Assistant provides a DataUpdateCoordinator class to help you manage this as efficiently as possible.
|
Home Assistant provides a DataUpdateCoordinator class to help you manage this as efficiently as possible.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.helpers import debounce, entity
|
from homeassistant.helpers import entity
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
@ -90,7 +91,7 @@ class MyEntity(entity.Entity):
|
|||||||
@property
|
@property
|
||||||
def available(self):
|
def available(self):
|
||||||
"""Return if entity is available."""
|
"""Return if entity is available."""
|
||||||
return not self.coordinator.failed_last_update
|
return self.coordinator.last_update_success
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
"""When entity is added to hass."""
|
"""When entity is added to hass."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user