2023-11-03 23:00:05 +02:00
|
|
|
extends StaticBody3D
|
|
|
|
|
|
|
|
@export var entity_id = "sensor.sun_next_dawn"
|
|
|
|
@onready var label: Label3D = $Label
|
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2023-11-24 02:36:31 +02:00
|
|
|
var stateInfo = await HomeApi.get_state(entity_id)
|
2023-11-14 01:51:48 +02:00
|
|
|
set_text(stateInfo)
|
2023-11-03 23:00:05 +02:00
|
|
|
|
2023-11-24 02:36:31 +02:00
|
|
|
await HomeApi.watch_state(entity_id, func(new_state):
|
2023-11-14 01:51:48 +02:00
|
|
|
set_text(new_state)
|
2023-11-03 23:00:05 +02:00
|
|
|
)
|
|
|
|
|
2023-11-14 01:51:48 +02:00
|
|
|
func set_text(stateInfo):
|
|
|
|
var text = stateInfo["state"]
|
|
|
|
|
|
|
|
if stateInfo["attributes"]["friendly_name"] != null:
|
|
|
|
text = stateInfo["attributes"]["friendly_name"] + "\n" + text
|
|
|
|
|
|
|
|
if stateInfo["attributes"].has("unit_of_measurement") && stateInfo["attributes"]["unit_of_measurement"] != null:
|
|
|
|
text += " " + stateInfo["attributes"]["unit_of_measurement"]
|
|
|
|
|
|
|
|
label.text = text
|
2023-12-09 19:39:38 +02:00
|
|
|
|
|
|
|
func _save():
|
|
|
|
return {
|
|
|
|
"transform": transform,
|
|
|
|
"entity_id": entity_id
|
|
|
|
}
|