Revert "Change naming of Shelly entities to correspond with HA guidelines" (#99059)

This commit is contained in:
Shay Levy 2023-08-28 11:42:24 +03:00 committed by GitHub
parent bb545b1c4d
commit b0f3b7bb76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 59 additions and 66 deletions

View file

@ -72,26 +72,26 @@ def get_block_entity_name(
device: BlockDevice,
block: Block | None,
description: str | None = None,
) -> str | None:
) -> str:
"""Naming for block based switch and sensors."""
channel_name = get_block_channel_name(device, block)
if description and channel_name:
return f"{channel_name} {uncapitalize(description)}"
if description:
return description
return f"{channel_name} {description.lower()}"
return channel_name
def get_block_channel_name(device: BlockDevice, block: Block | None) -> str | None:
def get_block_channel_name(device: BlockDevice, block: Block | None) -> str:
"""Get name based on device and channel name."""
entity_name = device.name
if (
not block
or block.type == "device"
or get_number_of_channels(device, block) == 1
):
return None
return entity_name
assert block.channel
@ -108,7 +108,7 @@ def get_block_channel_name(device: BlockDevice, block: Block | None) -> str | No
else:
base = ord("1")
return f"Channel {chr(int(block.channel)+base)}"
return f"{entity_name} channel {chr(int(block.channel)+base)}"
def is_block_momentary_input(
@ -285,32 +285,32 @@ def get_model_name(info: dict[str, Any]) -> str:
return cast(str, MODEL_NAMES.get(info["type"], info["type"]))
def get_rpc_channel_name(device: RpcDevice, key: str) -> str | None:
def get_rpc_channel_name(device: RpcDevice, key: str) -> str:
"""Get name based on device and channel name."""
key = key.replace("emdata", "em")
if device.config.get("switch:0"):
key = key.replace("input", "switch")
device_name = device.name
entity_name: str | None = None
if key in device.config:
entity_name = device.config[key].get("name")
entity_name = device.config[key].get("name", device_name)
if entity_name is None:
if key.startswith(("input:", "light:", "switch:")):
return key.replace(":", " ").capitalize()
return f"{device_name} {key.replace(':', '_')}"
return device_name
return entity_name
def get_rpc_entity_name(
device: RpcDevice, key: str, description: str | None = None
) -> str | None:
) -> str:
"""Naming for RPC based switch and sensors."""
channel_name = get_rpc_channel_name(device, key)
if description and channel_name:
return f"{channel_name} {uncapitalize(description)}"
if description:
return description
return f"{channel_name} {description.lower()}"
return channel_name
@ -405,8 +405,3 @@ def mac_address_from_name(name: str) -> str | None:
"""Convert a name to a mac address."""
mac = name.partition(".")[0].partition("-")[-1]
return mac.upper() if len(mac) == 12 else None
def uncapitalize(description: str) -> str:
"""Uncapitalize the first letter of a description."""
return description[:1].lower() + description[1:]