Tesla bug fixes. (#9774)

* Tesla bug fixes.

* Added myself to CODEOWNERS for tesla.
pull/9781/head
Sergey Isachenko 2017-10-09 14:38:00 +03:00 committed by Andrey
parent 43d77729c5
commit 9abd0fb92f
8 changed files with 60 additions and 10 deletions

View File

@ -57,5 +57,7 @@ homeassistant/components/switch/tplink.py @rytilahti
homeassistant/components/*/broadlink.py @danielhiversen
homeassistant/components/*/rfxtrx.py @danielhiversen
homeassistant/components/tesla.py @zabuldon
homeassistant/components/*/tesla.py @zabuldon
homeassistant/components/*/xiaomi_aqara.py @danielhiversen
homeassistant/components/*/xiaomi_miio.py @rytilahti

View File

@ -30,7 +30,6 @@ class TeslaBinarySensor(TeslaDevice, BinarySensorDevice):
def __init__(self, tesla_device, controller, sensor_type):
"""Initialisation of binary sensor."""
super().__init__(tesla_device, controller)
self._name = self.tesla_device.name
self._state = False
self.entity_id = ENTITY_ID_FORMAT.format(self.tesla_id)
self._sensor_type = sensor_type

View File

@ -35,7 +35,6 @@ class TeslaThermostat(TeslaDevice, ClimateDevice):
self.entity_id = ENTITY_ID_FORMAT.format(self.tesla_id)
self._target_temperature = None
self._temperature = None
self._name = self.tesla_device.name
@property
def current_operation(self):

View File

@ -29,20 +29,17 @@ class TeslaLock(TeslaDevice, LockDevice):
"""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):

View File

@ -49,7 +49,6 @@ class TeslaSensor(TeslaDevice, Entity):
self.entity_id = ENTITY_ID_FORMAT.format(
'{}_{}'.format(self.tesla_id, self.type))
else:
self._name = self.tesla_device.name
self.entity_id = ENTITY_ID_FORMAT.format(self.tesla_id)
@property

View File

@ -0,0 +1,53 @@
"""
Support for Tesla charger switch.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.tesla/
"""
import logging
from homeassistant.components.switch import ENTITY_ID_FORMAT, SwitchDevice
from homeassistant.components.tesla import DOMAIN as TESLA_DOMAIN, TeslaDevice
from homeassistant.const import STATE_ON, STATE_OFF
_LOGGER = logging.getLogger(__name__)
DEPENDENCIES = ['tesla']
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the Tesla switch platform."""
devices = [ChargerSwitch(device, hass.data[TESLA_DOMAIN]['controller'])
for device in hass.data[TESLA_DOMAIN]['devices']['switch']]
add_devices(devices, True)
class ChargerSwitch(TeslaDevice, SwitchDevice):
"""Representation of a Tesla charger switch."""
def __init__(self, tesla_device, controller):
"""Initialisation of the switch."""
self._state = None
super().__init__(tesla_device, controller)
self.entity_id = ENTITY_ID_FORMAT.format(self.tesla_id)
def turn_on(self, **kwargs):
"""Send the on command."""
_LOGGER.debug("Enable charging: %s", self._name)
self.tesla_device.start_charge()
def turn_off(self, **kwargs):
"""Send the off command."""
_LOGGER.debug("Disable charging for: %s", self._name)
self.tesla_device.stop_charge()
@property
def is_on(self):
"""Get whether the switch is in on state."""
return self._state == STATE_ON
def update(self):
"""Updating state of the switch."""
_LOGGER.debug("Updating state for: %s", self._name)
self.tesla_device.update()
self._state = STATE_ON if self.tesla_device.is_charging() \
else STATE_OFF

View File

@ -17,7 +17,7 @@ from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.entity import Entity
from homeassistant.util import slugify
REQUIREMENTS = ['teslajsonpy==0.0.11']
REQUIREMENTS = ['teslajsonpy==0.0.17']
DOMAIN = 'tesla'
@ -39,7 +39,7 @@ NOTIFICATION_ID = 'tesla_integration_notification'
NOTIFICATION_TITLE = 'Tesla integration setup'
TESLA_COMPONENTS = [
'sensor', 'lock', 'climate', 'binary_sensor', 'device_tracker'
'sensor', 'lock', 'climate', 'binary_sensor', 'device_tracker', 'switch'
]
@ -55,7 +55,8 @@ def setup(hass, base_config):
if hass.data.get(DOMAIN) is None:
try:
hass.data[DOMAIN] = {
'controller': teslaApi(email, password, update_interval),
'controller': teslaApi(
email, password, update_interval),
'devices': defaultdict(list)
}
_LOGGER.debug("Connected to the Tesla API.")

View File

@ -993,7 +993,7 @@ tellduslive==0.3.4
temperusb==1.5.3
# homeassistant.components.tesla
teslajsonpy==0.0.11
teslajsonpy==0.0.17
# homeassistant.components.thingspeak
thingspeak==0.4.1