mirror of
https://github.com/andvikt/mega_hacs.git
synced 2025-12-08 07:34:27 +05:00
- fix order for ws28xx
This commit is contained in:
@@ -1,5 +1,15 @@
|
||||
from itertools import permutations
|
||||
order ='brg'
|
||||
rgb = 'rgb'
|
||||
|
||||
RGB_COMBINATIONS = [''.join(x) for x in permutations('rgb')]
|
||||
map_to_order = [rgb.index(x) for x in order]
|
||||
map_from_order = [order.index(x) for x in rgb]
|
||||
|
||||
print(RGB_COMBINATIONS)
|
||||
|
||||
_rgb = [
|
||||
rgb[x] for x in map_to_order
|
||||
]
|
||||
_order = [
|
||||
_rgb[x] for x in map_from_order
|
||||
]
|
||||
|
||||
print(_rgb, _order)
|
||||
@@ -77,4 +77,5 @@ REMOVE_CONFIG = [
|
||||
'sensor',
|
||||
'smooth',
|
||||
]
|
||||
RGB_COMBINATIONS = [''.join(x) for x in permutations('rgb')]
|
||||
RGB_COMBINATIONS = [''.join(x) for x in permutations('rgb')]
|
||||
RGB = 'rgb'
|
||||
|
||||
@@ -33,9 +33,9 @@ from .const import (
|
||||
CONF_SWITCH,
|
||||
DOMAIN,
|
||||
CONF_CUSTOM,
|
||||
CONF_SKIP, CONF_LED, CONF_WS28XX, CONF_PORTS, CONF_WHITE_SEP, CONF_SMOOTH, CONF_ORDER, CONF_CHIP,
|
||||
CONF_SKIP, CONF_LED, CONF_WS28XX, CONF_PORTS, CONF_WHITE_SEP, CONF_SMOOTH, CONF_ORDER, CONF_CHIP, RGB,
|
||||
)
|
||||
from .tools import int_ignore
|
||||
from .tools import int_ignore, map_reorder_rgb
|
||||
|
||||
lg = logging.getLogger(__name__)
|
||||
SCAN_INTERVAL = timedelta(seconds=5)
|
||||
@@ -119,14 +119,8 @@ class MegaRGBW(LightEntity, BaseMegaEntity):
|
||||
self._task: asyncio.Task = None
|
||||
self._restore = None
|
||||
self.smooth: timedelta = self.customize[CONF_SMOOTH]
|
||||
self._color_map = self.customize.get(CONF_ORDER, 'rgb')
|
||||
self._color_order = self.customize.get(CONF_ORDER, 'rgb')
|
||||
self._last_called: float = 0
|
||||
if self._color_map == 'rgb':
|
||||
self._color_map = None
|
||||
else:
|
||||
self._color_map = {
|
||||
x: i for i, x in enumerate(self._color_map)
|
||||
}
|
||||
self._max_values = None
|
||||
|
||||
@property
|
||||
@@ -189,11 +183,9 @@ class MegaRGBW(LightEntity, BaseMegaEntity):
|
||||
rgb = [
|
||||
round(x * self.max_values[i]) for i, x in enumerate(rgb)
|
||||
]
|
||||
if self.is_ws and self._color_map is not None:
|
||||
if self.is_ws:
|
||||
# восстанавливаем мэпинг
|
||||
rgb = [
|
||||
rgb[self._color_map[x]] for x in 'rgb'
|
||||
]
|
||||
rgb = map_reorder_rgb(rgb, RGB, self._color_order)
|
||||
return rgb
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
@@ -267,7 +259,10 @@ class MegaRGBW(LightEntity, BaseMegaEntity):
|
||||
else:
|
||||
w = None
|
||||
rgb = rgbw
|
||||
|
||||
if self.is_ws:
|
||||
rgb = map_reorder_rgb(
|
||||
rgb, self._color_order, RGB
|
||||
)
|
||||
h, s, v = colorsys.rgb_to_hsv(*[x/self.max_values[i] for i, x in enumerate(rgb)])
|
||||
h *= 360
|
||||
s *= 100
|
||||
|
||||
@@ -15,5 +15,5 @@
|
||||
"@andvikt"
|
||||
],
|
||||
"issue_tracker": "https://github.com/andvikt/mega_hacs/issues",
|
||||
"version": "v1.0.0b1"
|
||||
"version": "v1.0.1"
|
||||
}
|
||||
@@ -117,3 +117,8 @@ class PriorityLock(asyncio.Lock):
|
||||
fut.set_result(True)
|
||||
|
||||
|
||||
def map_reorder_rgb(rgb: list, from_: str, to_: str):
|
||||
if from_ == to_:
|
||||
return rgb
|
||||
mapping = [from_.index(x) for x in to_]
|
||||
return [rgb[x] for x in mapping]
|
||||
|
||||
Reference in New Issue
Block a user