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
3 changed files with 60 additions and 14 deletions
|
@ -44,6 +44,7 @@ class TeslaDeviceTracker(object):
|
|||
_LOGGER.debug("Updating device position: %s", name)
|
||||
dev_id = slugify(device.uniq_name)
|
||||
location = device.get_location()
|
||||
if location:
|
||||
lat = location['latitude']
|
||||
lon = location['longitude']
|
||||
attrs = {
|
||||
|
|
|
@ -78,6 +78,14 @@ class TeslaSensor(TeslaDevice, Entity):
|
|||
self._unit = TEMP_FAHRENHEIT
|
||||
else:
|
||||
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:
|
||||
self.current_value = self.tesla_device.get_value()
|
||||
if self.tesla_device.bin_type == 0x5:
|
||||
|
|
|
@ -17,8 +17,13 @@ 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']]
|
||||
controller = hass.data[TESLA_DOMAIN]['devices']['controller']
|
||||
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)
|
||||
|
||||
|
||||
|
@ -52,3 +57,35 @@ class ChargerSwitch(TeslaDevice, SwitchDevice):
|
|||
self.tesla_device.update()
|
||||
self._state = STATE_ON if self.tesla_device.is_charging() \
|
||||
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…
Add table
Add a link
Reference in a new issue