Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix friendly name of unnamed Tasmota devices #249

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion hatasmota/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Any, cast

from .const import (
CONF_DEVICENAME,
CONF_FRIENDLYNAME,
CONF_FULLTOPIC,
CONF_HOSTNAME,
Expand Down Expand Up @@ -201,12 +202,14 @@ def get_state_button_trigger(status: str) -> Any:
return get_value(status, RSLT_ACTION)


def config_get_friendlyname(config: ConfigType, platform: str, idx: int) -> str:
def config_get_friendlyname(config: ConfigType, platform: str, idx: int) -> str | None:
"""Get config friendly name."""
friendly_names = config[CONF_FRIENDLYNAME]

if idx >= len(friendly_names) or friendly_names[idx] is None:
return f"{platform} {idx+1}"
if idx == 0 and friendly_names[idx] == config[CONF_DEVICENAME]:
return None
return friendly_names[idx]


Expand Down
Loading