Skip to content

Commit

Permalink
Merge pull request #86 from dougiteixeira/cleanup-config-flow
Browse files Browse the repository at this point in the history
Cleanup do config flow
  • Loading branch information
dougiteixeira authored May 10, 2023
2 parents 0b0e939 + 63e5a10 commit cefd4be
Showing 1 changed file with 0 additions and 99 deletions.
99 changes: 0 additions & 99 deletions custom_components/proxmoxve/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,105 +149,6 @@ async def async_step_host_auth(self, user_input: dict[str, Any]) -> FlowResult:
errors=errors,
)

async def async_step_add_node(
self,
user_input: dict[str, Any] | None = None,
) -> FlowResult:
"""Handle the node selection step."""

errors: dict[str, str] = {}

current_nodes = []
for node in self.config_entry.data[CONF_NODES]:
current_nodes.append(node)

if user_input:
node = user_input.get(CONF_NODE)
if node in current_nodes:
return self.async_abort(reason="node_already_exists")

config_data: dict[str, Any] = (
self.config_entry.data.copy()
if self.config_entry.data is not None
else {}
)

current_nodes.append(node)
config_data.update(
{
CONF_NODES: current_nodes,
}
)

self.hass.config_entries.async_update_entry(
self.config_entry, data=config_data
)

await self.hass.config_entries.async_reload(self.config_entry.entry_id)

return self.async_abort(reason="changes_successful")

# return await self.async_step_selection_qemu_lxc(node=node)

host = self.config_entry.data[CONF_HOST]
port = self.config_entry.data[CONF_PORT]
user = self.config_entry.data[CONF_USERNAME]
realm = self.config_entry.data[CONF_REALM]
password = self.config_entry.data[CONF_PASSWORD]
verify_ssl = self.config_entry.data[CONF_VERIFY_SSL]

try:
self._proxmox_client = ProxmoxClient(
host=host,
port=port,
user=user,
realm=realm,
password=password,
verify_ssl=verify_ssl,
)

await self.hass.async_add_executor_job(self._proxmox_client.build_client)

except (
proxmoxer.AuthenticationError,
SSLError,
ConnectTimeout,
Exception,
) as err:
raise (err)

proxmox = self._proxmox_client.get_api_client()

nodes = []

if (proxmox_cliente := self._proxmox_client) is not None:
if proxmox := (proxmox_cliente.get_api_client()):
proxmox_nodes = await self.hass.async_add_executor_job(
proxmox.nodes.get
)

for node in proxmox_nodes:
nodes.append(node[CONF_NODE])

for current_node in current_nodes:
if current_node in nodes:
nodes.remove(current_node)

if len(nodes) == 0:
return self.async_abort(reason="no_nodes_to_add")

return self.async_show_form(
step_id="add_node",
data_schema=vol.Schema(
{
vol.Required(CONF_NODE): vol.In(nodes),
}
),
errors=errors,
)

return self.async_abort(reason="no_nodes")

async def async_step_change_expose(
self,
user_input: dict[str, Any] | None = None,
Expand Down

0 comments on commit cefd4be

Please sign in to comment.