immersive-home/lib/home_adapters/adapter.gd

42 lines
914 B
GDScript3
Raw Normal View History

2023-10-30 02:21:50 +02:00
extends Node
2023-11-05 16:16:07 +02:00
const hass = preload("res://lib/home_adapters/hass/hass.gd")
const hass_ws = preload("res://lib/home_adapters/hass_ws/hass.gd")
2023-10-30 02:21:50 +02:00
enum ADAPTER_TYPES {
2023-11-03 00:13:55 +02:00
HASS,
HASS_WS
2023-10-30 02:21:50 +02:00
}
const adapters = {
2023-11-03 00:13:55 +02:00
ADAPTER_TYPES.HASS: hass,
ADAPTER_TYPES.HASS_WS: hass_ws
2023-10-30 02:21:50 +02:00
}
const methods = [
"load_devices",
"get_state",
"set_state"
2023-10-30 02:21:50 +02:00
]
var adapter: Node
func _init(type: ADAPTER_TYPES):
adapter = adapters[type].new()
2023-11-03 00:13:55 +02:00
add_child(adapter)
2023-10-30 02:21:50 +02:00
for method in methods:
assert(adapter.has_method(method), "Adapter does not implement method: " + method)
func load_devices():
return await adapter.load_devices()
func get_state(entity: String):
return await adapter.get_state(entity)
func set_state(entity: String, state: String, attributes: Dictionary = {}):
2023-11-03 00:13:55 +02:00
return await adapter.set_state(entity, state, attributes)
func watch_state(entity: String, callback: Callable):
return adapter.watch_state(entity, callback)