-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
6c030c5
commit 34ef406
Showing
1 changed file
with
18 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
import asyncio | ||
|
||
from homeassistant.components.local_file.camera import LocalFile | ||
|
||
|
||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): | ||
async def async_setup_platform( | ||
hass, config, async_add_entities, discovery_info=None, retry=3 | ||
): | ||
dev = [] | ||
for home in hass.data["tibber"].get_homes(only_active=True): | ||
name = home.info["viewer"]["home"]["appNickname"] | ||
if name is None: | ||
name = home.info["viewer"]["home"]["address"].get("address1", "") | ||
path = hass.config.path(f"www/prices_{name}.png") | ||
dev.append(LocalFile(name, path)) | ||
try: | ||
for home in hass.data["tibber"].get_homes(only_active=True): | ||
name = home.info["viewer"]["home"]["appNickname"] | ||
if name is None: | ||
name = home.info["viewer"]["home"]["address"].get("address1", "") | ||
path = hass.config.path(f"www/prices_{name}.png") | ||
dev.append(LocalFile(name, path)) | ||
except KeyError: | ||
await asyncio.sleep(10) | ||
if retry > 0: | ||
return await async_setup_platform( | ||
hass, config, async_add_entities, discovery_info=None, retry=retry - 1 | ||
) | ||
|
||
async_add_entities(dev) |