mirror of
https://github.com/andvikt/mega_hacs.git
synced 2025-12-12 01:24:29 +05:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7180c0477 | ||
|
|
1ceb7e4766 | ||
|
|
ef46ac2b2b | ||
|
|
e44aef35fb | ||
|
|
a860ba9822 | ||
|
|
2463b270e5 |
@@ -1,5 +1,5 @@
|
|||||||
[bumpversion]
|
[bumpversion]
|
||||||
current_version = 1.1.2b0
|
current_version = 1.1.4
|
||||||
parse = (?P<major>\d+)(\.(?P<minor>\d+))(\.(?P<patch>\d+))(?P<release>[bf]*)(?P<build>\d*)
|
parse = (?P<major>\d+)(\.(?P<minor>\d+))(\.(?P<patch>\d+))(?P<release>[bf]*)(?P<build>\d*)
|
||||||
commit = True
|
commit = True
|
||||||
tag = True
|
tag = True
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
"""Platform for light integration."""
|
"""Platform for light integration."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import typing
|
import typing
|
||||||
@@ -14,8 +16,8 @@ from homeassistant.components.light import (
|
|||||||
SUPPORT_BRIGHTNESS,
|
SUPPORT_BRIGHTNESS,
|
||||||
LightEntity,
|
LightEntity,
|
||||||
SUPPORT_TRANSITION,
|
SUPPORT_TRANSITION,
|
||||||
SUPPORT_COLOR,
|
SUPPORT_COLOR, ColorMode, LightEntityFeature,
|
||||||
SUPPORT_WHITE_VALUE
|
# SUPPORT_WHITE_VALUE
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@@ -116,6 +118,7 @@ class MegaRGBW(LightEntity, BaseMegaEntity):
|
|||||||
self._is_on = None
|
self._is_on = None
|
||||||
self._brightness = None
|
self._brightness = None
|
||||||
self._hs_color = None
|
self._hs_color = None
|
||||||
|
self._rgb_color: tuple[int, int, int] | None = None
|
||||||
self._white_value = None
|
self._white_value = None
|
||||||
self._task: asyncio.Task = None
|
self._task: asyncio.Task = None
|
||||||
self._restore = None
|
self._restore = None
|
||||||
@@ -143,10 +146,34 @@ class MegaRGBW(LightEntity, BaseMegaEntity):
|
|||||||
def is_ws(self):
|
def is_ws(self):
|
||||||
return self.customize.get(CONF_WS28XX)
|
return self.customize.get(CONF_WS28XX)
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def supported_color_modes(self) -> set[ColorMode] | set[str] | None:
|
||||||
|
return {
|
||||||
|
ColorMode.BRIGHTNESS,
|
||||||
|
ColorMode.RGB if len(self.port) != 4 else ColorMode.RGBW
|
||||||
|
}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def color_mode(self) -> ColorMode | str | None:
|
||||||
|
if len(self.port) == 4:
|
||||||
|
return ColorMode.RGBW
|
||||||
|
else:
|
||||||
|
return ColorMode.RGB
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def white_value(self):
|
def white_value(self):
|
||||||
if self.supported_features & SUPPORT_WHITE_VALUE:
|
# if self.supported_features & SUPPORT_WHITE_VALUE:
|
||||||
return float(self.get_attribute('white_value', 0))
|
return float(self.get_attribute('white_value', 0))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def rgb_color(self) -> tuple[int, int, int] | None:
|
||||||
|
return self._rgb_color
|
||||||
|
|
||||||
|
@property
|
||||||
|
def rgbw_color(self) -> tuple[int, int, int, int] | None:
|
||||||
|
if self._white_value is not None and self._rgb_color is not None:
|
||||||
|
return (*self._rgb_color, self._white_value)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brightness(self):
|
def brightness(self):
|
||||||
@@ -162,12 +189,7 @@ class MegaRGBW(LightEntity, BaseMegaEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def supported_features(self):
|
def supported_features(self):
|
||||||
return (
|
return LightEntityFeature.TRANSITION
|
||||||
SUPPORT_BRIGHTNESS |
|
|
||||||
SUPPORT_TRANSITION |
|
|
||||||
SUPPORT_COLOR |
|
|
||||||
(SUPPORT_WHITE_VALUE if len(self.port) == 4 else 0)
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_rgbw(self):
|
def get_rgbw(self):
|
||||||
if not self.is_on:
|
if not self.is_on:
|
||||||
@@ -225,6 +247,7 @@ class MegaRGBW(LightEntity, BaseMegaEntity):
|
|||||||
for item, value in kwargs.items():
|
for item, value in kwargs.items():
|
||||||
setattr(self, f'_{item}', value)
|
setattr(self, f'_{item}', value)
|
||||||
_after = self.get_rgbw()
|
_after = self.get_rgbw()
|
||||||
|
self._rgb_color = tuple(_after[:3])
|
||||||
if transition is None:
|
if transition is None:
|
||||||
transition = self.smooth.total_seconds()
|
transition = self.smooth.total_seconds()
|
||||||
ratio = self.calc_speed_ratio(_before, _after)
|
ratio = self.calc_speed_ratio(_before, _after)
|
||||||
|
|||||||
@@ -15,5 +15,5 @@
|
|||||||
"@andvikt"
|
"@andvikt"
|
||||||
],
|
],
|
||||||
"issue_tracker": "https://github.com/andvikt/mega_hacs/issues",
|
"issue_tracker": "https://github.com/andvikt/mega_hacs/issues",
|
||||||
"version": "v1.1.2b0"
|
"version": "v1.1.4"
|
||||||
}
|
}
|
||||||
@@ -50,6 +50,10 @@ class PriorityLock(asyncio.Lock):
|
|||||||
finally:
|
finally:
|
||||||
self.release()
|
self.release()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _loop(self):
|
||||||
|
return asyncio.get_event_loop()
|
||||||
|
|
||||||
async def acquire(self, priority=0) -> bool:
|
async def acquire(self, priority=0) -> bool:
|
||||||
"""Acquire a lock.
|
"""Acquire a lock.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user