Skip to content

Commit eefd6c9

Browse files
authored
Merge pull request #3211 from bramstroker/feat/white-mode
Add support for white color mode
2 parents 1b1e455 + 21fe029 commit eefd6c9

7 files changed

Lines changed: 62 additions & 0 deletions

File tree

custom_components/powercalc/strategy/lut.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ async def get_selected_color_mode(self, attrs: Mapping[str, Any], supported_mode
244244
color_mode = ColorMode(str(attrs.get(ATTR_COLOR_MODE, ColorMode.UNKNOWN)))
245245
except ValueError:
246246
color_mode = ColorMode.UNKNOWN
247+
if color_mode == ColorMode.WHITE:
248+
return ColorMode.BRIGHTNESS
247249
if color_mode == ColorMode.UNKNOWN:
248250
return color_mode
249251
if color_mode in COLOR_MODES_COLOR:

tests/strategy/test_lut.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,28 @@ async def test_effect_lut(hass: HomeAssistant, effect: str, brightness: int, exp
131131
)
132132

133133

134+
async def test_color_mode_white(hass: HomeAssistant) -> None:
135+
"""Test LUT lookup in effect mode"""
136+
strategy = await _create_lut_strategy(
137+
hass,
138+
"test",
139+
"test",
140+
custom_profile_dir=get_test_profile_dir("lut_white"),
141+
)
142+
await _calculate_and_assert_power(
143+
strategy,
144+
state=State(
145+
"light.test",
146+
STATE_ON,
147+
{
148+
ATTR_COLOR_MODE: ColorMode.WHITE,
149+
ATTR_BRIGHTNESS: 10,
150+
},
151+
),
152+
expected_power=10,
153+
)
154+
155+
134156
async def test_effect_mode_unsupported(hass: HomeAssistant) -> None:
135157
"""
136158
Test light is set in effect mode, but effect is not supported by the profile.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1,1
2+
10,10,
3+
100,100
4+
255,255
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"measure_description": "Measured with utils/measure script",
3+
"measure_device": "xx",
4+
"measure_method": "script",
5+
"measure_settings": {
6+
"SAMPLE_COUNT": 2,
7+
"SLEEP_TIME": 3,
8+
"VERSION": "v1.9.8:docker"
9+
},
10+
"name": "Test",
11+
"standby_power": 0.3,
12+
"calculation_strategy": "lut",
13+
"created_at": "2023-12-06T18:41:16",
14+
"author": "test"
15+
}

utils/measure/measure/controller/light/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class LutMode(str, Enum):
99
COLOR_TEMP = "color_temp"
1010
BRIGHTNESS = "brightness"
1111
EFFECT = "effect"
12+
WHITE = "white"
1213

1314

1415
class LightControllerType(str, Enum):

utils/measure/measure/controller/light/hass.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def change_light_state(
3939
LutMode.COLOR_TEMP: self.build_ct_json_body,
4040
LutMode.BRIGHTNESS: self.build_bri_json_body,
4141
LutMode.EFFECT: self.build_effect_json_body,
42+
LutMode.WHITE: self.build_white_json_body,
4243
}.get(lut_mode, self.build_bri_json_body)(**kwargs)
4344

4445
try:
@@ -117,6 +118,12 @@ def build_effect_json_body(self, bri: int, effect: str) -> dict:
117118
"brightness": bri,
118119
}
119120

121+
def build_white_json_body(self, bri: int) -> dict:
122+
return {
123+
"entity_id": self._entity_id,
124+
"white": bri,
125+
}
126+
120127
@staticmethod
121128
def kelvin_to_mired(kelvin_temperature: float) -> int:
122129
"""Convert degrees kelvin to mired shift."""

utils/measure/measure/runner/light.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ def run(self, answers: dict[str, Any], export_directory: str) -> RunnerResult |
9595
def prepare_measurements_for_mode(self, export_directory: str, mode: LutMode) -> MeasurementRunInput:
9696
"""Fetch all variations for the given color mode and prepare the measurement session."""
9797

98+
if mode == LutMode.WHITE:
99+
mode = LutMode.BRIGHTNESS
100+
98101
csv_file_path = f"{export_directory}/{mode.value}.csv"
99102

100103
resume_at = None
@@ -119,6 +122,14 @@ def run_mode(
119122
"""Run the measurement session for lights"""
120123

121124
mode = measurement_info.mode
125+
if mode == LutMode.WHITE:
126+
self.light_controller.change_light_state(
127+
mode,
128+
on=True,
129+
bri=255,
130+
)
131+
mode = LutMode.BRIGHTNESS
132+
122133
file_write_mode = "w"
123134
write_header_row = True
124135
if measurement_info.is_resuming:

0 commit comments

Comments
 (0)