Skip to content

Commit

Permalink
Added doors locked and open sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-r committed Jan 20, 2024
1 parent ec7a423 commit c7c55a1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ This integration exposes the following entities. Please note that entities will
* Binary Sensors
* Car Plugged In (EV Only)
* Car Charging (EV Only)
* Doors Locked
* Sensors
* Battery Level
* Charge Time
Expand Down
22 changes: 19 additions & 3 deletions custom_components/nissan_connect/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from homeassistant.const import STATE_UNKNOWN

from .base import KamereonEntity
from .kamereon import ChargingStatus, PluggedStatus, Feature
from .kamereon import ChargingStatus, PluggedStatus, LockStatus, Feature
from .const import DOMAIN, DATA_VEHICLES, DATA_COORDINATOR

_LOGGER = logging.getLogger(__name__)
Expand All @@ -20,8 +20,10 @@ async def async_setup_entry(hass, config, async_add_entities):

for vehicle in data:
if Feature.BATTERY_STATUS in data[vehicle].features:
entities.append(ChargingStatusEntity(coordinator, data[vehicle]))
entities.append(PluggedStatusEntity(coordinator, data[vehicle]))
entities += [ChargingStatusEntity(coordinator, data[vehicle]),
PluggedStatusEntity(coordinator, data[vehicle])]
if Feature.APP_DOOR_LOCKING in data[vehicle].features:
entities += [LockStatusEntity(coordinator, data[vehicle])]

async_add_entities(entities, update_before_add=True)

Expand Down Expand Up @@ -79,3 +81,17 @@ def device_state_attributes(self):
'last_updated': self.vehicle.battery_status_last_updated,
})
return a


class LockStatusEntity(KamereonEntity, BinarySensorEntity):
_attr_device_class = BinarySensorDeviceClass.LOCK
_attr_name = "Doors Locked"

@property
def icon(self):
"""Return the icon."""
return 'mdi:car-door-lock' if self.vehicle.lock_status == LockStatus.LOCKED else 'mdi:car-door-lock-open'

@property
def is_on(self):
return self.vehicle.lock_status == LockStatus.UNLOCKED

0 comments on commit c7c55a1

Please sign in to comment.