<commit_before># -*- coding: utf-8 -*-
import logging

log = logging.getLogger(__name__)


class Light(object):
    def __init__(self, light_id, bridge):
        self.bridge = bridge
        self.id = int(light_id)
        self.name = None
        self.json = None
        self._update()

    def __str__(self):
        return '<%s %s "%s">' % (self.__class__.__name__, self.id,
                                 self.name)

    def _update(self):
        j = self.bridge.get('/lights/%s' % self.id)
        self.name = j['name']
        self.json = j

    def __getattr__(self, name):
        if name in self.json:
            return self.json[name]
        else:
            raise AttributeError("'%s' object has no attribute '%s'" %
                                 (self.__class__.__name__, name))

    def _put(self, path, data):
        return self.bridge.put('/lights/%s/%s' % (self.id, path), data)

    def off(self):
        self.set_state({"on": False})

    def on(self, state={}):
        state.update({"on": True})
        self.set_state(state)

    def set_state(self, state):
        self._put('state', state)
        self._update()

    @property
    def bri(self):
        self._update()
        return self.json['state']['bri']

    @bri.setter
    def bri(self, brightness):
        if 0 <= brightness <= 255:
            self._put('state', {"bri": brightness})
            self._update()

    @property
    def hue(self):
        self._update()
        return self.json['state']['hue']

    @hue.setter
    def hue(self, hue):
        if 0 <= hue <= 65535:
            self._put('state', {"hue": hue})
            self._update()

    @property
    def sat(self):
        self._update()
        return self.json['state']['sat']

    @sat.setter
    def sat(self, saturation):
        if 0 <= saturation <= 255:
            self._put('state', {"sat": saturation})<commit_msg>Clean up Light state properties to use set_state function<commit_after># -*- coding: utf-8 -*-
import logging

log = logging.getLogger(__name__)


class Light(object):
    def __init__(self, light_id, bridge):
        self.bridge = bridge
        self.id = int(light_id)
        self.name = None
        self.json = None
        self._update()

    def __str__(self):
        return '<%s %s "%s">' % (self.__class__.__name__, self.id,
                                 self.name)

    def _update(self):
        j = self.bridge.get('/lights/%s' % self.id)
        self.name = j['name']
        self.json = j

    def __getattr__(self, name):
        if name in self.json:
            return self.json[name]
        else:
            raise AttributeError("'%s' object has no attribute '%s'" %
                                 (self.__class__.__name__, name))

    def _put(self, path, data):
        return self.bridge.put('/lights/%s/%s' % (self.id, path), data)

    def off(self):
        self.set_state({"on": False})

    def on(self, state={}):
        state.update({"on": True})
        self.set_state(state)

    def set_state(self, state):
        self._put('state', state)
        self._update()

    @property
    def bri(self):
        self._update()
        return self.json['state']['bri']

    @bri.setter
    def bri(self, brightness):
        if 0 <= brightness <= 255:
            self.set_state({"bri": brightness})

    @property
    def hue(self):
        self._update()
        return self.json['state']['hue']

    @hue.setter
    def hue(self, hue):
        if 0 <= hue <= 65535:
            self.set_state({"hue": hue})

    @property
    def sat(self):
        self._update()
        return self.json['state']['sat']

    @sat.setter
    def sat(self, saturation):
        if 0 <= saturation <= 255:
            self.set_state({"sat": saturation})
{'fraction_non_alphanumeric': 0.1506376195536663, 'fraction_numerical': 0.007970244420828906, 'mean_word_length': 1.896153846153846, 'pattern_counts': {'":': 10, '<': 17, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1141373', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1140, 'n_words': 276}