2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Tesla door locks."""
|
2017-08-31 04:13:02 +00:00
|
|
|
import logging
|
|
|
|
|
2020-04-25 16:02:41 +00:00
|
|
|
from homeassistant.components.lock import LockEntity
|
2017-08-31 04:13:02 +00:00
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import DOMAIN as TESLA_DOMAIN, TeslaDevice
|
|
|
|
|
2017-08-31 04:13:02 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2019-12-23 20:54:25 +00:00
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
|
|
"""Set up the Tesla binary_sensors by config_entry."""
|
|
|
|
entities = [
|
|
|
|
TeslaLock(
|
2020-08-27 11:56:20 +00:00
|
|
|
device,
|
|
|
|
hass.data[TESLA_DOMAIN][config_entry.entry_id]["coordinator"],
|
2019-12-23 20:54:25 +00:00
|
|
|
)
|
|
|
|
for device in hass.data[TESLA_DOMAIN][config_entry.entry_id]["devices"]["lock"]
|
2019-07-31 19:25:30 +00:00
|
|
|
]
|
2019-12-23 20:54:25 +00:00
|
|
|
async_add_entities(entities, True)
|
2017-08-31 04:13:02 +00:00
|
|
|
|
|
|
|
|
2020-04-25 16:02:41 +00:00
|
|
|
class TeslaLock(TeslaDevice, LockEntity):
|
2017-08-31 04:13:02 +00:00
|
|
|
"""Representation of a Tesla door lock."""
|
|
|
|
|
2019-11-15 04:15:58 +00:00
|
|
|
async def async_lock(self, **kwargs):
|
2017-08-31 04:13:02 +00:00
|
|
|
"""Send the lock command."""
|
2020-08-08 03:16:28 +00:00
|
|
|
_LOGGER.debug("Locking doors for: %s", self.name)
|
2019-11-15 04:15:58 +00:00
|
|
|
await self.tesla_device.lock()
|
2017-08-31 04:13:02 +00:00
|
|
|
|
2019-11-15 04:15:58 +00:00
|
|
|
async def async_unlock(self, **kwargs):
|
2017-08-31 04:13:02 +00:00
|
|
|
"""Send the unlock command."""
|
2020-08-08 03:16:28 +00:00
|
|
|
_LOGGER.debug("Unlocking doors for: %s", self.name)
|
2019-11-15 04:15:58 +00:00
|
|
|
await self.tesla_device.unlock()
|
2017-08-31 04:13:02 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_locked(self):
|
|
|
|
"""Get whether the lock is in locked state."""
|
2020-08-08 03:16:28 +00:00
|
|
|
if self.tesla_device.is_locked() is None:
|
|
|
|
return None
|
|
|
|
return self.tesla_device.is_locked()
|