11"""Simple web app to visualize brightness over time."""
22
3- import sys
43import datetime as dt
5- from contextlib import suppress
4+ import importlib .util
5+ import sys
6+ import types
67from pathlib import Path
78from typing import Any
89
10+ import homeassistant_util_color
911import matplotlib .pyplot as plt
1012import numpy as np
1113import shinyswatch
1214from astral import LocationInfo
1315from astral .location import Location
1416from homeassistant_util_color import color_temperature_to_rgb
15- import types
16- import homeassistant_util_color
17- import importlib .util
1817from shiny import App , render , ui
1918
2019# Mock homeassistant.util.color
2625sys .modules ["homeassistant.util.color" ] = homeassistant_util_color
2726
2827
29-
3028def date_range (tzinfo : dt .tzinfo ) -> list [dt .datetime ]:
3129 """Return a list of datetimes for the current day."""
3230 start_of_day = dt .datetime .now (tzinfo ).replace (
@@ -44,7 +42,12 @@ def date_range(tzinfo: dt.tzinfo) -> list[dt.datetime]:
4442
4543
4644# Load color_and_brightness directly from file, bypassing package __init__
47- component_path = Path (__file__ ).parent .parent / "custom_components" / "adaptive_lighting" / "color_and_brightness.py"
45+ component_path = (
46+ Path (__file__ ).parent .parent
47+ / "custom_components"
48+ / "adaptive_lighting"
49+ / "color_and_brightness.py"
50+ )
4851spec = importlib .util .spec_from_file_location ("color_and_brightness" , component_path )
4952module = importlib .util .module_from_spec (spec )
5053sys .modules ["color_and_brightness" ] = module
@@ -53,7 +56,6 @@ def date_range(tzinfo: dt.tzinfo) -> list[dt.datetime]:
5356from color_and_brightness import SunLightSettings
5457
5558
56-
5759def plot_brightness (inputs : dict [str , Any ], sleep_mode : bool ):
5860 """Plot the brightness over time for different modes."""
5961 # Define the time range for our simulation
@@ -355,17 +357,13 @@ def _kw(input):
355357 "timezone" : location .timezone ,
356358 # Separate color timing parameters
357359 "color_sunrise_time" : (
358- float_to_time (input .color_sunrise_time ())
359- if independent_color
360- else None
360+ float_to_time (input .color_sunrise_time ()) if independent_color else None
361361 ),
362362 "color_sunrise_offset" : dt .timedelta (0 ),
363363 "color_min_sunrise_time" : None ,
364364 "color_max_sunrise_time" : None ,
365365 "color_sunset_time" : (
366- float_to_time (input .color_sunset_time ())
367- if independent_color
368- else None
366+ float_to_time (input .color_sunset_time ()) if independent_color else None
369367 ),
370368 "color_sunset_offset" : dt .timedelta (0 ),
371369 "color_min_sunset_time" : None ,
0 commit comments