Mopar split (#21526)

* Split out mopar into a component and sensor platform

* Add the mopar switch platform

* Add the mopar lock platform

* Clean up and bump version

* Update per review

* Re-add service to trigger horn

* Clean up again

* Don't call async from sync context

* Lint

* Implement changes from review

* Lint

* A little more clean up
This commit is contained in:
Rohan Kapoor 2019-03-27 20:09:36 -07:00 committed by Paulus Schoutsen
parent f11f5255ae
commit c4eab21736
7 changed files with 317 additions and 115 deletions

View file

@ -0,0 +1,55 @@
"""Support for the Mopar vehicle lock."""
import logging
from homeassistant.components.lock import LockDevice
from homeassistant.components.mopar import (
DOMAIN as MOPAR_DOMAIN
)
from homeassistant.const import STATE_LOCKED, STATE_UNLOCKED
DEPENDENCIES = ['mopar']
_LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Mopar lock platform."""
data = hass.data[MOPAR_DOMAIN]
add_entities([MoparLock(data, index)
for index, _ in enumerate(data.vehicles)], True)
class MoparLock(LockDevice):
"""Representation of a Mopar vehicle lock."""
def __init__(self, data, index):
"""Initialize the Mopar lock."""
self._index = index
self._name = '{} Lock'.format(data.get_vehicle_name(self._index))
self._actuate = data.actuate
self._state = None
@property
def name(self):
"""Return the name of the lock."""
return self._name
@property
def is_locked(self):
"""Return true if vehicle is locked."""
return self._state == STATE_LOCKED
@property
def should_poll(self):
"""Return the polling requirement for this lock."""
return False
def lock(self, **kwargs):
"""Lock the vehicle."""
if self._actuate('lock', self._index):
self._state = STATE_LOCKED
def unlock(self, **kwargs):
"""Unlock the vehicle."""
if self._actuate('unlock', self._index):
self._state = STATE_UNLOCKED