Tesla platform (#9211)
* Tesla support implemetation * requirements_all.txt fix * .coveragerc fix * logging-too-many-args fix * logging-too-many-args attempt 2 * Post-review fixes. * requirements version fix * requirements * Lint fix * Hot fix * requirements_all.txt fix * Review preparation. * 1. Linting fix. 2. Minimal value for SCAN_INTERVAL hardcoded to 300 sec (to prevent possible ban form Tesla) * Removed redundant whitespace. * Fixed components according to @MartinHjelmare proposals and remarks. * .coveragerc as @MartinHjelmare suggested. * Minor changes * Fix docstrings * Update ordering * Update quotes * Minor changes * Update quotes
This commit is contained in:
1 parent
10e8aea46b
commit
5f445b4a13
8 files changed
+447
No files matched your search
@@ -0,0 +1,57 @@
|
||||
"""
|
||||
Support for the Tesla platform.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/device_tracker.tesla/
|
||||
"""
|
||||
import logging
|
||||
|
||||
from homeassistant.components.tesla import DOMAIN as TESLA_DOMAIN
|
||||
from homeassistant.helpers.event import track_utc_time_change
|
||||
from homeassistant.util import slugify
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEPENDENCIES = ['tesla']
|
||||
|
||||
|
||||
def setup_scanner(hass, config, see, discovery_info=None):
|
||||
"""Set up the Tesla tracker."""
|
||||
TeslaDeviceTracker(
|
||||
hass, config, see,
|
||||
hass.data[TESLA_DOMAIN]['devices']['devices_tracker'])
|
||||
return True
|
||||
|
||||
|
||||
class TeslaDeviceTracker(object):
|
||||
"""A class representing a Tesla device."""
|
||||
|
||||
def __init__(self, hass, config, see, tesla_devices):
|
||||
"""Initialize the Tesla device scanner."""
|
||||
self.hass = hass
|
||||
self.see = see
|
||||
self.devices = tesla_devices
|
||||
self._update_info()
|
||||
|
||||
track_utc_time_change(
|
||||
self.hass, self._update_info, second=range(0, 60, 30))
|
||||
|
||||
def _update_info(self, now=None):
|
||||
"""Update the device info."""
|
||||
for device in self.devices:
|
||||
device.update()
|
||||
name = device.name
|
||||
_LOGGER.debug("Updating device position: %s", name)
|
||||
dev_id = slugify(device.uniq_name)
|
||||
location = device.get_location()
|
||||
lat = location['latitude']
|
||||
lon = location['longitude']
|
||||
attrs = {
|
||||
'trackr_id': dev_id,
|
||||
'id': dev_id,
|
||||
'name': name
|
||||
}
|
||||
self.see(
|
||||
dev_id=dev_id, host_name=name,
|
||||
gps=(lat, lon), attributes=attrs
|
||||
)
|
||||
Reference in new issue
Block a user