예제 #1
0
def test_color_RGB_to_hsv():
    """Test color_RGB_to_hsv."""
    assert color_util.color_RGB_to_hsv(0, 0, 0) == (0, 0, 0)

    assert color_util.color_RGB_to_hsv(255, 255, 255) == (0, 0, 100)

    assert color_util.color_RGB_to_hsv(0, 0, 255) == (240, 100, 100)

    assert color_util.color_RGB_to_hsv(0, 255, 0) == (120, 100, 100)

    assert color_util.color_RGB_to_hsv(255, 0, 0) == (0, 100, 100)
예제 #2
0
 def update(self):
     """Synchronise internal state with the actual light state."""
     rgb = self._bulb.get_colour()
     hsv = color_util.color_RGB_to_hsv(*rgb)
     self._hs_color = hsv[:2]
     self._brightness = (hsv[2] / 100) * 255
     self._white = self._bulb.get_white()
     self._state = self._bulb.get_on()
예제 #3
0
 async def async_update(self):
     """Fetch new state data for this light."""
     try:
         if not self._available:
             await self._light.connect()
         state = await self._light.get_state()
     except pyzerproc.ZerprocException:
         if self._available:
             _LOGGER.warning("Unable to connect to %s", self._light.address)
         self._available = False
         return
     if self._available is False:
         _LOGGER.info("Reconnected to %s", self._light.address)
         self._available = True
     self._is_on = state.is_on
     hsv = color_util.color_RGB_to_hsv(*state.color)
     self._hs_color = hsv[:2]
     self._brightness = int(round((hsv[2] / 100) * 255))
예제 #4
0
    async def async_update(self):
        """Fetch new state data for this light."""
        try:
            if not self._available:
                await self._light.connect()
            # pylint: disable=invalid-name
            r, g, b, w = await self._light.get_color()
        except pykulersky.PykulerskyException as exc:
            if self._available:
                _LOGGER.warning("Unable to connect to %s: %s", self._light.address, exc)
            self._available = False
            return
        if self._available is False:
            _LOGGER.info("Reconnected to %s", self._light.address)

        self._available = True
        hsv = color_util.color_RGB_to_hsv(r, g, b)
        self._hs_color = hsv[:2]
        self._brightness = int(round((hsv[2] / 100) * 255))
        self._white_value = w
예제 #5
0
파일: light.py 프로젝트: OpenPeerPower/core
    async def async_update(self):
        """Update the light's status."""
        if self.device.appliance.status.get(self._key,
                                            {}).get(ATTR_VALUE) is True:
            self._state = True
        elif self.device.appliance.status.get(self._key,
                                              {}).get(ATTR_VALUE) is False:
            self._state = False
        else:
            self._state = None

        _LOGGER.debug("Updated, new light state: %s", self._state)

        if self._ambient:
            color = self.device.appliance.status.get(self._custom_color_key,
                                                     {})

            if not color:
                self._hs_color = None
                self._brightness = None
            else:
                colorvalue = color.get(ATTR_VALUE)[1:]
                rgb = color_util.rgb_hex_to_rgb_list(colorvalue)
                hsv = color_util.color_RGB_to_hsv(rgb[0], rgb[1], rgb[2])
                self._hs_color = [hsv[0], hsv[1]]
                self._brightness = ceil((hsv[2] - 10) * 255 / 90)
                _LOGGER.debug("Updated, new brightness: %s", self._brightness)

        else:
            brightness = self.device.appliance.status.get(
                self._brightness_key, {})
            if brightness is None:
                self._brightness = None
            else:
                self._brightness = ceil(
                    (brightness.get(ATTR_VALUE) - 10) * 255 / 90)
            _LOGGER.debug("Updated, new brightness: %s", self._brightness)
예제 #6
0
파일: light.py 프로젝트: OpenPeerPower/core
    async def async_turn_on(self, **kwargs):
        """Turn the light on."""
        hs_color = kwargs.get(ATTR_HS_COLOR, self._hs_color)
        brightness = kwargs.get(ATTR_BRIGHTNESS, self._brightness)
        effect = kwargs.get(ATTR_EFFECT)

        if effect is not None:
            colors = await self._api.set_pattern_by_id(self._channel, effect)

            rgb = color_int_to_rgb(colors[0])
            hsv = color_util.color_RGB_to_hsv(*rgb)
            hs_color = hsv[:2]
            brightness = hsv[2] / 100 * 255

        else:
            rgb = color_util.color_hsv_to_RGB(*hs_color,
                                              brightness / 255 * 100)
            colors = [color_rgb_to_int(*rgb)]

            await self._api.set_pattern(self._channel, colors)

        self._hs_color = hs_color
        self._brightness = brightness
        self._effect = effect
예제 #7
0
 def update(self):
     """Read back the device state."""
     rgb_color = self._stick.get_color()
     hsv = color_util.color_RGB_to_hsv(*rgb_color)
     self._hs_color = hsv[:2]
     self._brightness = hsv[2]