2024-04-11 17:51:30 +03:00
|
|
|
const HASS_API = preload ("../hass.gd")
|
|
|
|
|
|
|
|
var api: HASS_API
|
|
|
|
var integration_exists: bool = false
|
|
|
|
|
|
|
|
func _init(hass: HASS_API):
|
|
|
|
self.api = hass
|
|
|
|
|
|
|
|
func get_history(entity_id: String, start: String, end=null):
|
|
|
|
var meta_response = await api.send_request_packet({
|
|
|
|
"type": "recorder/get_statistics_metadata",
|
|
|
|
"statistic_ids": [
|
|
|
|
entity_id
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2024-05-10 02:00:31 +03:00
|
|
|
if meta_response.status != OK:
|
|
|
|
return null
|
|
|
|
|
2024-04-11 17:51:30 +03:00
|
|
|
var data_response = await api.send_request_packet({
|
|
|
|
"type": "recorder/statistics_during_period",
|
|
|
|
"start_time": start,
|
|
|
|
"statistic_ids": [
|
|
|
|
entity_id
|
|
|
|
],
|
|
|
|
"period": "5minute",
|
|
|
|
"types": [
|
|
|
|
"state",
|
|
|
|
"mean"
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2024-05-10 02:00:31 +03:00
|
|
|
if data_response.status != OK:
|
|
|
|
return null
|
|
|
|
|
2024-04-11 17:51:30 +03:00
|
|
|
return {
|
|
|
|
"unit": meta_response.payload.result[0]["display_unit_of_measurement"],
|
|
|
|
"has_mean": meta_response.payload.result[0]["has_mean"],
|
|
|
|
"unit_class": meta_response.payload.result[0]["unit_class"],
|
|
|
|
"data": data_response.payload.result[entity_id]
|
2024-05-06 19:22:12 +03:00
|
|
|
}
|