2024-01-25 17:29:33 +02:00
|
|
|
extends StoreClass
|
2024-04-09 18:11:24 +03:00
|
|
|
const StoreClass = preload ("./store.gd")
|
|
|
|
|
|
|
|
func _init():
|
2024-04-24 02:06:15 +03:00
|
|
|
self.state = R.state({
|
|
|
|
"devices": []
|
|
|
|
})
|
|
|
|
|
|
|
|
HomeApi.on_connect.connect(func():
|
2024-04-25 01:22:27 +03:00
|
|
|
var devices=await HomeApi.get_devices()
|
|
|
|
|
|
|
|
devices.sort_custom(func(a, b):
|
2024-05-06 13:42:45 +03:00
|
|
|
return a["name"].to_lower() < b["name"].to_lower()
|
2024-04-25 01:22:27 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
for device in devices:
|
2024-05-06 13:42:45 +03:00
|
|
|
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()
|
2024-04-25 01:22:27 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
self.state.devices=devices
|
|
|
|
)
|
|
|
|
|
|
|
|
HomeApi.on_disconnect.connect(func():
|
|
|
|
self.state.devices=[]
|
2024-04-24 02:06:15 +03:00
|
|
|
)
|
2024-01-25 17:29:33 +02:00
|
|
|
|
|
|
|
func clear():
|
2024-04-30 20:18:49 +03:00
|
|
|
pass
|