Skip to content

Commit

Permalink
Update lock.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sarangcr03 authored Oct 21, 2023
1 parent 4602a5a commit 9e5514c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions custom_components/fordpass/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Add the lock from the config."""
entry = hass.data[DOMAIN][config_entry.entry_id][COORDINATOR]

lock = Lock(entry)

all_doors_status = next((item for item in lock.coordinator.data["metrics"]["doorLockStatus"] if item["vehicleDoor"] == "ALL_DOORS"), None)
door_lock_status = lock.coordinator.data.get("metrics", {}).get("doorLockStatus", [])
all_doors_status = next((item for item in door_lock_status if item.get("vehicleDoor") == "ALL_DOORS"), None)

if all_doors_status and all_doors_status["value"] != "ERROR":
if all_doors_status and all_doors_status.get("value") != "ERROR":
async_add_entities([lock], False)
else:
_LOGGER.debug("Ford model doesn't support remote locking")
Expand All @@ -28,7 +28,7 @@ def __init__(self, coordinator):
"""Initialize."""
self._device_id = "fordpass_doorlock"
self.coordinator = coordinator
self.data = coordinator.data["metrics"]
self.data = coordinator.data.get("metrics", {})

# Required for HA 2022.7
self.coordinator_context = object()
Expand Down Expand Up @@ -63,10 +63,11 @@ async def async_unlock(self, **kwargs):
@property
def is_locked(self):
"""Determine if the lock is locked."""
all_doors_status = next((item for item in self.coordinator.data["metrics"]["doorLockStatus"] if item["vehicleDoor"] == "ALL_DOORS"), None)
door_lock_status = self.coordinator.data.get("metrics", {}).get("doorLockStatus", [])
all_doors_status = next((item for item in door_lock_status if item.get("vehicleDoor") == "ALL_DOORS"), None)
if not all_doors_status:
return None
return all_doors_status["value"] == "LOCKED" or all_doors_status["value"] == "DOUBLE_LOCKED"
return all_doors_status.get("value") == "LOCKED" or all_doors_status.get("value") == "DOUBLE_LOCKED"

@property
def icon(self):
Expand Down

0 comments on commit 9e5514c

Please sign in to comment.