-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add binary sensor support and fix areas
- Loading branch information
Showing
9 changed files
with
98 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
extends Entity | ||
|
||
const Entity = preload ("../entity.gd") | ||
|
||
@onready var label: Label3D = $Label | ||
@onready var state: Label3D = $State | ||
@onready var collision_shape = $CollisionShape3D | ||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
super() | ||
|
||
icon.value = "sensors" | ||
|
||
var stateInfo = await HomeApi.get_state(entity_id) | ||
set_text(stateInfo) | ||
|
||
await HomeApi.watch_state(entity_id, func(new_state): | ||
set_text(new_state) | ||
) | ||
|
||
func set_text(stateInfo): | ||
if stateInfo == null: | ||
return | ||
|
||
state.text = "check_box" if stateInfo["state"] == "True" else "check_box_outline_blank" | ||
|
||
if stateInfo["attributes"]["friendly_name"] != null: | ||
label.text = stateInfo["attributes"]["friendly_name"] | ||
|
||
var state_font = state.get_font() | ||
var state_size = state_font.get_string_size(state.text, HORIZONTAL_ALIGNMENT_LEFT, -1, state.font_size) * state.pixel_size | ||
var label_font = label.get_font() | ||
var label_size = label_font.get_string_size(label.text, HORIZONTAL_ALIGNMENT_RIGHT, -1, label.font_size) * label.pixel_size | ||
|
||
var size = Vector2(max(state_size.x, label_size.x) * 0.5, (state_size.y + label_size.y) * 0.25) | ||
|
||
collision_shape.shape.size.x = size.x | ||
collision_shape.shape.size.y = size.y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[gd_scene load_steps=6 format=3 uid="uid://bdnxxqng3s6l"] | ||
|
||
[ext_resource type="Script" path="res://content/entities/binary_sensor/binary_sensor.gd" id="1_ac2fh"] | ||
[ext_resource type="FontFile" uid="uid://cs508knjj1lnw" path="res://assets/fonts/Raleway-Medium.ttf" id="2_dqk35"] | ||
[ext_resource type="Script" path="res://content/functions/movable.gd" id="3_mxubb"] | ||
[ext_resource type="FontVariation" uid="uid://sshfnckriqxn" path="res://assets/icons/icons.tres" id="3_pen57"] | ||
|
||
[sub_resource type="BoxShape3D" id="BoxShape3D_mjnxo"] | ||
resource_local_to_scene = true | ||
size = Vector3(0.18, 0.03, 0.02) | ||
|
||
[node name="BinarySensor" type="StaticBody3D"] | ||
script = ExtResource("1_ac2fh") | ||
|
||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."] | ||
shape = SubResource("BoxShape3D_mjnxo") | ||
|
||
[node name="Label" type="Label3D" parent="."] | ||
transform = Transform3D(0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, 0, 0.02, 0) | ||
pixel_size = 0.001 | ||
text = "some text | ||
" | ||
font = ExtResource("2_dqk35") | ||
font_size = 80 | ||
outline_size = 0 | ||
|
||
[node name="State" type="Label3D" parent="."] | ||
transform = Transform3D(0.4, 0, 0, 0, 0.4, 0, 0, 0, 0.4, 0, -0.02, 0) | ||
pixel_size = 0.001 | ||
text = "check_box" | ||
font = ExtResource("3_pen57") | ||
font_size = 80 | ||
outline_size = 0 | ||
|
||
[node name="Movable" type="Node" parent="."] | ||
script = ExtResource("3_mxubb") | ||
resizable = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters