Skip to content

Commit

Permalink
Translate profile names for service
Browse files Browse the repository at this point in the history
  • Loading branch information
treetip committed Sep 7, 2024
1 parent 7b4cb04 commit f5b68b6
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 18 deletions.
6 changes: 3 additions & 3 deletions homeassistant/components/vallox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
DEFAULT_FAN_SPEED_HOME,
DEFAULT_NAME,
DOMAIN,
PRESET_MODE_TO_VALLOX_PROFILE,
I18N_KEY_TO_VALLOX_PROFILE,
)
from .coordinator import ValloxDataUpdateCoordinator

Expand Down Expand Up @@ -67,7 +67,7 @@

SERVICE_SCHEMA_SET_PROFILE = vol.Schema(
{
vol.Required(ATTR_PROFILE): vol.In(PRESET_MODE_TO_VALLOX_PROFILE),
vol.Required(ATTR_PROFILE): vol.In(I18N_KEY_TO_VALLOX_PROFILE),
vol.Optional(ATTR_DURATION): vol.All(
vol.Coerce(int), vol.Clamp(min=1, max=65535)
),
Expand Down Expand Up @@ -207,7 +207,7 @@ async def async_set_profile(
_LOGGER.debug("Activating profile %s for %s min", profile, duration)
try:
await self._client.set_profile(
PRESET_MODE_TO_VALLOX_PROFILE[profile], duration
I18N_KEY_TO_VALLOX_PROFILE[profile], duration
)
except ValloxApiException as err:
_LOGGER.error(
Expand Down
8 changes: 8 additions & 0 deletions homeassistant/components/vallox/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
DEFAULT_FAN_SPEED_AWAY = 25
DEFAULT_FAN_SPEED_BOOST = 65

I18N_KEY_TO_VALLOX_PROFILE = {
"home": VALLOX_PROFILE.HOME,
"away": VALLOX_PROFILE.AWAY,
"boost": VALLOX_PROFILE.BOOST,
"fireplace": VALLOX_PROFILE.FIREPLACE,
"extra": VALLOX_PROFILE.EXTRA,
}

VALLOX_PROFILE_TO_PRESET_MODE = {
VALLOX_PROFILE.HOME: "Home",
VALLOX_PROFILE.AWAY: "Away",
Expand Down
11 changes: 6 additions & 5 deletions homeassistant/components/vallox/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ set_profile:
required: true
selector:
select:
translation_key: "profile"
options:
- "Home"
- "Away"
- "Boost"
- "Fireplace"
- "Extra"
- "home"
- "away"
- "boost"
- "fireplace"
- "extra"
duration:
required: false
selector:
Expand Down
11 changes: 11 additions & 0 deletions homeassistant/components/vallox/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,16 @@
}
}
}
},
"selector": {
"profile": {
"options": {
"home": "Home",
"away": "Away",
"boost": "Boost",
"fireplace": "Fireplace",
"extra": "Extra"
}
}
}
}
20 changes: 10 additions & 10 deletions tests/components/vallox/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ async def test_create_service(
@pytest.mark.parametrize(
("profile", "duration"),
[
("Home", None),
("Home", 15),
("Away", None),
("Away", 15),
("Boost", None),
("Boost", 15),
("Fireplace", None),
("Fireplace", 15),
("Extra", None),
("Extra", 15),
("home", None),
("home", 15),
("away", None),
("away", 15),
("boost", None),
("boost", 15),
("fireplace", None),
("fireplace", 15),
("extra", None),
("extra", 15),
],
)
async def test_set_profile_service(
Expand Down

0 comments on commit f5b68b6

Please sign in to comment.