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:
1 parent
f11f5255ae
commit
c4eab21736
7 files changed
+317
-115
No files matched your search
@@ -0,0 +1,53 @@
|
||||
"""Support for the Mopar vehicle switch."""
|
||||
import logging
|
||||
|
||||
from homeassistant.components.mopar import DOMAIN as MOPAR_DOMAIN
|
||||
from homeassistant.components.switch import SwitchDevice
|
||||
from homeassistant.const import STATE_ON, STATE_OFF
|
||||
|
||||
DEPENDENCIES = ['mopar']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||
"""Set up the Mopar Switch platform."""
|
||||
data = hass.data[MOPAR_DOMAIN]
|
||||
add_entities([MoparSwitch(data, index)
|
||||
for index, _ in enumerate(data.vehicles)], True)
|
||||
|
||||
|
||||
class MoparSwitch(SwitchDevice):
|
||||
"""Representation of a Mopar switch."""
|
||||
|
||||
def __init__(self, data, index):
|
||||
"""Initialize the Switch."""
|
||||
self._index = index
|
||||
self._name = '{} Switch'.format(data.get_vehicle_name(self._index))
|
||||
self._actuate = data.actuate
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the switch."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return True if the entity is on."""
|
||||
return self._state == STATE_ON
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return the polling requirement for this switch."""
|
||||
return False
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn on the Mopar Vehicle."""
|
||||
if self._actuate('engine_on', self._index):
|
||||
self._state = STATE_ON
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""Turn off the Mopar Vehicle."""
|
||||
if self._actuate('engine_off', self._index):
|
||||
self._state = STATE_OFF
|
||||
Reference in new issue
Block a user