mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Add enable_wake_on_start option to Tesla (#33035)
This commit is contained in:
parent
d3f9408650
commit
087b672449
@ -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"
|
||||
}
|
||||
},
|
||||
"title": "Tesla"
|
||||
"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"
|
||||
},
|
||||
"options": {
|
||||
"step": {
|
||||
"init": {
|
||||
"data": {
|
||||
"scan_interval": "Seconds between scans"
|
||||
}
|
||||
}
|
||||
"step": {
|
||||
"user": {
|
||||
"data": {
|
||||
"username": "Email Address",
|
||||
"password": "Password"
|
||||
},
|
||||
"description": "Please enter your information.",
|
||||
"title": "Tesla - Configuration"
|
||||
}
|
||||
},
|
||||
"title": "Tesla"
|
||||
},
|
||||
"options": {
|
||||
"step": {
|
||||
"init": {
|
||||
"data": {
|
||||
"scan_interval": "Seconds between scans",
|
||||
"enable_wake_on_start": "Force cars awake on startup"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -28,8 +28,10 @@ from .config_flow import (
|
||||
validate_input,
|
||||
)
|
||||
from .const import (
|
||||
CONF_WAKE_ON_START,
|
||||
DATA_LISTENER,
|
||||
DEFAULT_SCAN_INTERVAL,
|
||||
DEFAULT_WAKE_ON_START,
|
||||
DOMAIN,
|
||||
ICONS,
|
||||
MIN_SCAN_INTERVAL,
|
||||
@ -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
|
||||
@ -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
|
||||
|
@ -15,7 +15,13 @@ from homeassistant.const import (
|
||||
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__)
|
||||
|
||||
@ -103,7 +109,13 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
|
||||
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)
|
||||
|
@ -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",
|
||||
|
@ -22,7 +22,8 @@
|
||||
"step": {
|
||||
"init": {
|
||||
"data": {
|
||||
"scan_interval": "Seconds between scans"
|
||||
"scan_interval": "Seconds between scans",
|
||||
"enable_wake_on_start": "Force cars awake on startup"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,13 @@ from unittest.mock import patch
|
||||
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,
|
||||
@ -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}
|
||||
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: DEFAULT_SCAN_INTERVAL,
|
||||
CONF_WAKE_ON_START: DEFAULT_WAKE_ON_START,
|
||||
}
|
||||
|
||||
|
||||
async def test_option_flow_input_floor(hass):
|
||||
@ -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,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user