Skip to content

Commit

Permalink
Fix consistent attribute name duration in number entity and create se…
Browse files Browse the repository at this point in the history
…rvice
  • Loading branch information
ufozone committed Dec 17, 2023
1 parent 1087d85 commit e0b30c0
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 46 deletions.
30 changes: 15 additions & 15 deletions custom_components/unifi_voucher/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
CONF_WLAN_NAME,
CONF_VOUCHER_NUMBER,
CONF_VOUCHER_QUOTA,
CONF_VOUCHER_EXPIRE,
CONF_VOUCHER_DURATION,
)
from .api import (
UnifiVoucherApiClient,
Expand Down Expand Up @@ -266,7 +266,7 @@ async def async_step_options(
CONF_WLAN_NAME: user_input.get(CONF_WLAN_NAME, "").strip(),
CONF_VOUCHER_NUMBER: _set_option(user_input, CONF_VOUCHER_NUMBER),
CONF_VOUCHER_QUOTA: _set_option(user_input, CONF_VOUCHER_QUOTA),
CONF_VOUCHER_EXPIRE: _set_option(user_input, CONF_VOUCHER_EXPIRE),
CONF_VOUCHER_DURATION: _set_option(user_input, CONF_VOUCHER_DURATION),
}
)
# User is done, create the config entry.
Expand Down Expand Up @@ -337,17 +337,17 @@ async def async_step_options(
)
),
vol.Optional(
CONF_VOUCHER_EXPIRE,
default=DEFAULT_VOUCHER[CONF_VOUCHER_EXPIRE].get("default", 0),
CONF_VOUCHER_DURATION,
default=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("default", 0),
description={
"suggested_value": _get_option((user_input or {}), CONF_VOUCHER_EXPIRE),
"suggested_value": _get_option((user_input or {}), CONF_VOUCHER_DURATION),
},
): selector.NumberSelector(
selector.NumberSelectorConfig(
mode=selector.NumberSelectorMode.BOX,
min=DEFAULT_VOUCHER[CONF_VOUCHER_EXPIRE].get("min", 0),
max=DEFAULT_VOUCHER[CONF_VOUCHER_EXPIRE].get("max", 10000),
step=DEFAULT_VOUCHER[CONF_VOUCHER_EXPIRE].get("step", 1),
min=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("min", 0),
max=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("max", 10000),
step=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("step", 1),
unit_of_measurement=UnitOfTime.HOURS,
)
),
Expand Down Expand Up @@ -438,7 +438,7 @@ async def async_step_init(
CONF_WLAN_NAME: user_input.get(CONF_WLAN_NAME, "").strip(),
CONF_VOUCHER_NUMBER: _set_option(user_input, CONF_VOUCHER_NUMBER),
CONF_VOUCHER_QUOTA: _set_option(user_input, CONF_VOUCHER_QUOTA),
CONF_VOUCHER_EXPIRE: _set_option(user_input, CONF_VOUCHER_EXPIRE),
CONF_VOUCHER_DURATION: _set_option(user_input, CONF_VOUCHER_DURATION),
}
)
# User is done, update the config entry.
Expand Down Expand Up @@ -489,17 +489,17 @@ async def async_step_init(
)
),
vol.Optional(
CONF_VOUCHER_EXPIRE,
default=DEFAULT_VOUCHER[CONF_VOUCHER_EXPIRE].get("default", 0),
CONF_VOUCHER_DURATION,
default=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("default", 0),
description={
"suggested_value": _get_option((user_input or self.options or {}), CONF_VOUCHER_EXPIRE),
"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_EXPIRE].get("min", 0),
max=DEFAULT_VOUCHER[CONF_VOUCHER_EXPIRE].get("max", 1000000),
step=DEFAULT_VOUCHER[CONF_VOUCHER_EXPIRE].get("step", 1),
min=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("min", 0),
max=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("max", 1000000),
step=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("step", 1),
unit_of_measurement=UnitOfTime.HOURS,
)
),
Expand Down
4 changes: 2 additions & 2 deletions custom_components/unifi_voucher/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
CONF_WLAN_NAME = "wlan_name"
CONF_VOUCHER_NUMBER = "voucher_number"
CONF_VOUCHER_QUOTA = "voucher_quota"
CONF_VOUCHER_EXPIRE = "voucher_expire"
CONF_VOUCHER_DURATION = "voucher_duration"
CONF_VOUCHER_USAGE_QUOTA = "voucher_usage_quota"
CONF_VOUCHER_RATE_MAX_UP = "voucher_rate_max_up"
CONF_VOUCHER_RATE_MAX_DOWN = "voucher_rate_max_down"
Expand Down Expand Up @@ -51,7 +51,7 @@
"min": 0,
"max": 10000,
},
CONF_VOUCHER_EXPIRE: {
CONF_VOUCHER_DURATION: {
"default": 24,
"min": 1,
"max": 1000000,
Expand Down
10 changes: 5 additions & 5 deletions custom_components/unifi_voucher/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
CONF_WLAN_NAME,
CONF_VOUCHER_NUMBER,
CONF_VOUCHER_QUOTA,
CONF_VOUCHER_EXPIRE,
CONF_VOUCHER_DURATION,
DEFAULT_VOUCHER,
)
from .api import (
Expand Down Expand Up @@ -230,7 +230,7 @@ async def async_create_voucher(
self,
number: int | None = None,
quota: int | None = None,
expire: int | None = None,
duration: int | None = None,
usage_quota: int | None = None,
rate_max_up: int | None = None,
rate_max_down: int | None = None,
Expand All @@ -243,14 +243,14 @@ async def async_create_voucher(
if quota is None:
quota = int(self.get_entry_option(CONF_VOUCHER_QUOTA))

if expire is None:
expire = int(self.get_entry_option(CONF_VOUCHER_EXPIRE))
if duration is None:
duration = int(self.get_entry_option(CONF_VOUCHER_DURATION))

await self.client.controller.request(
UnifiVoucherCreateRequest.create(
number=number,
quota=quota,
expire_number=expire,
expire_number=duration,
expire_unit=60,
usage_quota=usage_quota,
rate_max_up=rate_max_up,
Expand Down
6 changes: 3 additions & 3 deletions custom_components/unifi_voucher/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .const import (
DOMAIN,
CONF_VOUCHER_QUOTA,
CONF_VOUCHER_EXPIRE,
CONF_VOUCHER_DURATION,
DEFAULT_VOUCHER,
)
from .coordinator import UnifiVoucherCoordinator
Expand All @@ -36,10 +36,10 @@ async def async_setup_entry(
translation_key=CONF_VOUCHER_QUOTA,
),
NumberEntityDescription(
key=CONF_VOUCHER_EXPIRE,
key=CONF_VOUCHER_DURATION,
icon="mdi:clock-outline",
native_unit_of_measurement=UnitOfTime.HOURS,
translation_key=CONF_VOUCHER_EXPIRE,
translation_key=CONF_VOUCHER_DURATION,
),
]

Expand Down
12 changes: 6 additions & 6 deletions custom_components/unifi_voucher/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
DOMAIN,
CONF_VOUCHER_NUMBER,
CONF_VOUCHER_QUOTA,
CONF_VOUCHER_EXPIRE,
CONF_VOUCHER_DURATION,
CONF_VOUCHER_USAGE_QUOTA,
CONF_VOUCHER_RATE_MAX_UP,
CONF_VOUCHER_RATE_MAX_DOWN,
Expand Down Expand Up @@ -85,7 +85,7 @@ async def async_create(service_call: ServiceCall) -> None:
await coordinator.async_create_voucher(
number=service_call.data.get("number"),
quota=service_call.data.get("quota"),
expire=service_call.data.get("expire"),
duration=service_call.data.get("duration"),
usage_quota=service_call.data.get("usage_quota"),
rate_max_up=service_call.data.get("rate_max_up"),
rate_max_down=service_call.data.get("rate_max_down"),
Expand Down Expand Up @@ -137,13 +137,13 @@ async def async_update(service_call: ServiceCall) -> None:
)
),
vol.Optional(
"expire",
default=coordinator.get_entry_option(CONF_VOUCHER_EXPIRE)
"duration",
default=coordinator.get_entry_option(CONF_VOUCHER_DURATION)
): vol.All(
vol.Coerce(int),
vol.Range(
min=DEFAULT_VOUCHER[CONF_VOUCHER_EXPIRE].get("min", 1),
max=DEFAULT_VOUCHER[CONF_VOUCHER_EXPIRE].get("max", 1000000),
min=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("min", 1),
max=DEFAULT_VOUCHER[CONF_VOUCHER_DURATION].get("max", 1000000),
)
),
vol.Optional(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/unifi_voucher/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ create:
max: 10000
step: 1
mode: slider
expire:
duration:
required: false
example: 24
default: 24
Expand Down
10 changes: 5 additions & 5 deletions custom_components/unifi_voucher/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"wlan_name": "What is the name of your guest WLAN?",
"voucher_number": "How many new vouchers should be created at the same time?",
"voucher_quota": "How much data traffic should be available per voucher? (0 = unlimited)",
"voucher_expire": "How long should a voucher be valid from the time it is used?",
"voucher_duration": "How long should a voucher be valid from the time it is used?",
"voucher_usage_quota": "How much data traffic should be available per voucher? (0 = unlimited)"
}
}
Expand Down Expand Up @@ -55,7 +55,7 @@
"wlan_name": "What is the name of your guest WLAN?",
"voucher_number": "How many new vouchers should be created at the same time?",
"voucher_quota": "How often should a voucher be usable? (0 = unlimited)",
"voucher_expire": "How long should a voucher be valid from the time it is used?",
"voucher_duration": "How long should a voucher be valid from the time it is used?",
"voucher_usage_quota": "How much data traffic should be available per voucher? (0 = unlimited)"
}
}
Expand Down Expand Up @@ -118,7 +118,7 @@
}
}
},
"voucher_expire": {
"voucher_duration": {
"name": "Standard: Expire",
"state_attributes": {
"last_pull": {
Expand Down Expand Up @@ -198,8 +198,8 @@
"name": "Quota per Voucher",
"description": "Specifies how often a voucher can be used (0 = unlimited)."
},
"expire": {
"name": "Expiration",
"duration": {
"name": "Duration",
"description": "Specifies how long a voucher is valid (in hours) from the time it is entered."
},
"usage_quota": {
Expand Down
8 changes: 4 additions & 4 deletions custom_components/unifi_voucher/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"wlan_name": "Wie lautet der Namen deines Gast-WLANs?",
"voucher_number": "Wie viele neue Gutschein sollen gleichzeitig erstellt werden?",
"voucher_quota": "Wie viel Datenverkehr soll pro Gutschein nutzbar sein? (0 = unbegrenzt)",
"voucher_expire": "Wie lange soll ein Gutschein ab Einlösen gültig sein?",
"voucher_duration": "Wie lange soll ein Gutschein ab Einlösen gültig sein?",
"voucher_usage_quota": "Wie viel Datenverkehr soll pro Gutschein nutzbar sein? (0 = unbegrenzt)"
}
}
Expand Down Expand Up @@ -55,7 +55,7 @@
"wlan_name": "Wie lautet der Namen deines Gast-WLANs?",
"voucher_number": "Wie viele neue Gutschein sollen gleichzeitig erstellt werden?",
"voucher_quota": "Wie häufig soll ein Gutschein nutzbar sein? (0 = unbegrenzt)",
"voucher_expire": "Wie lange soll ein Gutschein ab Einlösen gültig sein?",
"voucher_duration": "Wie lange soll ein Gutschein ab Einlösen gültig sein?",
"voucher_usage_quota": "Wie viel Datenverkehr soll pro Gutschein nutzbar sein? (0 = unbegrenzt)"
}
}
Expand Down Expand Up @@ -118,7 +118,7 @@
}
}
},
"voucher_expire": {
"voucher_duration": {
"name": "Standard: Ablaufen",
"state_attributes": {
"last_pull": {
Expand Down Expand Up @@ -198,7 +198,7 @@
"name": "Kontingent pro Gutschein",
"description": "Gibt an, wie oft ein Gutschein verwendet werden kann (0 = unbegrenzt)."
},
"expire": {
"duration": {
"name": "Ablauf",
"description": "Gibt an, wie lange ein Gutschein ab dem Zeitpunkt seiner Eingabe gültig ist (in Stunden)."
},
Expand Down
10 changes: 5 additions & 5 deletions custom_components/unifi_voucher/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"wlan_name": "What is the name of your guest WLAN?",
"voucher_number": "How many new vouchers should be created at the same time?",
"voucher_quota": "How much data traffic should be available per voucher? (0 = unlimited)",
"voucher_expire": "How long should a voucher be valid from the time it is used?",
"voucher_duration": "How long should a voucher be valid from the time it is used?",
"voucher_usage_quota": "How much data traffic should be available per voucher? (0 = unlimited)"
}
}
Expand Down Expand Up @@ -55,7 +55,7 @@
"wlan_name": "What is the name of your guest WLAN?",
"voucher_number": "How many new vouchers should be created at the same time?",
"voucher_quota": "How often should a voucher be usable? (0 = unlimited)",
"voucher_expire": "How long should a voucher be valid from the time it is used?",
"voucher_duration": "How long should a voucher be valid from the time it is used?",
"voucher_usage_quota": "How much data traffic should be available per voucher? (0 = unlimited)"
}
}
Expand Down Expand Up @@ -118,7 +118,7 @@
}
}
},
"voucher_expire": {
"voucher_duration": {
"name": "Standard: Expire",
"state_attributes": {
"last_pull": {
Expand Down Expand Up @@ -198,8 +198,8 @@
"name": "Quota per Voucher",
"description": "Specifies how often a voucher can be used (0 = unlimited)."
},
"expire": {
"name": "Expiration",
"duration": {
"name": "Duration",
"description": "Specifies how long a voucher is valid (in hours) from the time it is entered."
},
"usage_quota": {
Expand Down

0 comments on commit e0b30c0

Please sign in to comment.