Skip to content

Commit

Permalink
Merge pull request #10 from jaroschek/feature/config-flow-revert
Browse files Browse the repository at this point in the history
Revert config flow to manual name input to avoid SNMP calls during setup
  • Loading branch information
jaroschek committed Feb 8, 2024
2 parents 4349d40 + 540e52c commit fcb82c5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 43 deletions.
47 changes: 6 additions & 41 deletions custom_components/eaton_ups/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,18 @@
)
from homeassistant.helpers.typing import ConfigType

from .api import SnmpApi
from .const import (
ATTR_AUTH_KEY,
ATTR_AUTH_PROTOCOL,
ATTR_COMMUNITY,
ATTR_HOST,
ATTR_NAME,
ATTR_PORT,
ATTR_PRIV_KEY,
ATTR_PRIV_PROTOCOL,
ATTR_USERNAME,
ATTR_VERSION,
DOMAIN,
SNMP_OID_IDENT_PRODUCT_NAME,
SNMP_OID_IDENT_SERIAL_NUMBER,
SNMP_PORT_DEFAULT,
AuthProtocol,
PrivProtocol,
Expand All @@ -42,6 +40,7 @@ def get_host_schema_config(data: ConfigType) -> Schema:
"""Return the host schema for config flow."""
return vol.Schema(
{
vol.Required(ATTR_NAME, default=data.get(ATTR_NAME)): cv.string,
vol.Required(ATTR_HOST, default=data.get(ATTR_HOST)): cv.string,
vol.Required(
ATTR_PORT, default=data.get(ATTR_PORT, SNMP_PORT_DEFAULT)
Expand Down Expand Up @@ -153,17 +152,7 @@ async def async_step_v1(self, v1_input: ConfigType | None = None) -> FlowResult:

self.data.update(v1_input)

api = SnmpApi(self.data)
result = api.get([SNMP_OID_IDENT_PRODUCT_NAME, SNMP_OID_IDENT_SERIAL_NUMBER])

await self.async_set_unique_id(
result.get(SNMP_OID_IDENT_SERIAL_NUMBER), raise_on_progress=False
)
self._abort_if_unique_id_configured()

return self.async_create_entry(
title=result.get(SNMP_OID_IDENT_PRODUCT_NAME), data=self.data
)
return self.async_create_entry(title=self.data[ATTR_NAME], data=self.data)

async def async_step_v3(self, v3_input: ConfigType | None = None) -> FlowResult:
"""Handle the v3 step."""
Expand All @@ -174,17 +163,7 @@ async def async_step_v3(self, v3_input: ConfigType | None = None) -> FlowResult:

self.data.update(v3_input)

api = SnmpApi(self.data)
result = api.get([SNMP_OID_IDENT_PRODUCT_NAME, SNMP_OID_IDENT_SERIAL_NUMBER])

await self.async_set_unique_id(
result.get(SNMP_OID_IDENT_SERIAL_NUMBER), raise_on_progress=False
)
self._abort_if_unique_id_configured()

return self.async_create_entry(
title=result.get(SNMP_OID_IDENT_PRODUCT_NAME), data=self.data
)
return self.async_create_entry(title=self.data[ATTR_NAME], data=self.data)

@staticmethod
@callback
Expand Down Expand Up @@ -231,14 +210,7 @@ async def async_step_v1(self, v1_input: ConfigType | None = None) -> FlowResult:

self.data.update(v1_input)

api = SnmpApi(self.config_entry.data)
result = api.get([SNMP_OID_IDENT_PRODUCT_NAME, SNMP_OID_IDENT_SERIAL_NUMBER])

self.hass.config_entries.async_update_entry(
self.config_entry,
title=result.get(SNMP_OID_IDENT_PRODUCT_NAME),
data=self.data,
)
self.hass.config_entries.async_update_entry(self.config_entry, data=self.data)

return self.async_create_entry(title="", data={})

Expand All @@ -251,14 +223,7 @@ async def async_step_v3(self, v3_input: ConfigType | None = None) -> FlowResult:

self.data.update(v3_input)

api = SnmpApi(self.config_entry.data)
result = api.get([SNMP_OID_IDENT_PRODUCT_NAME, SNMP_OID_IDENT_SERIAL_NUMBER])

self.hass.config_entries.async_update_entry(
self.config_entry,
title=result.get(SNMP_OID_IDENT_PRODUCT_NAME),
data=self.data,
)
self.hass.config_entries.async_update_entry(self.config_entry, data=self.data)

return self.async_create_entry(title="", data={})

Expand Down
1 change: 1 addition & 0 deletions custom_components/eaton_ups/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Platform.SENSOR,
]

ATTR_NAME = "name"
ATTR_HOST = "host"
ATTR_PORT = "port"
ATTR_VERSION = "version"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/eaton_ups/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"issue_tracker": "https://github.com/jaroschek/home-assistant-eaton-ups/issues",
"requirements": ["pysnmplib==5.0.21"],
"ssdp": [],
"version": "1.1.0",
"version": "1.1.1",
"zeroconf": []
}
3 changes: 2 additions & 1 deletion custom_components/eaton_ups/strings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"config": {
"step": {
"user": {
"host": {
"data": {
"name": "[%key:common::config_flow::data::name%]",
"host": "[%key:common::config_flow::data::host%]",
"username": "[%key:common::config_flow::data::username%]",
"password": "[%key:common::config_flow::data::password%]"
Expand Down
1 change: 1 addition & 0 deletions custom_components/eaton_ups/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"step": {
"host": {
"data": {
"name": "Name",
"host": "Host",
"port": "Port",
"version": "SNMP Version"
Expand Down

0 comments on commit fcb82c5

Please sign in to comment.