Skip to content

Commit

Permalink
Merge pull request #331 from dougiteixeira/fix-update-packages
Browse files Browse the repository at this point in the history
Fix update sensor availability available for packages
  • Loading branch information
dougiteixeira authored Jun 24, 2024
2 parents 2bebc58 + 000e2e8 commit 2c57aa9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
34 changes: 20 additions & 14 deletions custom_components/proxmoxve/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import UNDEFINED
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from . import COORDINATORS, DOMAIN, async_migrate_old_unique_ids, device_info
from .const import CONF_LXC, CONF_NODES, CONF_QEMU, ProxmoxKeyAPIParse, ProxmoxType
from .const import (
CONF_LXC,
CONF_NODES,
CONF_QEMU,
LOGGER,
ProxmoxKeyAPIParse,
ProxmoxType,
)
from .entity import ProxmoxEntity, ProxmoxEntityDescription


Expand Down Expand Up @@ -120,7 +128,7 @@ async def async_setup_binary_sensors_nodes(
# unfound node case
if coordinator.data is not None:
for description in PROXMOX_BINARYSENSOR_NODES:
if getattr(coordinator.data, description.key, False):
if getattr(coordinator.data, description.key, False) != UNDEFINED:
sensors.append(
create_binary_sensor(
coordinator=coordinator,
Expand All @@ -139,7 +147,10 @@ async def async_setup_binary_sensors_nodes(
if f"{ProxmoxType.Update}_{node}" in coordinators:
coordinator_updates = coordinators[f"{ProxmoxType.Update}_{node}"]
for description in PROXMOX_BINARYSENSOR_UPDATES:
if getattr(coordinator_updates.data, description.key, False):
if (
getattr(coordinator_updates.data, description.key, False)
!= UNDEFINED
):
sensors.append(
create_binary_sensor(
coordinator=coordinator_updates,
Expand Down Expand Up @@ -211,7 +222,7 @@ async def async_setup_binary_sensors_qemu(
continue
for description in PROXMOX_BINARYSENSOR_VM:
if description.api_category in (None, ProxmoxType.QEMU):
if getattr(coordinator.data, description.key, False):
if getattr(coordinator.data, description.key, False) != UNDEFINED:
sensors.append(
create_binary_sensor(
coordinator=coordinator,
Expand Down Expand Up @@ -251,7 +262,7 @@ async def async_setup_binary_sensors_lxc(
continue
for description in PROXMOX_BINARYSENSOR_VM:
if description.api_category in (None, ProxmoxType.LXC):
if getattr(coordinator.data, description.key, False):
if getattr(coordinator.data, description.key, False) != UNDEFINED:
sensors.append(
create_binary_sensor(
coordinator=coordinator,
Expand Down Expand Up @@ -309,18 +320,13 @@ def is_on(self) -> bool:
if (data := self.coordinator.data) is None:
return False

if not getattr(data, self.entity_description.key):
if not (data_value := getattr(data, self.entity_description.key)):
return False

if self.entity_description.inverted:
return (
getattr(data, self.entity_description.key)
not in self.entity_description.on_value
)
return (
getattr(data, self.entity_description.key)
in self.entity_description.on_value
)
return data_value not in self.entity_description.on_value

return data_value in self.entity_description.on_value

@property
def available(self) -> bool:
Expand Down
8 changes: 2 additions & 6 deletions custom_components/proxmoxve/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,16 +507,12 @@ async def _async_update_data(self) -> ProxmoxUpdateData:
)

updates_list = []
total = 0
for update in api_status:
updates_list.append(f"{update['Title']} - {update['Version']}")
total += 1

updates_list.sort()

update_avail = False
if total > 0:
update_avail = True
total = len(updates_list) if updates_list is not None else 0
update_avail = total > 0

return ProxmoxUpdateData(
type=ProxmoxType.Update,
Expand Down

0 comments on commit 2c57aa9

Please sign in to comment.