Skip to content

Commit

Permalink
Update camera.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielhiversen authored Nov 9, 2020
1 parent 6c030c5 commit 34ef406
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions custom_components/tibber_custom/camera.py
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)

0 comments on commit 34ef406

Please sign in to comment.