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

Improve string formatting #247

Merged
merged 1 commit into from
Jul 29, 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
14 changes: 8 additions & 6 deletions python_scripts/shellies_discovery_gen2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1877,13 +1877,15 @@ def get_sensor(
sensor_name = f"{switch_name} {description[KEY_NAME]}"
elif emeter_id is not None:
unique_id = f"{device_id}-{emeter_id}-{emeter_phase}-{sensor}".lower()
sensor_name = f"{description[KEY_NAME].format(phase=emeter_phase.upper())}"
sensor_name = description[KEY_NAME].format(phase=emeter_phase.upper())
elif sensor_id is not None:
unique_id = f"{device_id}-{sensor_id}-{sensor}".lower()
sensor_name = f"{device_config[f'{sensor}:{sensor_id}']['name'] or description[KEY_NAME].format(sensor=sensor_id)}"
sensor_name = device_config[f"{sensor}:{sensor_id}"][ATTR_NAME] or description[
KEY_NAME
].format(sensor=sensor_id)
else:
unique_id = f"{device_id}-{sensor}".lower()
sensor_name = f"{description[KEY_NAME]}"
sensor_name = description[KEY_NAME]

payload = {
KEY_NAME: sensor_name,
Expand Down Expand Up @@ -1969,7 +1971,7 @@ def get_binary_sensor(
)
else:
unique_id = f"{device_id}-{sensor}".lower()
sensor_name = f"{description[KEY_NAME]}"
sensor_name = description[KEY_NAME]

if is_input and input_type != ATTR_SWITCH:
payload = ""
Expand Down Expand Up @@ -2072,7 +2074,7 @@ def get_button(button, description):
topic = encode_config_topic(f"{disc_prefix}/button/{device_id}-{button}/config")

payload = {
KEY_NAME: f"{description[KEY_NAME]}",
KEY_NAME: description[KEY_NAME],
KEY_COMMAND_TOPIC: TOPIC_RPC,
KEY_PAYLOAD_PRESS: description[KEY_PAYLOAD_PRESS].format(source=source_topic),
KEY_ENABLED_BY_DEFAULT: str(description[KEY_ENABLED_BY_DEFAULT]).lower(),
Expand Down Expand Up @@ -2102,7 +2104,7 @@ def get_update(update, description):
topic = encode_config_topic(f"{disc_prefix}/update/{device_id}-{update}/config")

payload = {
KEY_NAME: f"{description[KEY_NAME]}",
KEY_NAME: description[KEY_NAME],
KEY_ENABLED_BY_DEFAULT: str(description[KEY_ENABLED_BY_DEFAULT]).lower(),
KEY_UNIQUE_ID: f"{device_id}-{update}".lower(),
KEY_STATE_TOPIC: description[KEY_STATE_TOPIC],
Expand Down