async def publish_values(self): with PubSub.Listener(self.hub) as queue: while True: key, value = await queue.get() try: mapping = self.mappings[key] except KeyError: continue if mapping.mode == Mapping.MODE_WRITEONLY: continue if mapping.throttle: try: last_send = self.last_send[mapping.key] except KeyError: last_send = 0 if last_send + mapping.throttle > time.time(): continue await self.client.publish(self.write_topic(mapping.key), mapping.formatter.to_mqtt(value)) self.last_send[mapping.key] = time.time()
async def printer(hub, ignored_topics=frozenset()): with PubSub.Listener(hub) as queue: while True: key, msg = await queue.get() if key not in ignored_topics: print(f'Reader for key {key} got message: {msg}')