How to use the teslajsonpy.Controller function in teslajsonpy

To help you get started, we’ve selected a few teslajsonpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github home-assistant / home-assistant / homeassistant / components / tesla / __init__.py View on Github external
async def async_setup_entry(hass, config_entry):
    """Set up Tesla as config entry."""

    hass.data.setdefault(DOMAIN, {})
    config = config_entry.data
    websession = aiohttp_client.async_get_clientsession(hass)
    email = config_entry.title
    if email in hass.data[DOMAIN] and CONF_SCAN_INTERVAL in hass.data[DOMAIN][email]:
        scan_interval = hass.data[DOMAIN][email][CONF_SCAN_INTERVAL]
        hass.config_entries.async_update_entry(
            config_entry, options={CONF_SCAN_INTERVAL: scan_interval}
        )
        hass.data[DOMAIN].pop(email)
    try:
        controller = TeslaAPI(
            websession,
            refresh_token=config[CONF_TOKEN],
            update_interval=config_entry.options.get(CONF_SCAN_INTERVAL, 300),
        )
        (refresh_token, access_token) = await controller.connect()
    except TeslaException as ex:
        _LOGGER.error("Unable to communicate with Tesla API: %s", ex.message)
        return False
    _async_save_tokens(hass, config_entry, access_token, refresh_token)
    entry_data = hass.data[DOMAIN][config_entry.entry_id] = {
        "controller": controller,
        "devices": defaultdict(list),
        DATA_LISTENER: [config_entry.add_update_listener(update_listener)],
    }
    _LOGGER.debug("Connected to the Tesla API.")
    all_devices = entry_data["controller"].get_homeassistant_components()
github home-assistant / home-assistant / homeassistant / components / tesla.py View on Github external
def setup(hass, base_config):
    """Set up of Tesla component."""
    from teslajsonpy import Controller as teslaAPI, TeslaException

    config = base_config.get(DOMAIN)

    email = config.get(CONF_USERNAME)
    password = config.get(CONF_PASSWORD)
    update_interval = config.get(CONF_SCAN_INTERVAL)
    if hass.data.get(DOMAIN) is None:
        try:
            hass.data[DOMAIN] = {
                'controller': teslaAPI(email, password, update_interval),
                'devices': defaultdict(list)
            }
            _LOGGER.debug("Connected to the Tesla API.")
        except TeslaException as ex:
            if ex.code == 401:
                hass.components.persistent_notification.create(
                    "Error:<br>Please check username and password."
                    "You will need to restart Home Assistant after fixing.",
                    title=NOTIFICATION_TITLE,
                    notification_id=NOTIFICATION_ID)
            else:
                hass.components.persistent_notification.create(
                    "Error:<br>Can't communicate with Tesla API.<br>"
                    "Error code: {} Reason: {}"
                    "You will need to restart Home Assistant after fixing."
                    "".format(ex.code, ex.message),

teslajsonpy

A library to work with Tesla API.

Apache-2.0
Latest version published 11 days ago

Package Health Score

75 / 100
Full package analysis

Similar packages