Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions homeassistant/components/tesla/.translations/en.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
{
"config": {
"error": {
"connection_error": "Error connecting; check network and retry",
"identifier_exists": "Email already registered",
"invalid_credentials": "Invalid credentials",
"unknown_error": "Unknown error, please report log info"
},
"step": {
"user": {
"data": {
"password": "Password",
"username": "Email Address"
},
"description": "Please enter your information.",
"title": "Tesla - Configuration"
}
"config": {
"error": {
"connection_error": "Error connecting; check network and retry",
"identifier_exists": "Email already registered",
"invalid_credentials": "Invalid credentials",
"unknown_error": "Unknown error, please report log info"
},
"step": {
"user": {
"data": {
"username": "Email Address",
"password": "Password"
},
"title": "Tesla"
"description": "Please enter your information.",
"title": "Tesla - Configuration"
}
},
"options": {
"step": {
"init": {
"data": {
"scan_interval": "Seconds between scans"
}
}
"title": "Tesla"
},
"options": {
"step": {
"init": {
"data": {
"scan_interval": "Seconds between scans",
"enable_wake_on_start": "Force cars awake on startup"
}
}
}
}
}
13 changes: 11 additions & 2 deletions homeassistant/components/tesla/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
validate_input,
)
from .const import (
CONF_WAKE_ON_START,
DATA_LISTENER,
DEFAULT_SCAN_INTERVAL,
DEFAULT_WAKE_ON_START,
DOMAIN,
ICONS,
MIN_SCAN_INTERVAL,
Expand Down Expand Up @@ -71,7 +73,10 @@ async def async_setup(hass, base_config):

def _update_entry(email, data=None, options=None):
data = data or {}
options = options or {CONF_SCAN_INTERVAL: DEFAULT_SCAN_INTERVAL}
options = options or {
CONF_SCAN_INTERVAL: DEFAULT_SCAN_INTERVAL,
CONF_WAKE_ON_START: DEFAULT_WAKE_ON_START,
}
for entry in hass.config_entries.async_entries(DOMAIN):
if email != entry.title:
continue
Expand Down Expand Up @@ -131,7 +136,11 @@ async def async_setup_entry(hass, config_entry):
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
),
)
(refresh_token, access_token) = await controller.connect()
(refresh_token, access_token) = await controller.connect(
wake_if_asleep=config_entry.options.get(
CONF_WAKE_ON_START, DEFAULT_WAKE_ON_START
)
)
except TeslaException as ex:
_LOGGER.error("Unable to communicate with Tesla API: %s", ex.message)
return False
Expand Down
16 changes: 14 additions & 2 deletions homeassistant/components/tesla/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
from homeassistant.core import callback
from homeassistant.helpers import aiohttp_client, config_validation as cv

from .const import DEFAULT_SCAN_INTERVAL, DOMAIN, MIN_SCAN_INTERVAL
from .const import (
CONF_WAKE_ON_START,
DEFAULT_SCAN_INTERVAL,
DEFAULT_WAKE_ON_START,
DOMAIN,
MIN_SCAN_INTERVAL,
)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -103,7 +109,13 @@ async def async_step_init(self, user_input=None):
default=self.config_entry.options.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
),
): vol.All(cv.positive_int, vol.Clamp(min=MIN_SCAN_INTERVAL))
): vol.All(cv.positive_int, vol.Clamp(min=MIN_SCAN_INTERVAL)),
vol.Optional(
CONF_WAKE_ON_START,
default=self.config_entry.options.get(
CONF_WAKE_ON_START, DEFAULT_WAKE_ON_START
),
): bool,
}
)
return self.async_show_form(step_id="init", data_schema=data_schema)
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/tesla/const.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Const file for Tesla cars."""
CONF_WAKE_ON_START = "enable_wake_on_start"
DOMAIN = "tesla"
DATA_LISTENER = "listener"
DEFAULT_SCAN_INTERVAL = 660
DEFAULT_WAKE_ON_START = False
MIN_SCAN_INTERVAL = 60
TESLA_COMPONENTS = [
"sensor",
Expand Down
5 changes: 3 additions & 2 deletions homeassistant/components/tesla/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
"step": {
"init": {
"data": {
"scan_interval": "Seconds between scans"
"scan_interval": "Seconds between scans",
"enable_wake_on_start": "Force cars awake on startup"
}
}
}
}
}
}
41 changes: 37 additions & 4 deletions tests/components/tesla/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
from teslajsonpy import TeslaException

from homeassistant import config_entries, data_entry_flow, setup
from homeassistant.components.tesla.const import DOMAIN, MIN_SCAN_INTERVAL
from homeassistant.components.tesla.const import (
CONF_WAKE_ON_START,
DEFAULT_SCAN_INTERVAL,
DEFAULT_WAKE_ON_START,
DOMAIN,
MIN_SCAN_INTERVAL,
)
from homeassistant.const import (
CONF_ACCESS_TOKEN,
CONF_PASSWORD,
Expand Down Expand Up @@ -137,10 +143,34 @@ async def test_option_flow(hass):
assert result["step_id"] == "init"

result = await hass.config_entries.options.async_configure(
result["flow_id"], user_input={CONF_SCAN_INTERVAL: 350}
result["flow_id"],
user_input={CONF_SCAN_INTERVAL: 350, CONF_WAKE_ON_START: True},
)
assert result["type"] == "create_entry"
assert result["data"] == {
CONF_SCAN_INTERVAL: 350,
CONF_WAKE_ON_START: True,
}


async def test_option_flow_defaults(hass):
"""Test config flow options."""
entry = MockConfigEntry(domain=DOMAIN, data={}, options=None)
entry.add_to_hass(hass)

result = await hass.config_entries.options.async_init(entry.entry_id)

assert result["type"] == "form"
assert result["step_id"] == "init"

result = await hass.config_entries.options.async_configure(
result["flow_id"], user_input={}
)
assert result["type"] == "create_entry"
assert result["data"] == {CONF_SCAN_INTERVAL: 350}
assert result["data"] == {
CONF_SCAN_INTERVAL: DEFAULT_SCAN_INTERVAL,
CONF_WAKE_ON_START: DEFAULT_WAKE_ON_START,
}


async def test_option_flow_input_floor(hass):
Expand All @@ -157,4 +187,7 @@ async def test_option_flow_input_floor(hass):
result["flow_id"], user_input={CONF_SCAN_INTERVAL: 1}
)
assert result["type"] == "create_entry"
assert result["data"] == {CONF_SCAN_INTERVAL: MIN_SCAN_INTERVAL}
assert result["data"] == {
CONF_SCAN_INTERVAL: MIN_SCAN_INTERVAL,
CONF_WAKE_ON_START: DEFAULT_WAKE_ON_START,
}