mirror of
https://github.com/home-assistant/core.git
synced 2025-04-26 02:07:54 +00:00
Xiaomi MiIO Light: Brightness mapping improved (#12203)
* Mapping ([1,100] <-> [1,255]) of the brightness improved. * The cast to int isn't needed for python3.
This commit is contained in:
parent
a2916a9c47
commit
cee57aab24
@ -7,6 +7,7 @@ https://home-assistant.io/components/light.xiaomi_miio/
|
|||||||
import asyncio
|
import asyncio
|
||||||
from functools import partial
|
from functools import partial
|
||||||
import logging
|
import logging
|
||||||
|
from math import ceil
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -204,11 +205,11 @@ class XiaomiPhilipsGenericLight(Light):
|
|||||||
"""Turn the light on."""
|
"""Turn the light on."""
|
||||||
if ATTR_BRIGHTNESS in kwargs:
|
if ATTR_BRIGHTNESS in kwargs:
|
||||||
brightness = kwargs[ATTR_BRIGHTNESS]
|
brightness = kwargs[ATTR_BRIGHTNESS]
|
||||||
percent_brightness = int(100 * brightness / 255)
|
percent_brightness = ceil(100 * brightness / 255.0)
|
||||||
|
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Setting brightness: %s %s%%",
|
"Setting brightness: %s %s%%",
|
||||||
self.brightness, percent_brightness)
|
brightness, percent_brightness)
|
||||||
|
|
||||||
result = yield from self._try_command(
|
result = yield from self._try_command(
|
||||||
"Setting brightness failed: %s",
|
"Setting brightness failed: %s",
|
||||||
@ -235,7 +236,7 @@ class XiaomiPhilipsGenericLight(Light):
|
|||||||
_LOGGER.debug("Got new state: %s", state)
|
_LOGGER.debug("Got new state: %s", state)
|
||||||
|
|
||||||
self._state = state.is_on
|
self._state = state.is_on
|
||||||
self._brightness = int(255 * 0.01 * state.brightness)
|
self._brightness = ceil((255/100.0) * state.brightness)
|
||||||
|
|
||||||
except DeviceException as ex:
|
except DeviceException as ex:
|
||||||
_LOGGER.error("Got exception while fetching the state: %s", ex)
|
_LOGGER.error("Got exception while fetching the state: %s", ex)
|
||||||
@ -306,11 +307,11 @@ class XiaomiPhilipsLightBall(XiaomiPhilipsGenericLight, Light):
|
|||||||
|
|
||||||
if ATTR_BRIGHTNESS in kwargs:
|
if ATTR_BRIGHTNESS in kwargs:
|
||||||
brightness = kwargs[ATTR_BRIGHTNESS]
|
brightness = kwargs[ATTR_BRIGHTNESS]
|
||||||
percent_brightness = int(100 * brightness / 255)
|
percent_brightness = ceil(100 * brightness / 255.0)
|
||||||
|
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Setting brightness: %s %s%%",
|
"Setting brightness: %s %s%%",
|
||||||
self.brightness, percent_brightness)
|
brightness, percent_brightness)
|
||||||
|
|
||||||
result = yield from self._try_command(
|
result = yield from self._try_command(
|
||||||
"Setting brightness failed: %s",
|
"Setting brightness failed: %s",
|
||||||
@ -331,7 +332,7 @@ class XiaomiPhilipsLightBall(XiaomiPhilipsGenericLight, Light):
|
|||||||
_LOGGER.debug("Got new state: %s", state)
|
_LOGGER.debug("Got new state: %s", state)
|
||||||
|
|
||||||
self._state = state.is_on
|
self._state = state.is_on
|
||||||
self._brightness = int(255 * 0.01 * state.brightness)
|
self._brightness = ceil((255/100.0) * state.brightness)
|
||||||
self._color_temp = self.translate(
|
self._color_temp = self.translate(
|
||||||
state.color_temperature,
|
state.color_temperature,
|
||||||
CCT_MIN, CCT_MAX,
|
CCT_MIN, CCT_MAX,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user