GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( a3394c...b99246 )
by Virantha
01:31
created

bricknil.sensor.light.Light.set_brightness()   A

Complexity

Conditions 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 2
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
# Copyright 2019 Virantha N. Ekanayake 
2
# 
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
# 
7
# http://www.apache.org/licenses/LICENSE-2.0
8
# 
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14
"""All LED/light output devices"""
15
16
from curio import sleep, current_task, spawn  # Needed for motor speed ramp
17
18
from enum import Enum
19
from struct import pack
20
21
from ..const import Color
22
from .peripheral import Peripheral
23
24
class LED(Peripheral):
25
    """ Changes the LED color on the Hubs::
26
27
            @attach(LED, name='hub_led')
28
29
            self.hub_led.set_output(Color.red)
30
    """
31
    _sensor_id = 0x0017
32
33
    async def set_color(self, color: Color):
34
        """ Converts a Color enumeration to a color value"""
35
36
        # For now, only support preset colors
37
        assert isinstance(color, Color)
38
        col = color.value
39
        assert col < 11
40
        mode = 0
41
        await self.set_output(mode, col)
42
43
44
class Light(Peripheral):
45
    """
46
        Connects to the external light.
47
48
        Example::
49
50
             @attach(Light, name='light')
51
52
        And then within the run body, use::
53
54
            await self.light.set_brightness(brightness)
55
    """
56
    _sensor_id = 0x0008
57
58
    async def set_brightness(self, brightness: int):
59
        """Sets the brightness of the light.
60
61
        Args:
62
            brightness (int) : A value between -100 and 100 where 0 is off and
63
                -100 or 100 are both maximum brightness.
64
        """
65
        mode = 0
66
        brightness, = pack('b', int(brightness))
67
        await self.set_output(mode, brightness)
68
69