Skip to content

Commit

Permalink
Fix friendly name of unnamed Tasmota devices (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored Sep 11, 2023
1 parent 100e99c commit 78e5d59
Showing 1 changed file with 4 additions and 1 deletion.
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

0 comments on commit 78e5d59

Please sign in to comment.