mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 22:07:10 +00:00
Adding additional switches and sensors for Tesla (#12241)
* Adding switch for maxrange charging and sensors for odometer and range * Fixing style errors
This commit is contained in:
parent
ae257651bf
commit
36e9f523d1
@ -44,14 +44,15 @@ class TeslaDeviceTracker(object):
|
|||||||
_LOGGER.debug("Updating device position: %s", name)
|
_LOGGER.debug("Updating device position: %s", name)
|
||||||
dev_id = slugify(device.uniq_name)
|
dev_id = slugify(device.uniq_name)
|
||||||
location = device.get_location()
|
location = device.get_location()
|
||||||
lat = location['latitude']
|
if location:
|
||||||
lon = location['longitude']
|
lat = location['latitude']
|
||||||
attrs = {
|
lon = location['longitude']
|
||||||
'trackr_id': dev_id,
|
attrs = {
|
||||||
'id': dev_id,
|
'trackr_id': dev_id,
|
||||||
'name': name
|
'id': dev_id,
|
||||||
}
|
'name': name
|
||||||
self.see(
|
}
|
||||||
dev_id=dev_id, host_name=name,
|
self.see(
|
||||||
gps=(lat, lon), attributes=attrs
|
dev_id=dev_id, host_name=name,
|
||||||
)
|
gps=(lat, lon), attributes=attrs
|
||||||
|
)
|
||||||
|
@ -78,6 +78,14 @@ class TeslaSensor(TeslaDevice, Entity):
|
|||||||
self._unit = TEMP_FAHRENHEIT
|
self._unit = TEMP_FAHRENHEIT
|
||||||
else:
|
else:
|
||||||
self._unit = TEMP_CELSIUS
|
self._unit = TEMP_CELSIUS
|
||||||
|
elif (self.tesla_device.bin_type == 0xA or
|
||||||
|
self.tesla_device.bin_type == 0xB):
|
||||||
|
self.current_value = self.tesla_device.get_value()
|
||||||
|
tesla_dist_unit = self.tesla_device.measurement
|
||||||
|
if tesla_dist_unit == 'LENGTH_MILES':
|
||||||
|
self._unit = LENGTH_MILES
|
||||||
|
else:
|
||||||
|
self._unit = LENGTH_KILOMETERS
|
||||||
else:
|
else:
|
||||||
self.current_value = self.tesla_device.get_value()
|
self.current_value = self.tesla_device.get_value()
|
||||||
if self.tesla_device.bin_type == 0x5:
|
if self.tesla_device.bin_type == 0x5:
|
||||||
|
@ -17,8 +17,13 @@ DEPENDENCIES = ['tesla']
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up the Tesla switch platform."""
|
"""Set up the Tesla switch platform."""
|
||||||
devices = [ChargerSwitch(device, hass.data[TESLA_DOMAIN]['controller'])
|
controller = hass.data[TESLA_DOMAIN]['devices']['controller']
|
||||||
for device in hass.data[TESLA_DOMAIN]['devices']['switch']]
|
devices = []
|
||||||
|
for device in hass.data[TESLA_DOMAIN]['devices']['switch']:
|
||||||
|
if device.bin_type == 0x8:
|
||||||
|
devices.append(ChargerSwitch(device, controller))
|
||||||
|
elif device.bin_type == 0x9:
|
||||||
|
devices.append(RangeSwitch(device, controller))
|
||||||
add_devices(devices, True)
|
add_devices(devices, True)
|
||||||
|
|
||||||
|
|
||||||
@ -38,7 +43,7 @@ class ChargerSwitch(TeslaDevice, SwitchDevice):
|
|||||||
|
|
||||||
def turn_off(self, **kwargs):
|
def turn_off(self, **kwargs):
|
||||||
"""Send the off command."""
|
"""Send the off command."""
|
||||||
_LOGGER.debug("Disable charging for: %s", self._name)
|
_LOGGER.debug("Disable charging for: %s", self._name)
|
||||||
self.tesla_device.stop_charge()
|
self.tesla_device.stop_charge()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -52,3 +57,35 @@ class ChargerSwitch(TeslaDevice, SwitchDevice):
|
|||||||
self.tesla_device.update()
|
self.tesla_device.update()
|
||||||
self._state = STATE_ON if self.tesla_device.is_charging() \
|
self._state = STATE_ON if self.tesla_device.is_charging() \
|
||||||
else STATE_OFF
|
else STATE_OFF
|
||||||
|
|
||||||
|
|
||||||
|
class RangeSwitch(TeslaDevice, SwitchDevice):
|
||||||
|
"""Representation of a Tesla max range charging switch."""
|
||||||
|
|
||||||
|
def __init__(self, tesla_device, controller):
|
||||||
|
"""Initialise 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 max range charging: %s", self._name)
|
||||||
|
self.tesla_device.set_max()
|
||||||
|
|
||||||
|
def turn_off(self, **kwargs):
|
||||||
|
"""Send the off command."""
|
||||||
|
_LOGGER.debug("Disable max range charging: %s", self._name)
|
||||||
|
self.tesla_device.set_standard()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_on(self):
|
||||||
|
"""Get whether the switch is in on state."""
|
||||||
|
return self._state == STATE_ON
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
"""Update the 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_maxrange() \
|
||||||
|
else STATE_OFF
|
||||||
|
Loading…
x
Reference in New Issue
Block a user