From: Eugene Crosser Date: Fri, 15 Jul 2022 11:01:05 +0000 (+0200) Subject: beesure: implement phone book commands X-Git-Tag: 1.90~19 X-Git-Url: http://www.average.org/gitweb/?p=loctrkd.git;a=commitdiff_plain;h=29a75727df57986490b02853208d30f6f878bf8b beesure: implement phone book commands --- diff --git a/loctrkd/beesure.py b/loctrkd/beesure.py index 9346b55..34108e1 100755 --- a/loctrkd/beesure.py +++ b/loctrkd/beesure.py @@ -171,6 +171,21 @@ def l3str(x: Union[str, List[str]]) -> List[str]: return lx +def pblist(x: Union[str, List[Tuple[str, str]]]) -> List[Tuple[str, str]]: + if isinstance(x, str): + + def splitpair(s: str) -> Tuple[str, str]: + a, b = s.split(":") + return a, b + + lx = [splitpair(el) for el in x.split(",")] + else: + lx = x + if len(lx) > 5: + raise ValueError(str(lx) + " has too many elements (max 5)") + return lx + + class MetaPkt(type): """ For each class corresponding to a message, automatically create @@ -439,6 +454,29 @@ class FLOWER(BeeSurePkt): return str(self.number) +class _PHB(BeeSurePkt): + OUT_KWARGS: Tuple[Tuple[str, Callable[[Any], Any], Any], ...] = ( + ("entries", pblist, []), + ) + + def out_encode(self) -> str: + self.entries: List[Tuple[str, str]] + return ",".join( + [ + ",".join((num, name.encode("utf_16_be").hex())) + for name, num in self.entries + ] + ) + + +class PHB(_PHB): + pass + + +class PHB2(_PHB): + pass + + class POWEROFF(BeeSurePkt): pass