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

Don't prune blank entity names in overridden discovery data #523

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion insteon_mqtt/mqtt/topic/DiscoveryTopic.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def _apply_discovery_overrides(self, entities, disc_overrides):
# delete any keys with empty string values
keys_to_delete = []
for key, val in config.items():
if val == "":
if val == "" and key != "name":
keys_to_delete.append(key)
for key in keys_to_delete:
del config[key]
Expand Down
7 changes: 7 additions & 0 deletions tests/mqtt/topic/test_DiscoveryTopic.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def test_load_device_discovery_overrides(self, discovery_fan, caplog):
'fake': {
"component": "fan",
"config": {
"name": "",
"unique_id": "unique",
"icon": "fake",
},
Expand Down Expand Up @@ -226,6 +227,7 @@ def test_load_device_discovery_overrides(self, discovery_fan, caplog):
discovery_fan.disc_templates = []

# test for adding config attribute
# Also test that name isn't removed
discovery_fan.device.config_extra['discovery_overrides'] = { 'fake': {
"config": {
"foo": "fake",
Expand All @@ -234,9 +236,12 @@ def test_load_device_discovery_overrides(self, discovery_fan, caplog):
discovery_fan.load_discovery_data(config)
payload = json.loads(discovery_fan.disc_templates[0].payload_str)
assert payload.get("foo", None) == "fake"
assert "name" in payload
assert payload.get("name", None) == ""
discovery_fan.disc_templates = []

# test for deleting config attribute
# Also test that name isn't removed
discovery_fan.device.config_extra['discovery_overrides'] = { 'fake': {
"config": {
"icon": "",
Expand All @@ -245,6 +250,8 @@ def test_load_device_discovery_overrides(self, discovery_fan, caplog):
discovery_fan.load_discovery_data(config)
payload = json.loads(discovery_fan.disc_templates[0].payload_str)
assert "icon" not in payload
assert "name" in payload
assert payload.get("name", None) == ""
discovery_fan.disc_templates = []

# test for overriding device info
Expand Down