Skip to content

Commit 50145ca

Browse files
committed
fix: Fix panel for HA 2025.1 + some cleanups
1 parent 873ac81 commit 50145ca

5 files changed

Lines changed: 18 additions & 10 deletions

File tree

custom_components/scene_presets/file_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
with open(custom_presets_path, 'r') as file:
2626
CUSTOM_PRESETS = json.load(file)
2727

28-
print("Custom presets loaded successfully.")
28+
_LOGGER.info("Custom presets loaded successfully.")
2929
except json.JSONDecodeError as e:
3030
_LOGGER.error(f"Error loading custom presets: {e}")
3131
else:

custom_components/scene_presets/frontend/scene_presets_panel.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

custom_components/scene_presets/presets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async def apply_preset(
6767
if color_support:
6868
light_params["xy_color"] = next_color
6969
elif temp_support:
70-
light_params["kelvin"] = find_closest_ct_match(next_color[0], next_color[1])
70+
light_params["kelvin"] = find_closest_ct_match(next_color[0], next_color[1]) # TODO: Change to color_temp_kelvin before 2026.1
7171
elif brightness_support:
7272
pass # Nothing to add to the payload. Brightness is already part of it
7373
else:

custom_components/scene_presets/view.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,18 @@ async def get(self, request):
2323
)
2424

2525
async def async_setup_view(hass):
26-
await hass.http.async_register_static_paths([
26+
static_paths = [
2727
StaticPathConfig(PANEL_URL, hass.config.path(f'{BASE_PATH}/frontend/scene_presets_panel.js'), True),
2828
StaticPathConfig(f'/assets/{DOMAIN}/iconset.js', hass.config.path(f'{BASE_PATH}/res/iconset.js'), True)
29-
])
29+
]
30+
31+
static_paths.extend(await get_preset_image_paths(hass))
32+
33+
await hass.http.async_register_static_paths(static_paths)
3034

3135
hass.http.register_view(ScenePresetDataView)
3236
add_extra_js_url(hass, f"/assets/{DOMAIN}/iconset.js?{VERSION}")
3337

34-
await bind_preset_images(hass)
35-
3638
async_register_built_in_panel(
3739
hass,
3840
component_name="custom",
@@ -52,7 +54,7 @@ async def async_setup_view(hass):
5254
async def async_remove_view(hass):
5355
async_remove_panel(hass, "scene_presets")
5456

55-
async def bind_preset_images(hass):
57+
async def get_preset_image_paths(hass):
5658
static_paths = []
5759

5860
for preset in PRESET_DATA.get("presets", []):
@@ -72,4 +74,4 @@ async def bind_preset_images(hass):
7274
)
7375
)
7476

75-
await hass.http.async_register_static_paths(static_paths)
77+
return static_paths

js/helpers.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
export const loadConfigDashboard = async () => {
55
await customElements.whenDefined("partial-panel-resolver");
66
const ppResolver = document.createElement("partial-panel-resolver");
7-
const routes = (ppResolver as any).getRoutes([
7+
8+
let getRoutes = (ppResolver as any)._getRoutes; // After HA 2025.1
9+
if (typeof getRoutes !== "function") { // Before HA 2025.1
10+
getRoutes = (ppResolver as any).getRoutes;
11+
}
12+
13+
const routes = getRoutes([
814
{
915
component_name: "config",
1016
url_path: "a",

0 commit comments

Comments
 (0)