2024-01-27 16:13:43 +02:00
|
|
|
extends Entity
|
|
|
|
|
2024-04-17 17:49:58 +03:00
|
|
|
const Entity = preload ("../entity.gd")
|
2023-12-10 01:34:54 +02:00
|
|
|
|
|
|
|
@onready var button = $Button
|
|
|
|
|
|
|
|
func _ready():
|
2024-01-27 16:13:43 +02:00
|
|
|
super()
|
|
|
|
|
2024-04-17 17:49:58 +03:00
|
|
|
icon.value = "radio_button_checked"
|
|
|
|
|
2023-12-10 01:34:54 +02:00
|
|
|
var stateInfo = await HomeApi.get_state(entity_id)
|
|
|
|
|
|
|
|
if stateInfo == null:
|
|
|
|
return
|
|
|
|
|
|
|
|
set_state(stateInfo)
|
|
|
|
|
|
|
|
await HomeApi.watch_state(entity_id, func(new_state):
|
|
|
|
set_state(new_state)
|
|
|
|
)
|
|
|
|
|
|
|
|
button.on_button_down.connect(func():
|
|
|
|
HomeApi.set_state(entity_id, "pressed")
|
|
|
|
)
|
|
|
|
|
|
|
|
func set_state(state):
|
|
|
|
if state.attributes.has("friendly_name"):
|
2023-12-11 13:57:19 +02:00
|
|
|
var name = state.attributes["friendly_name"]
|
|
|
|
|
|
|
|
if name.begins_with("icon:"):
|
|
|
|
name = name.substr(5)
|
|
|
|
button.icon = true
|
|
|
|
else:
|
|
|
|
button.icon = false
|
|
|
|
button.label = name
|
2024-04-17 22:27:09 +03:00
|
|
|
|
|
|
|
func quick_action():
|
|
|
|
HomeApi.set_state(entity_id, "pressed")
|