Skip to content

Commit d9db475

Browse files
committed
listeners for balance
1 parent 6326d76 commit d9db475

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

teslemetry_stream/stream.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,22 @@ async def listen(self):
202202
LOGGER.error("Uncaught error in listener: %s", error)
203203
LOGGER.debug("Listen has finished")
204204

205+
def listen_Credits(self, callback: Callable[[dict[str, str | int]], None]) -> Callable[[], None]:
206+
"""Listen for credits update."""
207+
208+
return self.async_add_listener(
209+
lambda x: callback(x["credits"]),
210+
{"credits": None}
211+
)
212+
213+
def listen_Balance(self, callback: Callable[[int], None]) -> Callable[[], None]:
214+
"""Listen for credits balance."""
215+
216+
return self.async_add_listener(
217+
lambda x: callback(x["credits"]["balance"]),
218+
{"credits": {"balance": None}}
219+
)
220+
205221
def recursive_match(dict1, dict2):
206222
"""Recursively match dict1 with dict2."""
207223
if dict1 is not None:

0 commit comments

Comments
 (0)