Code cleanup yale_smart_alarm (#65081)
This commit is contained in:
parent
d479949ca2
commit
9610fa5979
2 changed files with 13 additions and 15 deletions
|
@ -27,7 +27,6 @@ DATA_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(CONF_USERNAME): cv.string,
|
vol.Required(CONF_USERNAME): cv.string,
|
||||||
vol.Required(CONF_PASSWORD): cv.string,
|
vol.Required(CONF_PASSWORD): cv.string,
|
||||||
vol.Required(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
||||||
vol.Required(CONF_AREA_ID, default=DEFAULT_AREA_ID): cv.string,
|
vol.Required(CONF_AREA_ID, default=DEFAULT_AREA_ID): cv.string,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -45,7 +44,7 @@ class YaleConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
entry: ConfigEntry
|
entry: ConfigEntry | None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@callback
|
@callback
|
||||||
|
@ -53,20 +52,21 @@ class YaleConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
"""Get the options flow for this handler."""
|
"""Get the options flow for this handler."""
|
||||||
return YaleOptionsFlowHandler(config_entry)
|
return YaleOptionsFlowHandler(config_entry)
|
||||||
|
|
||||||
async def async_step_import(self, config: dict):
|
async def async_step_import(self, config: dict[str, Any]) -> FlowResult:
|
||||||
"""Import a configuration from config.yaml."""
|
"""Import a configuration from config.yaml."""
|
||||||
|
|
||||||
self.context.update(
|
|
||||||
{"title_placeholders": {CONF_NAME: f"YAML import {DOMAIN}"}}
|
|
||||||
)
|
|
||||||
return await self.async_step_user(user_input=config)
|
return await self.async_step_user(user_input=config)
|
||||||
|
|
||||||
async def async_step_reauth(self, user_input=None):
|
async def async_step_reauth(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
"""Handle initiation of re-authentication with Yale."""
|
"""Handle initiation of re-authentication with Yale."""
|
||||||
self.entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
|
self.entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
|
||||||
return await self.async_step_reauth_confirm()
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
async def async_step_reauth_confirm(self, user_input=None):
|
async def async_step_reauth_confirm(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
"""Dialog that informs the user that reauth is required."""
|
"""Dialog that informs the user that reauth is required."""
|
||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class YaleConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
|
|
||||||
if not errors:
|
if not errors:
|
||||||
existing_entry = await self.async_set_unique_id(username)
|
existing_entry = await self.async_set_unique_id(username)
|
||||||
if existing_entry:
|
if existing_entry and self.entry:
|
||||||
self.hass.config_entries.async_update_entry(
|
self.hass.config_entries.async_update_entry(
|
||||||
existing_entry,
|
existing_entry,
|
||||||
data={
|
data={
|
||||||
|
@ -105,14 +105,16 @@ class YaleConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||||
errors=errors,
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> FlowResult:
|
||||||
"""Handle the initial step."""
|
"""Handle the initial step."""
|
||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
username = user_input[CONF_USERNAME]
|
username = user_input[CONF_USERNAME]
|
||||||
password = user_input[CONF_PASSWORD]
|
password = user_input[CONF_PASSWORD]
|
||||||
name = user_input.get(CONF_NAME, DEFAULT_NAME)
|
name = DEFAULT_NAME
|
||||||
area = user_input.get(CONF_AREA_ID, DEFAULT_AREA_ID)
|
area = user_input.get(CONF_AREA_ID, DEFAULT_AREA_ID)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -38,7 +38,6 @@ async def test_form(hass: HomeAssistant) -> None:
|
||||||
{
|
{
|
||||||
"username": "test-username",
|
"username": "test-username",
|
||||||
"password": "test-password",
|
"password": "test-password",
|
||||||
"name": "Yale Smart Alarm",
|
|
||||||
"area_id": "1",
|
"area_id": "1",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -81,7 +80,6 @@ async def test_form_invalid_auth(
|
||||||
{
|
{
|
||||||
"username": "test-username",
|
"username": "test-username",
|
||||||
"password": "test-password",
|
"password": "test-password",
|
||||||
"name": "Yale Smart Alarm",
|
|
||||||
"area_id": "1",
|
"area_id": "1",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -101,7 +99,6 @@ async def test_form_invalid_auth(
|
||||||
{
|
{
|
||||||
"username": "test-username",
|
"username": "test-username",
|
||||||
"password": "test-password",
|
"password": "test-password",
|
||||||
"name": "Yale Smart Alarm",
|
|
||||||
"area_id": "1",
|
"area_id": "1",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -124,7 +121,6 @@ async def test_form_invalid_auth(
|
||||||
{
|
{
|
||||||
"username": "test-username",
|
"username": "test-username",
|
||||||
"password": "test-password",
|
"password": "test-password",
|
||||||
"name": "Yale Smart Alarm",
|
|
||||||
"area_id": "1",
|
"area_id": "1",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue