More garbage collection
This commit is contained in:
20
gauge.py
20
gauge.py
@@ -917,7 +917,20 @@ _last_mqtt_check = 0
|
||||
_discovery_queue = []
|
||||
_discovery_idx = 0
|
||||
_last_discovery_ms = 0
|
||||
_DISCOVERY_INTERVAL_MS = 200
|
||||
_DISCOVERY_INTERVAL_MS = 350
|
||||
|
||||
|
||||
def _compact_discovery_payload(payload):
|
||||
"""Trim optional HA discovery fields when RAM is tight."""
|
||||
compact = dict(payload)
|
||||
|
||||
# Light entities are the largest payloads because they repeat effect metadata.
|
||||
# Keep core functionality, but omit optional effect declarations to reduce heap use.
|
||||
if compact.get("schema") == "json":
|
||||
compact.pop("effect", None)
|
||||
compact.pop("effect_list", None)
|
||||
|
||||
return compact
|
||||
|
||||
|
||||
def check_mqtt():
|
||||
@@ -968,7 +981,8 @@ def check_mqtt():
|
||||
|
||||
|
||||
def _publish_discovery_entity(client, topic, payload, log_msg):
|
||||
client.publish(topic, ujson.dumps(payload), retain=True)
|
||||
gc.collect()
|
||||
client.publish(topic, ujson.dumps(_compact_discovery_payload(payload)), retain=True)
|
||||
info(log_msg)
|
||||
|
||||
|
||||
@@ -1241,6 +1255,7 @@ def service_discovery():
|
||||
if _last_discovery_ms and utime.ticks_diff(now, _last_discovery_ms) < _DISCOVERY_INTERVAL_MS:
|
||||
return
|
||||
|
||||
gc.collect()
|
||||
topic, payload, log_msg = _discovery_queue[_discovery_idx]
|
||||
try:
|
||||
if isinstance(payload, bytes):
|
||||
@@ -1251,7 +1266,6 @@ def service_discovery():
|
||||
log_err(f"Discovery publish failed for {topic}: {e}")
|
||||
_discovery_idx += 1
|
||||
_last_discovery_ms = utime.ticks_ms()
|
||||
if (_discovery_idx & 3) == 0:
|
||||
gc.collect()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user