Add tradfri api call error handling (#39681)

Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
Martin Hjelmare 2020-09-05 23:02:32 +02:00 committed by GitHub
parent 29c1bec0f3
commit b6630a48b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 124 additions and 93 deletions

View file

@ -2,7 +2,7 @@
from homeassistant.components.switch import SwitchEntity
from .base_class import TradfriBaseDevice
from .const import CONF_GATEWAY_ID, DOMAIN, KEY_API, KEY_GATEWAY
from .const import CONF_GATEWAY_ID, DEVICES, DOMAIN, KEY_API
async def async_setup_entry(hass, config_entry, async_add_entities):
@ -10,10 +10,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
gateway_id = config_entry.data[CONF_GATEWAY_ID]
tradfri_data = hass.data[DOMAIN][config_entry.entry_id]
api = tradfri_data[KEY_API]
gateway = tradfri_data[KEY_GATEWAY]
devices = tradfri_data[DEVICES]
devices_commands = await api(gateway.get_devices())
devices = await api(devices_commands)
switches = [dev for dev in devices if dev.has_socket_control]
if switches:
async_add_entities(