Skip to content

Commit

Permalink
Merge pull request #162 from dougiteixeira/avoid-erros-coordinator
Browse files Browse the repository at this point in the history
Avoid integration errors when the coordinator does not exist
  • Loading branch information
dougiteixeira authored Nov 12, 2023
2 parents d5533ab + 2148bfe commit f19e764
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 38 deletions.
48 changes: 31 additions & 17 deletions custom_components/proxmoxve/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ async def async_setup_entry(
coordinators = hass.data[DOMAIN][config_entry.entry_id][COORDINATORS]

for node in config_entry.data[CONF_NODES]:
coordinator = coordinators[node]
if node in coordinators:
coordinator = coordinators[node]
else:
continue

# unfound node case
if coordinator.data is not None:
for description in PROXMOX_BINARYSENSOR_NODES:
Expand All @@ -101,25 +105,31 @@ async def async_setup_entry(
resource_id=node,
)
)
coordinator_updates = coordinators[f"{ProxmoxType.Update}_{node}"]
for description in PROXMOX_BINARYSENSOR_UPDATES:
sensors.append(
create_binary_sensor(
coordinator=coordinator_updates,
config_entry=config_entry,
info_device=device_info(
hass=hass,

if f"{ProxmoxType.Update}_{node}" in coordinators:
coordinator_updates = coordinators[f"{ProxmoxType.Update}_{node}"]
for description in PROXMOX_BINARYSENSOR_UPDATES:
sensors.append(
create_binary_sensor(
coordinator=coordinator_updates,
config_entry=config_entry,
api_category=ProxmoxType.Update,
node=node,
),
description=description,
resource_id=node,
info_device=device_info(
hass=hass,
config_entry=config_entry,
api_category=ProxmoxType.Update,
node=node,
),
description=description,
resource_id=node,
)
)
)

for vm_id in config_entry.data[CONF_QEMU]:
coordinator = coordinators[vm_id]
if vm_id in coordinators:
coordinator = coordinators[vm_id]
else:
continue

# unfound vm case
if coordinator.data is None:
continue
Expand All @@ -141,7 +151,11 @@ async def async_setup_entry(
)

for container_id in config_entry.data[CONF_LXC]:
coordinator = coordinators[container_id]
if container_id in coordinators:
coordinator = coordinators[container_id]
else:
continue

# unfound container case
if coordinator.data is None:
continue
Expand Down
17 changes: 14 additions & 3 deletions custom_components/proxmoxve/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ async def async_setup_entry(
proxmox_client = hass.data[DOMAIN][config_entry.entry_id][PROXMOX_CLIENT]

for node in config_entry.data[CONF_NODES]:
coordinator = coordinators[node]
if node in coordinators:
coordinator = coordinators[node]
else:
continue

# unfound vm case
if coordinator.data is not None:
for description in PROXMOX_BUTTON_NODE:
Expand All @@ -172,7 +176,11 @@ async def async_setup_entry(
)

for vm_id in config_entry.data[CONF_QEMU]:
coordinator = coordinators[vm_id]
if vm_id in coordinators:
coordinator = coordinators[vm_id]
else:
continue

# unfound vm case
if coordinator.data is None:
continue
Expand All @@ -196,7 +204,10 @@ async def async_setup_entry(
)

for ct_id in config_entry.data[CONF_LXC]:
coordinator = coordinators[ct_id]
if ct_id in coordinators:
coordinator = coordinators[ct_id]
else:
continue
# unfound container case
if coordinator.data is None:
continue
Expand Down
54 changes: 36 additions & 18 deletions custom_components/proxmoxve/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,11 @@ async def async_setup_entry(
coordinators = hass.data[DOMAIN][config_entry.entry_id][COORDINATORS]

for node in config_entry.data[CONF_NODES]:
coordinator = coordinators[node]
if node in coordinators:
coordinator = coordinators[node]
else:
continue

# unfound vm case
if coordinator.data is not None:
for description in PROXMOX_SENSOR_NODES:
Expand All @@ -369,25 +373,31 @@ async def async_setup_entry(
config_entry=config_entry,
)
)
coordinator_updates = coordinators[f"{ProxmoxType.Update}_{node}"]
for description in PROXMOX_SENSOR_UPDATE:
sensors.append(
create_sensor(
coordinator=coordinator_updates,
info_device=device_info(
hass=hass,

if f"{ProxmoxType.Update}_{node}" in coordinators:
coordinator_updates = coordinators[f"{ProxmoxType.Update}_{node}"]
for description in PROXMOX_SENSOR_UPDATE:
sensors.append(
create_sensor(
coordinator=coordinator_updates,
info_device=device_info(
hass=hass,
config_entry=config_entry,
api_category=ProxmoxType.Update,
node=node,
),
description=description,
resource_id=node,
config_entry=config_entry,
api_category=ProxmoxType.Update,
node=node,
),
description=description,
resource_id=node,
config_entry=config_entry,
)
)
)

for vm_id in config_entry.data[CONF_QEMU]:
coordinator = coordinators[vm_id]
if vm_id in coordinators:
coordinator = coordinators[vm_id]
else:
continue

# unfound vm case
if coordinator.data is None:
continue
Expand All @@ -409,7 +419,11 @@ async def async_setup_entry(
)

for ct_id in config_entry.data[CONF_LXC]:
coordinator = coordinators[ct_id]
if ct_id in coordinators:
coordinator = coordinators[ct_id]
else:
continue

# unfound container case
if coordinator.data is None:
continue
Expand All @@ -431,7 +445,11 @@ async def async_setup_entry(
)

for storage_id in config_entry.data[CONF_STORAGE]:
coordinator = coordinators[storage_id]
if storage_id in coordinators:
coordinator = coordinators[storage_id]
else:
continue

# unfound container case
if coordinator.data is None:
continue
Expand Down

0 comments on commit f19e764

Please sign in to comment.