def test_dispatch(self):

        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        try:
            s.connect(('10.255.255.255', 1))
        except Exception as e:
            self.fail("Can't be tested without an internet connection")
        finally:
            s.close()

        # Should result in 3 messages, one embed, one embed with photo, and one photo.
        builder = EmbedBuilder()
        builder.set_title("Test title")
        builder.set_description("No snapshot")

        self.assertTrue(
            self.discord._dispatch_message(embed=builder.get_embeds()[0]))

        with open(self._get_path("test_pattern.png"), "rb") as f:
            builder.set_description("With snapshot")
            builder.set_image(("snapshot.png", f))
            self.assertTrue(
                self.discord._dispatch_message(embed=builder.get_embeds()[0]))

            f.seek(0)
            self.assertTrue(
                self.discord._dispatch_message(snapshot=("snapshot.png", f)))
    def status(self):
        builder = EmbedBuilder()
        builder.set_title('Status')
        builder.set_author(name=self.plugin.get_printer_name())

        if self.plugin.get_settings().get(['show_local_ip'], merged=True):
            ip_addr = self.plugin.get_ip_address()
            if ip_addr != '127.0.0.1':
                builder.add_field(title='Local IP', text=ip_addr, inline=True)

        if self.plugin.get_settings().get(['show_external_ip'], merged=True):
            builder.add_field(title='External IP', text=self.plugin.get_external_ip_address(), inline=True)

        operational = self.plugin.get_printer().is_operational()
        builder.add_field(title='Operational', text='Yes' if operational else 'No', inline=True)
        current_data = self.plugin.get_printer().get_current_data()

        if current_data.get('currentZ'):
            builder.add_field(title='Current Z', text=current_data['currentZ'], inline=True)
        if operational:
            temperatures = self.plugin.get_printer().get_current_temperatures()
            for heater in temperatures.keys():
                if heater == 'bed':
                    continue
                builder.add_field(title='Extruder Temp (%s)' % heater, text=temperatures[heater]['actual'], inline=True)

            if temperatures['bed']['actual']:
                builder.add_field(title='Bed Temp', text=temperatures['bed']['actual'], inline=True)

            printing = self.plugin.get_printer().is_printing()
            builder.add_field(title='Printing', text='Yes' if printing else 'No', inline=True)
            if printing:
                builder.add_field(title='File', text=current_data['job']['file']['name'], inline=True)
                completion = current_data['progress']['completion']
                if completion:
                    builder.add_field(title='Progress', text='%d%%' % completion, inline=True)

                builder.add_field(title='Time Spent', text=self.plugin.get_print_time_spent(), inline=True)
                builder.add_field(title='Time Remaining', text=self.plugin.get_print_time_remaining(), inline=True)

        snapshots = self.plugin.get_snapshot()
        if snapshots and len(snapshots) == 1:
            builder.set_image(snapshots[0])
        return None, builder.get_embeds()
Esempio n. 3
0
    def status(self):
        builder = EmbedBuilder()
        builder.set_title('Current Status')
        builder.set_author(name=self.plugin.get_printer_name())

        if self.plugin.get_settings().get(['show_local_ip'], merged=True) != 'off':
            ip_addr = self.plugin.get_ip_address()
            if ip_addr != '127.0.0.1':
                builder.add_field(title='Local IP', text=ip_addr, inline=True)

        if self.plugin.get_settings().get(['show_external_ip'], merged=True) != 'off':
            builder.add_field(title='External IP', text=self.plugin.get_external_ip_address(), inline=True)

        operational = self.plugin.get_printer().is_operational()
        builder.add_field(title='Operational', text='Yes' if operational else 'No', inline=True)
        current_data = self.plugin.get_printer().get_current_data()

        if current_data.get('currentZ'):
            builder.add_field(title='Current Z', text=str(current_data['currentZ']), inline=True)
        if operational:
            temperatures = self.plugin.get_printer().get_current_temperatures()
            for heater in temperatures.keys():
                if heater == 'bed':
                    continue
                if temperatures[heater]['actual'] is None or len(str(temperatures[heater]['actual'])) == 0:
                    continue
                builder.add_field(title='Extruder Temp (%s)' % heater,
                                  text=str(temperatures[heater]['actual']),
                                  inline=True)

            if temperatures['bed']['actual']:
                builder.add_field(title='Bed Temp', text=str(temperatures['bed']['actual']), inline=True)

            printing = self.plugin.get_printer().is_printing()
            builder.add_field(title='Printing', text='Yes' if printing else 'No', inline=True)
            if printing:
                builder.add_field(title='File', text=current_data['job']['file']['name'], inline=True)
                completion = current_data['progress']['completion']
                if completion:
                    builder.add_field(title='Progress', text='%d%%' % completion, inline=True)

                builder.add_field(title='Time Spent', text=self.plugin.get_print_time_spent(), inline=True)
                builder.add_field(title='Time Remaining', text=self.plugin.get_print_time_remaining(), inline=True)

        try:
            cmd_response = subprocess.Popen(['vcgencmd', 'get_throttled'], stdout=subprocess.PIPE).communicate()
            throttled_string = cmd_response[0].decode().split('=')[1].strip()
            throttled_value = int(throttled_string, 0)
            if throttled_value & (1 << 0):
                builder.add_field(title='WARNING', text="PI is under-voltage", inline=True)
            if throttled_value & (1 << 1):
                builder.add_field(title='WARNING', text="PI has capped it's ARM frequency", inline=True)
            if throttled_value & (1 << 2):
                builder.add_field(title='WARNING', text="PI is currently throttled", inline=True)
            if throttled_value & (1 << 3):
                builder.add_field(title='WARNING', text="PI has reached temperature limit", inline=True)
            if throttled_value & (1 << 16):
                builder.add_field(title='WARNING', text="PI Under-voltage has occurred", inline=True)
            if throttled_value & (1 << 17):
                builder.add_field(title='WARNING', text="PI ARM frequency capped has occurred", inline=True)
            if throttled_value & (1 << 18):
                builder.add_field(title='WARNING', text="PI Throttling has occurred", inline=True)
            if throttled_value & (1 << 19):
                builder.add_field(title='WARNING', text="PI temperature limit has occurred", inline=True)
        except OSError as e:
            pass

        snapshots = self.plugin.get_snapshot()
        if snapshots and len(snapshots) == 1:
            builder.set_image(snapshots[0])
        return None, builder.get_embeds()