diff --git a/custom_components/simple_sticky_note/__init__.py b/custom_components/simple_sticky_note/__init__.py index 5a54687..5943eae 100644 --- a/custom_components/simple_sticky_note/__init__.py +++ b/custom_components/simple_sticky_note/__init__.py @@ -3,7 +3,6 @@ from homeassistant.helpers.typing import ConfigType from homeassistant.const import Platform from homeassistant.helpers import config_validation as cv - from .const import DOMAIN PLATFORMS: list[Platform] = [Platform.SENSOR] @@ -12,15 +11,17 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the Simple Sticky Note component.""" - # This registers your JavaScript file to be served by Home Assistant + # Register the static path for your JavaScript file hass.http.register_static_path( f"/custom_components/{DOMAIN}/js/sticky_note_card.js", hass.config.path(f"custom_components/{DOMAIN}/js/sticky_note_card.js"), True ) - # Register as a Lovelace resource - hass.components.frontend.add_resources([f"/local/custom_components/{DOMAIN}/js/sticky_note_card.js"]) + # Add the resource to Lovelace + resource_url = f"/custom_components/{DOMAIN}/js/sticky_note_card.js" + if not any(resource["url"] == resource_url for resource in hass.data["lovelace"]["resources"].async_items()): + await hass.data["lovelace"]["resources"].async_create_item({"res_type": "module", "url": resource_url}) return True @@ -28,11 +29,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Simple Sticky Note from a config entry.""" hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][entry.entry_id] = entry.data + await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) + return True async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS): hass.data[DOMAIN].pop(entry.entry_id) + return unload_ok diff --git a/custom_components/simple_sticky_note/manifest.json b/custom_components/simple_sticky_note/manifest.json index 050e1b4..673307e 100644 --- a/custom_components/simple_sticky_note/manifest.json +++ b/custom_components/simple_sticky_note/manifest.json @@ -3,10 +3,10 @@ "name": "Simple Sticky Note", "codeowners": ["@biofects"], "config_flow": true, - "dependencies": [], + "dependencies": ["frontend", "lovelace"], "documentation": "https://github.com/biofects/simple_sticky_note", "iot_class": "local_push", "issue_tracker": "https://github.com/biofects/simple_sticky_note/issues", "requirements": [], - "version": "1.3.1" + "version": "1.3.6" }