40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
"""Support for Volvo On Call locks."""
|
|
from __future__ import annotations
|
|
|
|
from homeassistant.components.lock import LockEntity
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
|
|
|
from . import DATA_KEY, VolvoEntity
|
|
|
|
|
|
async def async_setup_platform(
|
|
hass: HomeAssistant,
|
|
config: ConfigType,
|
|
async_add_entities: AddEntitiesCallback,
|
|
discovery_info: DiscoveryInfoType | None = None,
|
|
) -> None:
|
|
"""Set up the Volvo On Call lock."""
|
|
if discovery_info is None:
|
|
return
|
|
|
|
async_add_entities([VolvoLock(hass.data[DATA_KEY], *discovery_info)])
|
|
|
|
|
|
class VolvoLock(VolvoEntity, LockEntity):
|
|
"""Represents a car lock."""
|
|
|
|
@property
|
|
def is_locked(self):
|
|
"""Return true if lock is locked."""
|
|
return self.instrument.is_locked
|
|
|
|
async def async_lock(self, **kwargs):
|
|
"""Lock the car."""
|
|
await self.instrument.lock()
|
|
|
|
async def async_unlock(self, **kwargs):
|
|
"""Unlock the car."""
|
|
await self.instrument.unlock()
|