mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 05:37:44 +00:00
Fix Control4 light setup issues (#38952)
* catch KeyError and UnboundLocalError in light setup * add check for no dimmer info from control4 * use existence of light_level data to enable dimming * check if light data is not in dimmer and non_dimmer * add item_variables logging * add await to item_variables call * add full item dump * remove full item list * change logging message * fix typo * reduce code inside try and add all entities at once * Apply suggestions from code review Co-authored-by: J. Nick Koston <nick@koston.org> * format with black Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
bdc5af8dd2
commit
e626937147
@ -73,40 +73,64 @@ async def async_setup_entry(
|
||||
await dimmer_coordinator.async_refresh()
|
||||
|
||||
items_of_category = await get_items_of_category(hass, entry, CONTROL4_CATEGORY)
|
||||
|
||||
entity_list = []
|
||||
for item in items_of_category:
|
||||
if item["type"] == CONTROL4_ENTITY_TYPE:
|
||||
item_name = item["name"]
|
||||
item_id = item["id"]
|
||||
item_parent_id = item["parentId"]
|
||||
item_is_dimmer = item["capabilities"]["dimmer"]
|
||||
try:
|
||||
if item["type"] == CONTROL4_ENTITY_TYPE:
|
||||
item_name = item["name"]
|
||||
item_id = item["id"]
|
||||
item_parent_id = item["parentId"]
|
||||
|
||||
if item_is_dimmer:
|
||||
item_coordinator = dimmer_coordinator
|
||||
item_manufacturer = None
|
||||
item_device_name = None
|
||||
item_model = None
|
||||
|
||||
for parent_item in items_of_category:
|
||||
if parent_item["id"] == item_parent_id:
|
||||
item_manufacturer = parent_item["manufacturer"]
|
||||
item_device_name = parent_item["name"]
|
||||
item_model = parent_item["model"]
|
||||
else:
|
||||
item_coordinator = non_dimmer_coordinator
|
||||
|
||||
for parent_item in items_of_category:
|
||||
if parent_item["id"] == item_parent_id:
|
||||
item_manufacturer = parent_item["manufacturer"]
|
||||
item_device_name = parent_item["name"]
|
||||
item_model = parent_item["model"]
|
||||
async_add_entities(
|
||||
[
|
||||
Control4Light(
|
||||
entry_data,
|
||||
entry,
|
||||
item_coordinator,
|
||||
item_name,
|
||||
item_id,
|
||||
item_device_name,
|
||||
item_manufacturer,
|
||||
item_model,
|
||||
item_parent_id,
|
||||
item_is_dimmer,
|
||||
)
|
||||
],
|
||||
True,
|
||||
continue
|
||||
except KeyError:
|
||||
_LOGGER.exception(
|
||||
"Unknown device properties received from Control4: %s", item,
|
||||
)
|
||||
continue
|
||||
|
||||
if item_id in dimmer_coordinator.data:
|
||||
item_is_dimmer = True
|
||||
item_coordinator = dimmer_coordinator
|
||||
elif item_id in non_dimmer_coordinator.data:
|
||||
item_is_dimmer = False
|
||||
item_coordinator = non_dimmer_coordinator
|
||||
else:
|
||||
director = entry_data[CONF_DIRECTOR]
|
||||
item_variables = await director.getItemVariables(item_id)
|
||||
_LOGGER.warning(
|
||||
"Couldn't get light state data for %s, skipping setup. Available variables from Control4: %s",
|
||||
item_name,
|
||||
item_variables,
|
||||
)
|
||||
continue
|
||||
|
||||
entity_list.append(
|
||||
Control4Light(
|
||||
entry_data,
|
||||
entry,
|
||||
item_coordinator,
|
||||
item_name,
|
||||
item_id,
|
||||
item_device_name,
|
||||
item_manufacturer,
|
||||
item_model,
|
||||
item_parent_id,
|
||||
item_is_dimmer,
|
||||
)
|
||||
)
|
||||
|
||||
async_add_entities(entity_list, True)
|
||||
|
||||
|
||||
class Control4Light(Control4Entity, LightEntity):
|
||||
|
Loading…
x
Reference in New Issue
Block a user