Ejemplo n.º 1
0
 def test_typeset_3lines_single(self, tsetter):
     seq = FrameSequence()
     msg = TextTripleLinesLayout()
     msg.lines = ["Foo", "Bar"]
     tsetter.typeset_3lines(seq, msg)
     assert 1 == len(seq)
     for f in seq.frames:
         assert len(f) == Config()['DISPLAY_SIZE']
Ejemplo n.º 2
0
 def test_typeset_3lines_multi(self, tsetter):
     seq = FrameSequence()
     msg = TextTripleLinesLayout()
     msg.lines = ["Foo", "Bar", "Quux", "Foobar", "FooQuux"]
     tsetter.typeset_3lines(seq, msg)
     assert len(seq) > 1
     for f in seq.frames:
         assert len(f) == Config()['DISPLAY_SIZE']
Ejemplo n.º 3
0
 def test_ledslie_typesetting_3lines_multiline(self, tsetter):
     """I test sending more then 3 lines to the display in 3 lines mode."""
     topic = LEDSLIE_TOPIC_TYPESETTER_3LINES
     msg = TextTripleLinesLayout()
     msg.lines = ["Foo", "Bar", "Quux", "FOOBAR"]
     tsetter.onPublish(topic, msg.serialize(), qos=0, dup=False, retain=False, msgId=0)
     seq_topic, seq_data = tsetter.protocol._published_messages[-1]
     assert seq_topic == LEDSLIE_TOPIC_SEQUENCES_UNNAMED
     res_obj = json.loads(seq_data.decode())
Ejemplo n.º 4
0
 def test_typeset_3lines_none(self, tsetter):
     """
     I test the behaviour when 3lines gets empty lines or None. No Frame should be put onto the FrameSequence.
     """
     seq = FrameSequence()
     msg = TextTripleLinesLayout()
     msg.lines = []
     tsetter.typeset_3lines(seq, msg)
     assert 0 == len(seq)
     msg.lines = None
     tsetter.typeset_3lines(seq, msg)
     assert 0 == len(seq)
Ejemplo n.º 5
0
 def test_ledslie_typesetter_3lines(self, tsetter):
     topic = LEDSLIE_TOPIC_TYPESETTER_3LINES
     msg = TextTripleLinesLayout()
     msg.lines = ["Ledslie \u00a9 GNU-AGPL3 ~ ;-)",
                  "https://wiki.techinc.nl/index.php/Ledslie",
                  "https://github.com/techinc/ledslie"]
     assert 0 == len(tsetter.protocol._published_messages)
     tsetter.onPublish(topic, msg.serialize(), qos=0, dup=False, retain=False, msgId=0)
     assert 1 == len(tsetter.protocol._published_messages)
     seq_topic, seq_data = tsetter.protocol._published_messages[-1]
     assert seq_topic == LEDSLIE_TOPIC_SEQUENCES_UNNAMED
     assert len(seq_data) > Config()['DISPLAY_SIZE']
Ejemplo n.º 6
0
    def publish_prices(self, coin_lines: list) -> Deferred:
        def _logAll(*args):
            self.log.debug("all publishing complete args={args!r}", args=args)

        msg = TextTripleLinesLayout()
        msg.lines = coin_lines
        msg.duration = self.config["COINS_DISPLAY_DURATION"]
        msg.program = 'coins'
        d = self.publish(topic=LEDSLIE_TOPIC_TYPESETTER_3LINES,
                         message=msg,
                         qos=1)
        d.addCallbacks(_logAll, self._logFailure)
        return d
Ejemplo n.º 7
0
 def test_typeset_3lines_appends(self, tsetter):
     """
     I test that typeset_3lines appends new frames to the end of the sequence.
     """
     msg = TextTripleLinesLayout()
     msg.lines = ["Foo"]
     seq = FrameSequence()
     tsetter.typeset_3lines(seq, msg)
     assert 1 == len(seq)
     frame1 = seq[-1].raw()
     msg.lines = ["Bar"]
     tsetter.typeset_3lines(seq, msg)
     assert 2 == len(seq)
     assert frame1 != seq[-1].raw()
Ejemplo n.º 8
0
 def onPublish(self, topic, payload, qos, dup, retain, msgId):
     '''
     Callback Receiving messages from publisher
     '''
     self.log.debug("onPublish topic={topic};q={qos}, msg={payload}", payload=payload, qos=qos, topic=topic)
     seq_msg = FrameSequence()
     image_bytes = None
     if topic == LEDSLIE_TOPIC_TYPESETTER_SIMPLE_TEXT:
         font_size = self.config['TYPESETTER_1LINE_DEFAULT_FONT_SIZE']
         image_bytes = self.typeset_1line(payload[:30], font_size)
         msg = TextSingleLineLayout()
         msg.duration = self.config['DISPLAY_DEFAULT_DELAY']
     elif topic == LEDSLIE_TOPIC_TYPESETTER_1LINE:
         msg = TextSingleLineLayout().load(payload)
         font_size = msg.font_size if msg.font_size is not None else self.config['TYPESETTER_1LINE_DEFAULT_FONT_SIZE']
         text = msg.text
         image_bytes = self.typeset_1line(text, font_size)
     elif topic == LEDSLIE_TOPIC_TYPESETTER_3LINES:
         msg = TextTripleLinesLayout().load(payload)
         self.typeset_3lines(seq_msg, msg)
     elif topic.startswith(LEDSLIE_TOPIC_ALERT):
         msg = TextAlertLayout().load(payload)
         frame_seq = self.typeset_alert(topic, msg)
         frame_seq.program = "alert"
         return self.send_frame_sequence(frame_seq)
     else:
         raise NotImplementedError("topic '%s' (%s) is not known" % (topic, type(topic)))
     if image_bytes is None and seq_msg.is_empty():
         return
     seq_msg.program = msg.program
     seq_msg.valid_time = msg.valid_time
     if seq_msg.is_empty():
         seq_msg.frames.append((image_bytes, {'duration': msg.duration}))
     self.send_image(seq_msg)
