Skip to content

Commit a3fc22d

Browse files
committed
fixed issue with index rebuild for arrays
1 parent 8e8c45d commit a3fc22d

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

examples/simple_ws.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ def command_active_monitor(command: str, active: bool):
3737
dataref = ws.dataref("sim/cockpit2/clock_timer/local_time_seconds")
3838
ws.monitor_dataref(dataref)
3939

40+
arrdref = ws.dataref("sim/weather/aircraft/wind_direction_degt[0]")
41+
ws.monitor_dataref(arrdref)
42+
4043
ws.monitor_command_active(ws.command("sim/map/show_current"))
4144

4245
print("\n\nplease activate map in X-Plane with sim/map/show_current (usually key stroke 'm')\n")

xpwebapi/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,9 @@ def get_string_value(self, encoding: str) -> str | None:
486486
logger.warning("value type is not data")
487487
return None
488488
value_bytes = self.value
489-
value_bytes_stripped = value_bytes.rstrip(b"\x00") # remove trailing 0 (bytes with value 0)
490-
if len(value_bytes_stripped) > 0:
491-
value_bytes = value_bytes_stripped
489+
if value_bytes is None:
490+
logger.debug("no value")
491+
return None
492492
if type(value_bytes) is not bytes:
493493
logger.warning("value is not bytes")
494494
return None

xpwebapi/rest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,14 @@ def rebuild_dataref_ids(self):
296296
"""Rebuild dataref idenfier index"""
297297
if len(self._dataref_by_id) > 0:
298298
if self.all_datarefs.has_data:
299-
self._dataref_by_id = {d.ident: d for d in self._dataref_by_id.values()}
299+
newdict = dict()
300+
for d in self._dataref_by_id.values():
301+
if type(d) is Dataref:
302+
newdict[d.ident] = d
303+
elif type(d) is list and len(d) > 0:
304+
t = d[0] # ident of first element, same for all elements in the list
305+
newdict[t.ident] = d
306+
self._dataref_by_id = newdict
300307
logger.info("dataref ids rebuilt")
301308
return
302309
logger.warning("no data to rebuild dataref ids")

0 commit comments

Comments
 (0)