display correct names in entities menu

This commit is contained in:
Nitwel 2024-05-06 12:42:45 +02:00
parent 927521419f
commit 4c4b0fdd2a
6 changed files with 33 additions and 24 deletions

View File

@ -10,7 +10,7 @@
[sub_resource type="BoxShape3D" id="BoxShape3D_3qyo4"]
size = Vector3(0.32, 0.16, 0.02)
[sub_resource type="ShaderMaterial" id="ShaderMaterial_h0yvw"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_cw188"]
resource_local_to_scene = true
render_priority = 10
shader = ExtResource("6_40cd1")
@ -25,7 +25,7 @@ shader_parameter/corner_radius = 0.8
shader_parameter/roughness = 0.3
shader_parameter/grain_amount = 0.02
[sub_resource type="QuadMesh" id="QuadMesh_a23j8"]
[sub_resource type="QuadMesh" id="QuadMesh_ryeda"]
size = Vector2(0.32, 0.16)
[node name="Timer" type="StaticBody3D" groups=["entity"]]
@ -78,7 +78,7 @@ label = "stop"
icon = true
[node name="Panel" parent="." instance=ExtResource("5_j3gsb")]
material_override = SubResource("ShaderMaterial_h0yvw")
mesh = SubResource("QuadMesh_a23j8")
material_override = SubResource("ShaderMaterial_cw188")
mesh = SubResource("QuadMesh_ryeda")
size = Vector2(0.32, 0.16)
corner_radius = 0.8

View File

@ -18,8 +18,7 @@ func _ready():
if search.value != "":
return devices.filter(func(device):
var info=device.values()[0]
return info["name"].to_lower().find(search.value.to_lower()) != - 1
return device["name"].to_lower().find(search.value.to_lower()) != - 1||device["id"].to_lower().find(search.value.to_lower()) != - 1
)
return devices
@ -47,13 +46,12 @@ func _ready():
child.free()
for device in visible_devices.value:
var info=device.values()[0]
var button_instance=ButtonScene.instantiate()
button_instance.label=info["name"]
button_instance.label=device["name"]
button_instance.font_size=8
button_instance.on_button_up.connect(func():
on_select_device.emit(device.keys()[0])
on_select_device.emit(device["id"])
)
grid_container.add_child(button_instance)

View File

@ -22,13 +22,13 @@ func _ready():
var entities=[]
for device in devices:
if device.keys()[0] == selected_device.value:
entities=device.values()[0]["entities"]
if device["id"] == selected_device.value:
entities=device["entities"]
break
if search.value != "":
return entities.filter(func(entity):
return entity.to_lower().find(search.value.to_lower()) != - 1
return entity["name"].to_lower().find(search.value.to_lower()) != - 1||entity["id"].to_lower().find(search.value.to_lower()) != - 1
)
return entities
@ -61,10 +61,10 @@ func _ready():
for entity in visible_entities.value:
var entity_node=EntityScene.instantiate()
entity_node.icon=EntityFactory.get_entity_icon(entity.split(".")[0])
entity_node.text=entity
entity_node.icon=EntityFactory.get_entity_icon(entity["id"].split(".")[0])
entity_node.text=entity["name"]
entity_node.on_select.connect(func():
on_select_entity.emit(entity)
on_select_entity.emit(entity["id"])
)
entity_container.add_child(entity_node)

View File

@ -1,6 +1,6 @@
extends Node3D
@onready var voice_assist = $Content/VoiceAssist
@onready var voice_assist = $VoiceAssist
func _ready():
var settings_store = Store.settings.state
@ -36,4 +36,4 @@ func _ready():
)
R.bind(voice_assist, "label", button_label)
R.bind(voice_assist, "active", settings_store, "voice_assistant")
R.bind(voice_assist, "active", settings_store, "voice_assistant")

View File

@ -1,19 +1,23 @@
{% set devices = states | map(attribute='entity_id') | map('device_id') | unique | reject('eq',None) | list %}
{%- set ns = namespace(devices = []) %}
{%- set ns = namespace(devices = [], entities = []) %}
{%- for device in devices %}
{%- set entities = device_entities(device) | list %}
{%- set ns.entities = [] %}
{%- if entities %}
{%- set ns.devices = ns.devices + [ {device: {"name": device_attr(device, "name"), "entities": entities }} ] %}
{%- for entity in entities %}
{%- set ns.entities = ns.entities + [ {"id": entity, "name": state_attr(entity, "friendly_name")} ] %}
{%- endfor %}
{%- set ns.devices = ns.devices + [{"id": device, "name": device_attr(device, "name"), "entities": ns.entities } ] %}
{%- endif %}
{%- endfor %}
{%- set ns_group = namespace(entities = []) %}
{%- for state in states %}
{%- if device_id(state.entity_id) == None %}
{%- set ns_group.entities = ns_group.entities + [state.entity_id] %}
{%- set ns_group.entities = ns_group.entities + [{"id": state.entity_id, "name": state.entity_id}] %}
{%- endif %}
{%- endfor %}
{%- set ns.devices = ns.devices + [ {"other": {"name": "Other", "entities": ns_group.entities }} ] %}
{%- set ns.devices = ns.devices + [ {"id": "other.other", "name": "Other", "entities": ns_group.entities } ] %}
{{ ns.devices }}

View File

@ -10,12 +10,19 @@ func _init():
var devices=await HomeApi.get_devices()
devices.sort_custom(func(a, b):
return a.values()[0]["name"].to_lower() < b.values()[0]["name"].to_lower()
return a["name"].to_lower() < b["name"].to_lower()
)
for device in devices:
device.values()[0]["entities"].sort_custom(func(a, b):
return a.to_lower() < b.to_lower()
if device["name"] == null:
device["name"]=device["id"]
for entity in device["entities"]:
if entity["name"] == null:
entity["name"]=entity["id"]
device["entities"].sort_custom(func(a, b):
return a["name"].to_lower() < b["name"].to_lower()
)
self.state.devices=devices