Ejemplo n.º 9
0
 def typeset_alert(self, topic: str, msg: TextAlertLayout) -> FrameSequence:
     assert topic.split('/')[-1] == "spacealert"
     text = msg.text
     who = msg.who
     fs = FrameSequence()
     char_width = self._char_display_width()
     fs.program = msg.program
     alert = self.typeset_1line("Space Alert!", 20)
     alert_neg = bytearray([(~x & 0xff) for x in alert])
     fs.add_frame(Frame(alert, duration=200))
     fs.add_frame(Frame(alert_neg, duration=200))
     fs.add_frame(Frame(alert, duration=200))
     fs.add_frame(Frame(alert_neg, duration=200))
     if text:
         three_line_msg = TextTripleLinesLayout()
         three_line_msg.lines = ["From %s" % who, text[:char_width], text[char_width:]]
         three_line_msg.duration = 2000
         self.typeset_3lines(fs, three_line_msg)
     fs.prio = "alert"
     return fs
Ejemplo n.º 10
0
    def publishInfo(self):
        def _logFailure(failure):
            self.log.debug("reported {message}", message=failure.getErrorMessage())
            return failure

        def _logAll(*args):
            self.log.debug("all publishing complete args={args!r}", args=args)

        self.log.debug(" >< Starting one round of publishing >< ")
        msg = TextTripleLinesLayout()
        msg.lines = [
            "Ledslie GNU-AGPL3",
            "http://ledslie.ti",
            "ledslie @ the Wiki",
        ]
        msg.duration = self.config['INFO_DISPLAY_DURATION']
        msg.program = 'info'
        d = self.publish(topic=LEDSLIE_TOPIC_TYPESETTER_3LINES, message=msg, qos=1)
        d.addCallbacks(_logAll, _logFailure)
        return d
Ejemplo n.º 11
0
 def publish_ov_display(self, info_lines: list) -> Deferred:
     def _logAll(*args):
         self.log.debug("all publishing complete args={args!r}", args=args)
     if not info_lines:
         return
     msg = TextTripleLinesLayout()
     msg.lines = info_lines
     msg.line_duration = self.config["OVINFO_LINE_DELAY"]
     msg.valid_time = 60  # Information is only valid for a minute.
     msg.program = 'ovinfo'
     msg.size = '6x7'
     msg.lines = info_lines
     d = self.publish(topic=LEDSLIE_TOPIC_TYPESETTER_3LINES, message=msg, qos=1)
     d.addCallbacks(_logAll, self._logFailure)
     return d
Ejemplo n.º 12
0
    def publish_events(self, event_lines: list) -> Deferred:
        def _logAll(*args):
            self.log.debug("all publishing complete args={args!r}", args=args)

        msg = TextTripleLinesLayout()
        msg.lines = event_lines
        msg.line_duration = self.config["EVENTS_LINE_DURATION"]
        msg.program = 'events'
        msg.size = '6x7'
        d = self.publish(topic=LEDSLIE_TOPIC_TYPESETTER_3LINES,
                         message=msg,
                         qos=1)
        d.addCallbacks(_logAll, self._logFailure)
        return d
Ejemplo n.º 13
0
 def midnight_message(self,
                      midnight_offset: float) -> TextTripleLinesLayout:
     tz_names = self.tz_groups[midnight_offset]
     tz_name, gmt_name = random.choice(tz_names)
     city = create_city_name(tz_name)
     self.tz_groups = create_midnight_groups(
     )  # Catch changes due to Daylight saving.
     msg = TextTripleLinesLayout()
     msg.duration = self.config['MIDNIGHT_DISPLAY_DURATION']
     msg.program = 'midnight'
     msg.lines = ['Midnight in', city]
     if gmt_name:
         msg.lines.append(gmt_name)
     else:
         msg.lines.append("")
     msg.valid_time = self.config["MIDNIGHT_SHOW_VALIDITY"]
     return msg
Ejemplo n.º 14
0
    def display_song_info(self, data):
        def _logAll(*args):
            self.log.debug("all publishing complete args={args!r}", args=args)

        playing_info = [
            data.get('title', "UNKNOWN"),
            "by {}".format(data.get('artist', "UNKNOWN")),
            "from {}".format(data.get('album', "UNKNOWN")),
        ]
        msg = TextTripleLinesLayout()
        msg.lines = playing_info
        msg.duration = self.config['INFO_DISPLAY_DURATION']
        msg.program = self.program_name
        msg.size = '6x7'
        self.log.info(repr(playing_info))
        d = self.publish(topic=LEDSLIE_TOPIC_TYPESETTER_3LINES,
                         message=msg,
                         qos=1)
        d.addCallbacks(_logAll, self._logFailure)
        return d
Ejemplo n.º 15
0
    def test_typeset_3lines_font(self, tsetter):
        """
        I test different fonts for 3lines.
        """
        msg = TextTripleLinesLayout()
        msg.lines = ["Foo"]
        seq = FrameSequence()
        tsetter.typeset_3lines(seq, msg)
        frame_font_default = seq[-1].raw()
        msg.size = '8x8'
        tsetter.typeset_3lines(seq, msg)
        assert frame_font_default == seq[-1].raw()

        msg.size = '6x7'
        tsetter.typeset_3lines(seq, msg)
        assert frame_font_default != seq[-1].raw()

        msg.size = '1x1'
        try:
            tsetter.typeset_3lines(seq, msg)
            fail("Should not get here.")
        except KeyError:
            pass