<commit_before>import os

from zmqservices import services
from cnavconstants.servers import (
    LOCAL_LED_MATRIX_ADDRESS, LED_MATRIX_PORT_ADDRESS
)

from cnavsense import settings
from cnavsense.utils import sentry, logger


class LedMatrix(services.JsonrpcServerResource):

    def __init__(self, *args, **kwargs):
        super(LedMatrix, self).__init__(*args, **kwargs)

        self.driver = kwargs.pop('driver', settings.SENSE_HAT_DRIVER)

        self.endpoints = {
            'set_rotation': self.validate_set_rotation_params,
            'set_pixels': self.validate_set_pixels_params,
            'set_pixel': self.validate_set_pixel_params,
            'get_pixel': self.validate_get_pixel_params,
            'load_image': self.validate_load_image_params,
            'flip_horizontally': self.validate_no_params,
            'flip_vertically': self.validate_no_params,
            'clear': self.validate_no_params,
            'set_colour': self.validate_set_colour_params,
            'show_message': self.validate_text_and_back_colour_params,
            'show_letter': self.validate_text_and_back_colour_params,
            'set_low_light': (
                lambda x: True if (x is True or x is False) else False
            ),
        }

    def run(self, *args, **kwargs):
        with sentry():
            super(LedMatrix, self).run(*args, **kwargs)

    @staticmethod
    def validate_no_params(params=None):
        return params is None

    @staticmethod
    def validate_set_rotation_params(params):
        return params.get('value') in (0, 90, 180, 270)

    def set_rotation(self, value):
        self.driver.set_rotation(value)
<commit_msg>Fix validating no parms for led_matrix methods<commit_after>import os

from zmqservices import services
from cnavconstants.servers import (
    LOCAL_LED_MATRIX_ADDRESS, LED_MATRIX_PORT_ADDRESS
)

from cnavsense import settings
from cnavsense.utils import sentry, logger


class LedMatrix(services.JsonrpcServerResource):

    def __init__(self, *args, **kwargs):
        super(LedMatrix, self).__init__(*args, **kwargs)

        self.driver = kwargs.pop('driver', settings.SENSE_HAT_DRIVER)

        self.endpoints = {
            'set_rotation': self.validate_set_rotation_params,
            'set_pixels': self.validate_set_pixels_params,
            'set_pixel': self.validate_set_pixel_params,
            'get_pixel': self.validate_get_pixel_params,
            'load_image': self.validate_load_image_params,
            'flip_horizontally': self.validate_no_params,
            'flip_vertically': self.validate_no_params,
            'clear': self.validate_no_params,
            'set_colour': self.validate_set_colour_params,
            'show_message': self.validate_text_and_back_colour_params,
            'show_letter': self.validate_text_and_back_colour_params,
            'set_low_light': (
                lambda x: True if (x is True or x is False) else False
            ),
        }

    def run(self, *args, **kwargs):
        with sentry():
            super(LedMatrix, self).run(*args, **kwargs)

    @staticmethod
    def validate_no_params(params=None):
        return not params

    @staticmethod
    def validate_set_rotation_params(params):
        return params.get('value') in (0, 90, 180, 270)

    def set_rotation(self, value):
        self.driver.set_rotation(value)

{'fraction_non_alphanumeric': 0.09249925882004151, 'fraction_numerical': 0.005336495701156241, 'mean_word_length': 2.9787735849056602, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3200205', 'n_tokens_mistral': 1050, 'n_tokens_neox': 1003, 'n_words': 203}