X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=loctrkd%2Fbeesure.py;h=34108e12d25993c59d64d09b72c331d186cbf728;hb=29a75727df57986490b02853208d30f6f878bf8b;hp=9346b55979eaf49540172a2b61810d1812084031;hpb=15537c8be40f3ba25c5a51af75d9bed53a8a215d;p=loctrkd.git 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