From e0b30c08e9ea4865091d8b07aed81f0ecbc9ce36 Mon Sep 17 00:00:00 2001 From: ufozone Date: Sun, 17 Dec 2023 22:23:24 +0100 Subject: [PATCH] Fix consistent attribute name duration in number entity and create service --- .../unifi_voucher/config_flow.py | 30 +++++++++---------- custom_components/unifi_voucher/const.py | 4 +-- .../unifi_voucher/coordinator.py | 10 +++---- custom_components/unifi_voucher/number.py | 6 ++-- custom_components/unifi_voucher/services.py | 12 ++++---- custom_components/unifi_voucher/services.yaml | 2 +- custom_components/unifi_voucher/strings.json | 10 +++---- .../unifi_voucher/translations/de.json | 8 ++--- .../unifi_voucher/translations/en.json | 10 +++---- 9 files changed, 46 insertions(+), 46 deletions(-) diff --git a/custom_components/unifi_voucher/config_flow.py b/custom_components/unifi_voucher/config_flow.py index 1ce6545..7898795 100644 --- a/custom_components/unifi_voucher/config_flow.py +++ b/custom_components/unifi_voucher/config_flow.py @@ -40,7 +40,7 @@ CONF_WLAN_NAME, CONF_VOUCHER_NUMBER, CONF_VOUCHER_QUOTA, - CONF_VOUCHER_EXPIRE, + CONF_VOUCHER_DURATION, ) from .api import ( UnifiVoucherApiClient, @@ -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. @@ -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, ) ), @@ -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. @@ -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, ) ), diff --git a/custom_components/unifi_voucher/const.py b/custom_components/unifi_voucher/const.py index 14156d7..3313d24 100644 --- a/custom_components/unifi_voucher/const.py +++ b/custom_components/unifi_voucher/const.py @@ -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" @@ -51,7 +51,7 @@ "min": 0, "max": 10000, }, - CONF_VOUCHER_EXPIRE: { + CONF_VOUCHER_DURATION: { "default": 24, "min": 1, "max": 1000000, diff --git a/custom_components/unifi_voucher/coordinator.py b/custom_components/unifi_voucher/coordinator.py index 22e0cb1..750f212 100644 --- a/custom_components/unifi_voucher/coordinator.py +++ b/custom_components/unifi_voucher/coordinator.py @@ -31,7 +31,7 @@ CONF_WLAN_NAME, CONF_VOUCHER_NUMBER, CONF_VOUCHER_QUOTA, - CONF_VOUCHER_EXPIRE, + CONF_VOUCHER_DURATION, DEFAULT_VOUCHER, ) from .api import ( @@ -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, @@ -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, diff --git a/custom_components/unifi_voucher/number.py b/custom_components/unifi_voucher/number.py index 1b68d93..43e3629 100644 --- a/custom_components/unifi_voucher/number.py +++ b/custom_components/unifi_voucher/number.py @@ -15,7 +15,7 @@ from .const import ( DOMAIN, CONF_VOUCHER_QUOTA, - CONF_VOUCHER_EXPIRE, + CONF_VOUCHER_DURATION, DEFAULT_VOUCHER, ) from .coordinator import UnifiVoucherCoordinator @@ -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, ), ] diff --git a/custom_components/unifi_voucher/services.py b/custom_components/unifi_voucher/services.py index 6a556ca..3c211e0 100644 --- a/custom_components/unifi_voucher/services.py +++ b/custom_components/unifi_voucher/services.py @@ -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, @@ -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"), @@ -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( diff --git a/custom_components/unifi_voucher/services.yaml b/custom_components/unifi_voucher/services.yaml index fc8fd54..dcdd003 100644 --- a/custom_components/unifi_voucher/services.yaml +++ b/custom_components/unifi_voucher/services.yaml @@ -23,7 +23,7 @@ create: max: 10000 step: 1 mode: slider - expire: + duration: required: false example: 24 default: 24 diff --git a/custom_components/unifi_voucher/strings.json b/custom_components/unifi_voucher/strings.json index 0c47ce1..6452785 100644 --- a/custom_components/unifi_voucher/strings.json +++ b/custom_components/unifi_voucher/strings.json @@ -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)" } } @@ -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)" } } @@ -118,7 +118,7 @@ } } }, - "voucher_expire": { + "voucher_duration": { "name": "Standard: Expire", "state_attributes": { "last_pull": { @@ -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": { diff --git a/custom_components/unifi_voucher/translations/de.json b/custom_components/unifi_voucher/translations/de.json index 2750d04..760fa79 100644 --- a/custom_components/unifi_voucher/translations/de.json +++ b/custom_components/unifi_voucher/translations/de.json @@ -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)" } } @@ -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)" } } @@ -118,7 +118,7 @@ } } }, - "voucher_expire": { + "voucher_duration": { "name": "Standard: Ablaufen", "state_attributes": { "last_pull": { @@ -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)." }, diff --git a/custom_components/unifi_voucher/translations/en.json b/custom_components/unifi_voucher/translations/en.json index aa1bbcb..725491b 100644 --- a/custom_components/unifi_voucher/translations/en.json +++ b/custom_components/unifi_voucher/translations/en.json @@ -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)" } } @@ -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)" } } @@ -118,7 +118,7 @@ } } }, - "voucher_expire": { + "voucher_duration": { "name": "Standard: Expire", "state_attributes": { "last_pull": { @@ -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": {