Skip to content

Commit

Permalink
Add usage_quota option to config flow
Browse files Browse the repository at this point in the history
  • Loading branch information
ufozone committed Dec 18, 2023
1 parent fe734ba commit b9c9be4
Showing 1 changed file with 38 additions and 5 deletions.
43 changes: 38 additions & 5 deletions custom_components/unifi_voucher/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
CONF_VOUCHER_NUMBER,
CONF_VOUCHER_QUOTA,
CONF_VOUCHER_DURATION,
CONF_VOUCHER_USAGE_QUOTA,
)
from .api import (
UnifiVoucherApiClient,
Expand Down Expand Up @@ -267,6 +268,7 @@ async def async_step_options(
CONF_VOUCHER_NUMBER: _set_option(user_input, CONF_VOUCHER_NUMBER),
CONF_VOUCHER_QUOTA: _set_option(user_input, CONF_VOUCHER_QUOTA),
CONF_VOUCHER_DURATION: _set_option(user_input, CONF_VOUCHER_DURATION),
CONF_VOUCHER_USAGE_QUOTA: _set_option(user_input, CONF_VOUCHER_USAGE_QUOTA),
}
)
# User is done, create the config entry.
Expand Down Expand Up @@ -338,19 +340,34 @@ async def async_step_options(
),
vol.Optional(
CONF_VOUCHER_DURATION,
default=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("default", 0),
default=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("default", 24),
description={
"suggested_value": _get_option((user_input or {}), CONF_VOUCHER_DURATION),
},
): selector.NumberSelector(
selector.NumberSelectorConfig(
mode=selector.NumberSelectorMode.BOX,
min=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("min", 0),
max=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("max", 10000),
min=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("min", 1),
max=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("max", 1000000),
step=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("step", 1),
unit_of_measurement=UnitOfTime.HOURS,
)
),
vol.Optional(
CONF_VOUCHER_USAGE_QUOTA,
default=DEFAULT_VOUCHER[CONF_VOUCHER_USAGE_QUOTA].get("default", 0),
description={
"suggested_value": _get_option((user_input or {}), CONF_VOUCHER_USAGE_QUOTA),
},
): selector.NumberSelector(
selector.NumberSelectorConfig(
mode=selector.NumberSelectorMode.BOX,
min=DEFAULT_VOUCHER[CONF_VOUCHER_USAGE_QUOTA].get("min", 0),
max=DEFAULT_VOUCHER[CONF_VOUCHER_USAGE_QUOTA].get("max", 1048576),
step=DEFAULT_VOUCHER[CONF_VOUCHER_USAGE_QUOTA].get("step", 1),
unit_of_measurement=UnitOfTime.HOURS,
)
),
}
),
last_step=True,
Expand Down Expand Up @@ -439,6 +456,7 @@ async def async_step_init(
CONF_VOUCHER_NUMBER: _set_option(user_input, CONF_VOUCHER_NUMBER),
CONF_VOUCHER_QUOTA: _set_option(user_input, CONF_VOUCHER_QUOTA),
CONF_VOUCHER_DURATION: _set_option(user_input, CONF_VOUCHER_DURATION),
CONF_VOUCHER_USAGE_QUOTA: _set_option(user_input, CONF_VOUCHER_USAGE_QUOTA),
}
)
# User is done, update the config entry.
Expand Down Expand Up @@ -490,19 +508,34 @@ async def async_step_init(
),
vol.Optional(
CONF_VOUCHER_DURATION,
default=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("default", 0),
default=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("default", 24),
description={
"suggested_value": _get_option((user_input or self.options or {}), CONF_VOUCHER_DURATION),
},
): selector.NumberSelector(
selector.NumberSelectorConfig(
mode=selector.NumberSelectorMode.BOX,
min=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("min", 0),
min=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("min", 1),
max=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("max", 1000000),
step=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("step", 1),
unit_of_measurement=UnitOfTime.HOURS,
)
),
vol.Optional(
CONF_VOUCHER_USAGE_QUOTA,
default=DEFAULT_VOUCHER[CONF_VOUCHER_USAGE_QUOTA].get("default", 0),
description={
"suggested_value": _get_option((user_input or self.options or {}), CONF_VOUCHER_USAGE_QUOTA),
},
): selector.NumberSelector(
selector.NumberSelectorConfig(
mode=selector.NumberSelectorMode.BOX,
min=DEFAULT_VOUCHER[CONF_VOUCHER_USAGE_QUOTA].get("min", 0),
max=DEFAULT_VOUCHER[CONF_VOUCHER_USAGE_QUOTA].get("max", 1000000),
step=DEFAULT_VOUCHER[CONF_VOUCHER_USAGE_QUOTA].get("step", 1),
unit_of_measurement=UnitOfTime.HOURS,
)
),
}
),
last_step=True,
Expand Down

0 comments on commit b9c9be4

Please sign in to comment.