Skip to content

Commit

Permalink
bump pyfuelprices
Browse files Browse the repository at this point in the history
complete optionsflow
  • Loading branch information
pantherale0 committed Feb 9, 2024
1 parent 41dcfe2 commit 0aead64
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
1 change: 1 addition & 0 deletions custom_components/fuel_prices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

async def update_listener(hass: HomeAssistant, entry: ConfigEntry):
"""Update listener."""
await hass.data[DOMAIN][entry.entry_id].api.client_session.close()
await hass.config_entries.async_reload(entry.entry_id)

entry.async_on_unload(entry.add_update_listener(update_listener))
Expand Down
50 changes: 46 additions & 4 deletions custom_components/fuel_prices/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ async def async_step_sources(self, user_input: dict[str, Any] | None = None):
"""Set data source config."""
if user_input is not None:
self.configured_sources = user_input[CONF_SOURCES]
self.timeout = user_input[CONF_TIMEOUT]
self.interval = user_input[CONF_SCAN_INTERVAL]
return await self.async_step_main_menu(None)
return self.async_show_form(
step_id="sources",
Expand Down Expand Up @@ -138,7 +140,7 @@ async def async_step_sources(self, user_input: dict[str, Any] | None = None):
): selector.NumberSelector(
selector.NumberSelectorConfig(
mode=selector.NumberSelectorMode.BOX,
min=120,
min=1,
max=1440,
unit_of_measurement="m",
)
Expand Down Expand Up @@ -287,6 +289,8 @@ async def async_step_finished(self, user_input: dict[str, Any] | None = None):
else:
user_input[CONF_SOURCES] = list(SOURCE_MAP)
user_input[CONF_AREAS] = self.configured_areas
user_input[CONF_SCAN_INTERVAL] = self.interval
user_input[CONF_TIMEOUT] = self.timeout
return self.async_create_entry(title=NAME, data=user_input)
return self.async_show_form(step_id="finished", errors=errors, last_step=True)

Expand All @@ -304,12 +308,24 @@ class FuelPricesOptionsFlow(config_entries.OptionsFlow):
configured_sources = []
configuring_area = {}
configuring_index = -1
timeout = 10
interval = 1440

def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
"""Initialize options flow."""
self.config_entry = config_entry
self.configured_areas = self.config_entry.data.get(CONF_AREAS, [])
self.configured_sources = self.config_entry.data.get(CONF_SOURCES, [])
self.configured_areas = config_entry.options.get(
CONF_AREAS, config_entry.data.get(CONF_AREAS, [])
)
self.configured_sources = config_entry.options.get(
CONF_SOURCES, config_entry.data.get(CONF_SOURCES, [])
)
self.timeout = config_entry.options.get(
CONF_TIMEOUT, config_entry.data.get(CONF_TIMEOUT, 10)
)
self.interval = config_entry.options.get(
CONF_SCAN_INTERVAL, config_entry.data.get(CONF_SCAN_INTERVAL, 1440)
)

@property
def configured_area_names(self) -> list[str]:
Expand Down Expand Up @@ -338,6 +354,8 @@ async def async_step_sources(self, user_input: dict[str, Any] | None = None):
"""Set data source config."""
if user_input is not None:
self.configured_sources = user_input[CONF_SOURCES]
self.timeout = user_input[CONF_TIMEOUT]
self.interval = user_input[CONF_SCAN_INTERVAL]
return await self.async_step_main_menu(None)
return self.async_show_form(
step_id="sources",
Expand All @@ -351,7 +369,29 @@ async def async_step_sources(self, user_input: dict[str, Any] | None = None):
options=list(SOURCE_MAP),
multiple=True,
)
)
),
vol.Optional(
CONF_TIMEOUT,
default=self.timeout,
): selector.NumberSelector(
selector.NumberSelectorConfig(
mode=selector.NumberSelectorMode.BOX,
min=5,
max=60,
unit_of_measurement="s",
)
),
vol.Optional(
CONF_SCAN_INTERVAL,
default=self.interval,
): selector.NumberSelector(
selector.NumberSelectorConfig(
mode=selector.NumberSelectorMode.BOX,
min=1,
max=1440,
unit_of_measurement="m",
)
),
}
),
)
Expand Down Expand Up @@ -495,6 +535,8 @@ async def async_step_finished(self, user_input: dict[str, Any] | None = None):
else list(SOURCE_MAP)
)
user_input[CONF_AREAS] = self.configured_areas
user_input[CONF_SCAN_INTERVAL] = self.interval
user_input[CONF_TIMEOUT] = self.timeout
return self.async_create_entry(title=NAME, data=user_input)
return self.async_show_form(step_id="finished", errors=errors, last_step=True)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/fuel_prices/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"requirements": [
"reverse-geocode==1.4.1",
"these-united-states==1.1.0.21",
"pyfuelprices==2.2.2"
"pyfuelprices==2.2.3"
],
"ssdp": [],
"version": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ colorlog==6.7.0
homeassistant==2023.8.0
pip>=21.0,<23.2
ruff==0.0.292
pyfuelprices==2.2.2
pyfuelprices==2.2.3

0 comments on commit 0aead64

Please sign in to comment.