-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
296 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers import translation as i18n | ||
|
||
from .const import DOMAIN | ||
from .elehant import ElehantData | ||
|
||
|
||
async def get_translated_key( | ||
hass: HomeAssistant, | ||
category: str, | ||
key: str, | ||
placeholders: dict[str, str] | None = None, | ||
fallback: str | None = None, | ||
): | ||
language = hass.config.language | ||
tr = await i18n.async_get_translations(hass, language, category, [DOMAIN]) | ||
|
||
return tr.get(f"component.{DOMAIN}.{category}.{key}", fallback or "").format( | ||
**placeholders or {} | ||
) | ||
|
||
|
||
def get_device_name(hass: HomeAssistant, device: ElehantData): | ||
return get_translated_key( | ||
hass, | ||
"device", | ||
key=f"{device.key_model}.name", | ||
placeholders={"serial": device.str_serial}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.