Tesla platform (#9211)
* Tesla support implemetation * requirements_all.txt fix * .coveragerc fix * logging-too-many-args fix * logging-too-many-args attempt 2 * Post-review fixes. * requirements version fix * requirements * Lint fix * Hot fix * requirements_all.txt fix * Review preparation. * 1. Linting fix. 2. Minimal value for SCAN_INTERVAL hardcoded to 300 sec (to prevent possible ban form Tesla) * Removed redundant whitespace. * Fixed components according to @MartinHjelmare proposals and remarks. * .coveragerc as @MartinHjelmare suggested. * Minor changes * Fix docstrings * Update ordering * Update quotes * Minor changes * Update quotes
This commit is contained in:
parent
10e8aea46b
commit
5f445b4a13
8 changed files with 447 additions and 0 deletions
57
homeassistant/components/lock/tesla.py
Normal file
57
homeassistant/components/lock/tesla.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
"""
|
||||
Support for Tesla door locks.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/lock.tesla/
|
||||
"""
|
||||
import logging
|
||||
|
||||
from homeassistant.components.lock import ENTITY_ID_FORMAT, LockDevice
|
||||
from homeassistant.components.tesla import DOMAIN as TESLA_DOMAIN, TeslaDevice
|
||||
from homeassistant.const import STATE_LOCKED, STATE_UNLOCKED
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEPENDENCIES = ['tesla']
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up the Tesla lock platform."""
|
||||
devices = [TeslaLock(device, hass.data[TESLA_DOMAIN]['controller'])
|
||||
for device in hass.data[TESLA_DOMAIN]['devices']['lock']]
|
||||
add_devices(devices, True)
|
||||
|
||||
|
||||
class TeslaLock(TeslaDevice, LockDevice):
|
||||
"""Representation of a Tesla door lock."""
|
||||
|
||||
def __init__(self, tesla_device, controller):
|
||||
"""Initialisation of the lock."""
|
||||
self._state = None
|
||||
super().__init__(tesla_device, controller)
|
||||
self._name = self.tesla_device.name
|
||||
self.entity_id = ENTITY_ID_FORMAT.format(self.tesla_id)
|
||||
|
||||
def lock(self, **kwargs):
|
||||
"""Send the lock command."""
|
||||
_LOGGER.debug("Locking doors for: %s", self._name)
|
||||
self.tesla_device.lock()
|
||||
self._state = STATE_LOCKED
|
||||
|
||||
def unlock(self, **kwargs):
|
||||
"""Send the unlock command."""
|
||||
_LOGGER.debug("Unlocking doors for: %s", self._name)
|
||||
self.tesla_device.unlock()
|
||||
self._state = STATE_UNLOCKED
|
||||
|
||||
@property
|
||||
def is_locked(self):
|
||||
"""Get whether the lock is in locked state."""
|
||||
return self._state == STATE_LOCKED
|
||||
|
||||
def update(self):
|
||||
"""Updating state of the lock."""
|
||||
_LOGGER.debug("Updating state for: %s", self._name)
|
||||
self.tesla_device.update()
|
||||
self._state = STATE_LOCKED if self.tesla_device.is_locked() \
|
||||
else STATE_UNLOCKED
|
Loading…
Add table
Add a link
Reference in a new issue