Skip to content

Commit

Permalink
Introduce state of global color temp and brightness values
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-mueller committed Jan 13, 2025
1 parent 3b4404a commit 33a9883
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
7 changes: 7 additions & 0 deletions custom_components/sunset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ async def maybe_apply_new_state(lgt: str, current_state: HA.State):
async def timer_event(_: DT.datetime | None) -> None:
nonlocal known_states

hass.states.async_set(DOMAIN + ".color_temp_kelvin", current_target_color_temp())
hass.states.async_set(DOMAIN + ".brightness", new_brightness())

current_states = fetch_light_states()
known_states = forget_off_lights(current_states)

Expand Down Expand Up @@ -282,6 +285,10 @@ def make_brightness_calculator() -> DaytimeCalculator | None:

hass.states.async_set(DOMAIN + ".redshift_active", True)
hass.states.async_set(DOMAIN + ".brightness_active", True)

hass.states.async_set(DOMAIN + ".color_temp_kelvin", current_target_color_temp())
hass.states.async_set(DOMAIN + ".brightness", new_brightness())

EV.async_track_time_interval(hass, timer_event, DT.timedelta(seconds=1))

return True
Expand Down
16 changes: 16 additions & 0 deletions tests/test_brightness.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,19 @@ async def test_manual_brightness_not_intervened_by_redshift(
await hass.async_block_till_done()

assert turn_on_service.pop().data[ATTR_BRIGHTNESS] == 128


async def test_global_brightness(hass, start_at_noon):
assert await async_setup(hass, {DOMAIN: {}})

start_at_noon.tick(600)
async_fire_time_changed_now_time(hass)
await hass.async_block_till_done()

assert hass.states.get('sunset.brightness').state == '254'

start_at_noon.move_to(some_night_time())
async_fire_time_changed_now_time(hass)
await hass.async_block_till_done()

assert hass.states.get('sunset.brightness').state == '127'
16 changes: 16 additions & 0 deletions tests/test_redshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,3 +972,19 @@ async def test_manual_redshift_not_intervened_by_brightness(
await hass.async_block_till_done()

assert turn_on_service.pop().data[ATTR_COLOR_TEMP_KELVIN] == 3500


async def test_global_color_temp(hass, start_at_noon):
assert await async_setup(hass, {DOMAIN: {}})

start_at_noon.tick(600)
async_fire_time_changed_now_time(hass)
await hass.async_block_till_done()

assert hass.states.get('sunset.color_temp_kelvin').state == '6250'

start_at_noon.move_to(some_evening_time())
async_fire_time_changed_now_time(hass)
await hass.async_block_till_done()

assert hass.states.get('sunset.color_temp_kelvin').state == '4375'

0 comments on commit 33a9883

Please sign in to comment.