Store smappee flow data in flow handler attributes (#127178)

pull/126761/head^2
Erik Montnemery 2024-10-01 11:17:20 +02:00 committed by GitHub
parent f71baf3c73
commit f0b57e2873
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 17 deletions

View File

@ -28,6 +28,9 @@ class SmappeeFlowHandler(
DOMAIN = DOMAIN
ip_address: str # Set by zeroconf step, used by zeroconf_confirm step
serial_number: str # Set by zeroconf step, used by zeroconf_confirm step
async def async_oauth_create_entry(self, data):
"""Create an entry for the flow."""
@ -59,13 +62,9 @@ class SmappeeFlowHandler(
if self.is_cloud_device_already_added():
return self.async_abort(reason="already_configured_device")
self.context.update(
{
CONF_IP_ADDRESS: discovery_info.host,
CONF_SERIALNUMBER: serial_number,
"title_placeholders": {"name": serial_number},
}
)
self.context["title_placeholders"] = {"name": serial_number}
self.ip_address = discovery_info.host
self.serial_number = serial_number
return await self.async_step_zeroconf_confirm()
@ -80,33 +79,32 @@ class SmappeeFlowHandler(
return self.async_abort(reason="already_configured_device")
if user_input is None:
serialnumber = self.context.get(CONF_SERIALNUMBER)
return self.async_show_form(
step_id="zeroconf_confirm",
description_placeholders={"serialnumber": serialnumber},
description_placeholders={"serialnumber": self.serial_number},
errors=errors,
)
ip_address = self.context.get(CONF_IP_ADDRESS)
serial_number = self.context.get(CONF_SERIALNUMBER)
# Attempt to make a connection to the local device
if helper.is_smappee_genius(serial_number):
if helper.is_smappee_genius(self.serial_number):
# next generation device, attempt connect to the local mqtt broker
smappee_mqtt = mqtt.SmappeeLocalMqtt(serial_number=serial_number)
smappee_mqtt = mqtt.SmappeeLocalMqtt(serial_number=self.serial_number)
connect = await self.hass.async_add_executor_job(smappee_mqtt.start_attempt)
if not connect:
return self.async_abort(reason="cannot_connect")
else:
# legacy devices, without local mqtt broker, try api access
smappee_api = api.api.SmappeeLocalApi(ip=ip_address)
smappee_api = api.api.SmappeeLocalApi(ip=self.ip_address)
logon = await self.hass.async_add_executor_job(smappee_api.logon)
if logon is None:
return self.async_abort(reason="cannot_connect")
return self.async_create_entry(
title=f"{DOMAIN}{serial_number}",
data={CONF_IP_ADDRESS: ip_address, CONF_SERIALNUMBER: serial_number},
title=f"{DOMAIN}{self.serial_number}",
data={
CONF_IP_ADDRESS: self.ip_address,
CONF_SERIALNUMBER: self.serial_number,
},
)
async def async_step_user(