2023-10-30 02:21:50 +02:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
const hass = preload("res://src/home_adapters/hass/hass.gd")
|
2023-11-03 00:13:55 +02:00
|
|
|
const hass_ws = preload("res://src/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 = [
|
2023-10-31 23:15:33 +02:00
|
|
|
"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()
|
2023-10-31 23:15:33 +02:00
|
|
|
|
|
|
|
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)
|